Notify / Endon / Waittill

From COD Modding & Mapping Wiki
Revision as of 19:54, 15 October 2008 by Zeroy (talk | contribs) (New page: == Notify / Endon / Waittill == Image:Nutshell.png These 3 functions can be used to do many things, they are often used to "end" a script/function from running, they can be used t...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Notify / Endon / Waittill

These 3 functions can be used to do many things, they are often used to "end" a script/function from running, they can be used to stop a script running until another part of the code is ready for it to continue and it can be used in simple debugging (although, not the only way).

The functions are often used mainly on a player or the level. I will provide an example of each.

level endon ("thread_restart");

and from any gametype script.

self notify("killed_player");

If you use "player waittill" or "player endon", then using a "level notify" will not trigger any of the 2.

To use the functions is very easy. First you decide on what you want the function to be called on.

If the action is going to happen to a specific player, then use "player" (although, this will need to change depending on how the player is being called, i.e. self, other, user, etc), or if you want the function to work for the entire script, use level.

Then you must decide which function to use. You need to choose, either "endon" or "waittill", they are both self explanatory, one will end when called, and the other will 'wait'.


Next you decide on a unique 'call' for the function. For exmaple...

level endon("a_unique_call");

Now. when you want the 'endon' function to happen, you will use the 'Notify' function...

level notify("a_unique_call");

Anything with the unique call will be activated, so, multiple 'endon' and 'waittill' functions can be placed around your script.

Here is a quick example of it in use in multiple threads in the DM gametype...

spawnPlayer()
{
  self endon("disconnect");
  self notify("spawned");
  self notify("end_respawn");
  
  /*... Code Snipped ...*/
  
  self notify("spawned_player");
}
Callback_PlayerKilled(?, ?, ?, ?, ?, ?, ?, ?, ?)
{
  self endon("spawned");
  self notify("killed_player");
  
  attacker notify("update_playerhud_score");
}
spawnSpectator(origin, angles)
{
  self notify("spawned");
  self notify("end_respawn");
}

All the threads depend on those notifies being called. Here is a quick easy demonstration...

waiting_thread()
{
  level waittill("stop_waitting", user);
  iprintln("This thread has stopped waitting, because " + user.name + " touched the trigger");
}
trigger()
{
  trigger waittill("trigger", user);
  level notify("stop_waitting", user);
}