Author Topic: Timing and Deactivation  (Read 674 times)

Is there a way to activate something (perhaps with a slash command) and deactivate it after a period of time?

For example, a command that changed the color of the head node, but deactivated it after 15 seconds. Thanks for the help!

Code: [Select]
function servercmdMakeHeadBlue(%client)
{
 if(!isObject(%client.player) || %client.player.getState() $= "Dead")
  return;
 if(%client.player.getDatablock().shapefile !$= "base/data/shapes/player/m.dts")
  return;
 %client.player.setNodeColor("headskin","0 0 1 1");
 schedule(15 * 1000,0,resetHeadColor,%client.player);
}

function resetHeadColor(%player)
{
 if(!isObject(%player))
  return;
 %player.setNodeColor("headskin",%player.client.headColor);
}

Code: [Select]
function servercmdMakeHeadBlue(%client)
{
 if(Player Doesn't Exist Or Player is Dead)
  Exit Function
 if(Player Isn't Standard i.e. Horse)
  Exit Function
 Set Color Of Head To Blue (R G B A)
 Schedule([15*1000]ms,0,ResetHeadColor,Player)
}

function resetHeadColor(%player)
{
 if(Player Doesn't Exist)
  Exit Function
 Set Color Of Head To Player's Client's Preference
}

schedule(%time,0,%function,%arg0,[... %argN]);
%object.schedule(%time,%function,%arg0,[... %argN]);
(Technically, ShapeBase::schedule(%time,%function,%arg0,[... %argN]);)

If you use %object.schedule, do not put the 0 in - it indicates to call *ObjectType*::function, as in:
%client.schedule(1000,applyBodyParts);
will call GameConnection::applyBodyParts(); in one second.