UGX-Mods Login

or login with an authentication provider below
Sign In with Google
Sign In with Twitter
Sign In with Discord
Sign In with Steam
Sign In with Facebook
Sign In with Twitch

Wait until all doors are open to start a thread

broken avatar :(
Created 6 years ago
by jiggy22
0 Members and 1 Guest are viewing this topic.
3,001 views
broken avatar :(
×
broken avatar :(
Location: us
Date Registered: 30 December 2016
Last active: 1 year ago
Posts
229
Respect
Forum Rank
Mr. Elemental
Primary Group
Member
My Contact & Social Links
More
×
jiggy22's Groups
jiggy22's Contact & Social Linksarchdukesquidlyllljiggy22
Hey, so with an easter egg I'm trying to script, I'm trying to get it the script to wait until all doors/areas on the map are open until it begins. I'm pretty sure it's supposed to be set as a flag_wait(); but I'm not exactly sure what to put for what it should be waiting for. For example, I tried doing:
Code Snippet
Plaintext
	flag_wait("zones_initialized");
Which is obviously quite wrong, but it should give you an idea as to what I mean by this. Anybody know how I could fix this? Thanks!
broken avatar :(
×
broken avatar :(
Location: us
Date Registered: 11 March 2014
Last active: 3 years ago
Posts
264
Respect
Forum Rank
Mr. Elemental
Primary Group
Member
Signature
"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live."
×
buttkicker845's Groups
buttkicker845's Contact & Social Links
There isn't a notify for when all the doors have been activated, but you can count each time a door is opened and once the count is greater than or equal to the amount of doors in the world then all doors have been opened.

You can do the same thing for determining if all zones are active, but instead checking if there is a zone that is not active like this
Code Snippet
Plaintext
IsAllZonesActive()
{
//get all the zone names
zoneKeys = GetArrayKeys(level.zones);

for(i = 0; i < zoneKeys.size; i++)
{
//check if the zone is not active
if(!level.zones[zoneKeys[i].is_enabled)
{
return false;
}
}

//if we get this far then all zones are active
return true;
}

PS: I haven't done much with zones nor have i tested this so it may not be the exact way to reference the zones but the concept is correct
Last Edit: February 05, 2018, 12:45:32 pm by buttkicker845
broken avatar :(
×
broken avatar :(
Location: us
Date Registered: 30 December 2016
Last active: 1 year ago
Posts
229
Respect
Forum Rank
Mr. Elemental
Primary Group
Member
My Contact & Social Links
More
×
jiggy22's Groups
jiggy22's Contact & Social Linksarchdukesquidlyllljiggy22
There isn't a notify for when all the doors have been activated, but you can count each time a door is opened and once the count is greater than or equal to the amount of doors in the world then all doors have been opened.

You can do the same thing for determining if all zones are active, but instead checking if there is a zone that is not active like this
Code Snippet
Plaintext
IsAllZonesActive()
{
//get all the zone names
zoneKeys = GetArrayKeys(level.zones);

for(i = 0; i < zoneKeys.size; i++)
{
//check if the zone is not active
if(!level.zones[zoneKeys[i].is_enabled)
{
return false;
}
}

//if we get this far then all zones are active
return true;
}

PS: I haven't done much with zones nor have i tested this so it may not be the exact way to reference the zones but the concept is correct

This is fantastic man, thank you so much! However, now my game is crashing on load. Any chance you can take a look at what I have so far and see what I'm doing wrong?

Code Snippet
Plaintext
#include common_scripts\utility;
#include maps\_utility;
#include maps\_zombiemode_utility;
#include maps\_zombiemode_zone_manager;

init()
{
    flag_wait("all_players_connected");
level thread IsAllZonesActive();
}


IsAllZonesActive()
{
//get all the zone names
zoneKeys = GetArrayKeys(level.zones);

for(i = 0; i < zoneKeys.size; i++)
{
//check if the zone is not active
if( !level.zones[zoneKeys[i]].is_enabled )
{
return false;
}
}

//if we get this far then all zones are active
return true;
wait 5;
level thread egg_start();
}

egg_start()
{
iPrintLnBold("All areas unlocked, now find the grave!");
level thread grave_random_spawn();
}

grave_random_spawn()
{
grave_spawn = [];
grave_spawn[0] = SetModel("zmb_dig_pile", (0, 0, 0));
grave_spawn[1] = SetModel("zmb_dig_pile", (0, 0, 0));

//array_thread(grave_spawns, ::grave_spawn_think);
}

With the script you provided before, I kept getting a syntax error due to this line:
Code Snippet
Plaintext
		if(!level.zones[zoneKeys[i].is_enabled)

Shouldn't there be an extra bracket after the variable so that it reads like this?
Code Snippet
Plaintext
		if(!level.zones[zoneKeys[i]].is_enabled)
Last Edit: February 05, 2018, 09:22:04 pm by jiggy22
broken avatar :(
×
broken avatar :(
Location: us
Date Registered: 11 March 2014
Last active: 3 years ago
Posts
264
Respect
Forum Rank
Mr. Elemental
Primary Group
Member
×
buttkicker845's Groups
buttkicker845's Contact & Social Links
Yes you are correct it should have had the second bracket to close the array index.

So there are a few issues with the script that i can see off hand.

First:
this
Code Snippet
Plaintext
flag_wait("all_players_connected");
should be something like this, it's possible that once the players have been connected the zones aren't initialized yet
Code Snippet
Plaintext
//wait to make sure all zones have been inited
//this is only because i can't find proof of flag_wait("zones_initialized") being a flag
while(!isDefined(level.zones))
{
wait(.05);
}

Second:
The function i gave you should be used to test if they've all been enabled
Code Snippet
Plaintext
//run until we have activated all zones
while(1)
{
//check if all the zones are active
if(IsAllZonesActive())
{
//since this isn't an infinite loop of any kind it doesn't need to be threaded
egg_start();
break;
}
wait(.05);
}


Third:
In order to use a model in script it must be preChached before the players are spawned, IE: before _load::Main() is called
Code Snippet
Plaintext
preCacheModel("zmb_dig_pile");
Finally:
You initialized the array properly but didn't populate using the correct function, setModel() must be called on a script_model and doesn't return anything
Code Snippet
Plaintext
//this will spawn a grave site at each location
spawnGraves()
{
//array of different locations to spawn the grave sits at
//this can be used to generate random locations for only a few of the graves
graveLocations = [];
graveLocations[graveLocations.size] = (0,0,0);//index = 0
graveLocations[graveLocations.size] = (100,200,0);//index = 1

//generate array
grave_spawns = [];

//populate the array with 2 script_models that are located at (0,0,0)
grave_spawns[grave_spawns.size] = spawn("script_model", graveLocations[grave_spawns.size]);// index = 0
grave_spawns[grave_spawns.size] = spawn("script_model", graveLocations[grave_spawns.size]);//index = 1

//set each script_model to the same model
for(i = 0; i < grave_spawns.size; i++)
{
grave_spawns[i] setModel("zmb_dig_pile");
}
}

hope this helps clearify some of the process for spawning scipt_models into the world
broken avatar :(
×
broken avatar :(
Location: us
Date Registered: 30 December 2016
Last active: 1 year ago
Posts
229
Respect
Forum Rank
Mr. Elemental
Primary Group
Member
My Contact & Social Links
More
×
jiggy22's Groups
jiggy22's Contact & Social Linksarchdukesquidlyllljiggy22
Thanks again for the help, this should certainly help me in the future. However, with my script, I'm still getting a fatal error whenever I load up the map. I think it may have something to do with my trigger thread. Wanna take a look?

Code Snippet
Plaintext
grave_spawn_think()
{
self.trigger = Spawn("trigger_radius", self.origin, 0, 100, 125);
self.trigger UseTriggerRequireLookAt();
self.trigger SetCursorHint("HINT_NOICON");

    while(true)
    {
    self.trigger waittill("trigger", player);
    if(isPlayer(player))
    {
hasWeapons = player GetWeaponsListPrimaries();
if(hasweapons.size > 1)
{
curWeapon = player GetCurrentWeapon();
player TakeWeapon(curWeapon);
player GiveWeapon("tesla_gun_zm");
player GiveMaxAmmo("tesla_gun_zm");
player SwitchToWeapon("tesla_gun_zm");
level thread maps\_zombiemode_audio::do_announcer_playvox( level.devil_vox["powerup"]["random_weapon"] );
}
else if ( self HasWeapon ("tesla_gun_zm"));
player GiveMaxAmmo ("tesla_gun_zm");
player SwitchToWeapon("tesla_gun_zm");
level thread maps\_zombiemode_audio::do_announcer_playvox( level.devil_vox["powerup"]["random_weapon"] );
else
{
player GiveWeapon("tesla_gun_zm");
player GiveMaxAmmo("tesla_gun_zm");
player SwitchToWeapon("tesla_gun_zm");
level thread maps\_zombiemode_audio::do_announcer_playvox( level.devil_vox["powerup"]["random_weapon"] );
}
}
wait 0.1;
}
self Delete();
self.trigger Delete();
}

Is it supposed to be called as an array thread at the end of the spawnGraves thread? Like this?

Code Snippet
Plaintext
	array_thread(grave_spawns, ::grave_spawn_think);
broken avatar :(
×
broken avatar :(
Location: us
Date Registered: 11 March 2014
Last active: 3 years ago
Posts
264
Respect
Forum Rank
Mr. Elemental
Primary Group
Member
×
buttkicker845's Groups
buttkicker845's Contact & Social Links
As far as i can tell the that should at least compile correctly, so you should try to launch your level while enabling "developer 1" in the console to find the issue.

The script does have a logic error though, A trigger radius if i remember correctly doesn't actually give the notify for "trigger" so you will need to do something closer to this
Code Snippet
Plaintext
//we can exit the loop by simply deleting the trigger
while(isDefined(self.trigger))
{
wait(.05)
players = GetPlayers();

for(i = 0; i < players.size; i++)
{
//player is touching the trigger and pressing {action}
if(is_player_valid(players[i]) && players[i] isTouching(self.trigger) && players[i] UseButtonPressed())
{
hasWeapons = player GetWeaponsListPrimaries();

//give weapons
//all this could probably be placed into its own function
if(hasweapons.size > 1)
{
curWeapon = player GetCurrentWeapon();
player TakeWeapon(curWeapon);
player GiveWeapon("tesla_gun_zm");
player GiveMaxAmmo("tesla_gun_zm");
player SwitchToWeapon("tesla_gun_zm");
level thread maps\_zombiemode_audio::do_announcer_playvox( level.devil_vox["powerup"]["random_weapon"] );
}
else if ( self HasWeapon ("tesla_gun_zm"));
player GiveMaxAmmo ("tesla_gun_zm");
player SwitchToWeapon("tesla_gun_zm");
level thread maps\_zombiemode_audio::do_announcer_playvox( level.devil_vox["powerup"]["random_weapon"] );
else
{
player GiveWeapon("tesla_gun_zm");
player GiveMaxAmmo("tesla_gun_zm");
player SwitchToWeapon("tesla_gun_zm");
level thread maps\_zombiemode_audio::do_announcer_playvox( level.devil_vox["powerup"]["random_weapon"] );
}

//delete the trigger to exit the loop
self.trigger Delete();
}
}
}


alternatively i developed a script that allowed you to use HudElements instead of trigger for interaction with objects, it helps lower the HintString limit that WAW has.
This is how you would use that system if you wanted to
Code Snippet
Plaintext
//Alternative option
//self = graveSite
//dist is how close you need to be to the grave to use
GraveTrigHintThink(dist)
{
while(isDefined(self))
{
players = GetPlayers();

for(i = 0; i < players.size; i++)
{
if(is_player_valid(players[i]) && distance(players[i].origin, self.origin) < dist)
{
self thread printDisplay(self, players[i], "Press and hold [{+action}] to pick up grave", dist);
}
}
wait(.05);
}

}

//self = graveSite
//dist is how close you need to be to the grave to use
GraveTrigUseThink(dist)
{
while(isDefined(self)
{
players = GetPlayers();

for(i = 0; i < players.size; i++)
{
if(is_player_valid(players[i]) && distance(players[i].origin, self.origin) < dist && players[i] UseButtonPressed())
{

//give weapons
//all this could probably be placed into its own function
hasWeapons = player GetWeaponsListPrimaries();
if(hasweapons.size > 1)
{
curWeapon = player GetCurrentWeapon();
player TakeWeapon(curWeapon);
player GiveWeapon("tesla_gun_zm");
player GiveMaxAmmo("tesla_gun_zm");
player SwitchToWeapon("tesla_gun_zm");
level thread maps\_zombiemode_audio::do_announcer_playvox( level.devil_vox["powerup"]["random_weapon"] );
}
else if ( self HasWeapon ("tesla_gun_zm"));
player GiveMaxAmmo ("tesla_gun_zm");
player SwitchToWeapon("tesla_gun_zm");
level thread maps\_zombiemode_audio::do_announcer_playvox( level.devil_vox["powerup"]["random_weapon"] );
else
{
player GiveWeapon("tesla_gun_zm");
player GiveMaxAmmo("tesla_gun_zm");
player SwitchToWeapon("tesla_gun_zm");
level thread maps\_zombiemode_audio::do_announcer_playvox( level.devil_vox["powerup"]["random_weapon"] );
}

//delete the graveSite to exit the useThink and hintSet loop
self Delete();
}
}
}
}

//will create a hud element for the player with the text that is passed in the parameter, will display the hud element as long as the player is close enough to see it
printDisplay(ent, player, message, dist)
{
//if the thread is called again stops the previous running thread
player notify("setting_hint");
player endon("setting_hint");

//if either the ent to display the message for or the player is undefined then stop the thread
if(!isDefined(ent) || !isDefined(player))
return;

//if there isnt a message passed then present a warning instead of the message
if(!isDefined(message))
message = "hint string for enity " + ent.targetname + " is not defined in printDisplay";

//if the destance for how close the player must be isnt set then use default distance
if(!isDefined(dist))
dist = 100;

//if the hud element isnt defined then create a new one and set its position in the middle of the screen
if(!isDefined(player.trigText))
{
player.trigText = NewClientHudElem( player );
player.trigText.alignX = "center";
player.trigText.alignY = "middle";
player.trigText.horzAlign = "center";
player.trigText.vertAlign = "middle";
player.trigText.y += 100;
player.trigText.foreground = true;
player.trigText.fontScale = 1.5;
player.trigText.alpha = 1;
player.trigText.color = ( 1.0, 1.0, 1.0 );
}

//if the element is defined then set the text to the message passed
if(isDefined(player.trigText))
{

player.trigText SetText( message );
}

//if the entity passed is a trigger of some kind then set the hint cursor to nothing
if(isDefined(ent.classname) && isSubStr(ent.classname, "trigger"))
ent SetCursorHint( "HINT_NOICON" );

//keep the hud element as long as the entity is defined, the player is valid and as long as the player is close enough
while(isDefined(ent) && isDefined(player) && is_player_valid(player) && distance(ent.origin, player.origin) < dist)
{
wait(.05);
}

//if the hud element is still defined destroy it from the screen
if(isDefined(player.trigText))
player.trigText destroy();
}//end printDisplay

 
Loading ...