SetTimer
Jump to navigation
Jump to search
Description:
This will create set a timer, which will be triggered when the given time has passed.
Parameters:
(FunctionName, interval, repeat)
FunctionName : The name of the function to be called.
interval : The amount of time (in milliseconds) after which the function will be called.
repeat : 1, if the timer is to be repeated, 0 otherwise.
Return Values:
The ID of the timer created, which can be used with KillTimer
Example
//Copyright Kye 2009 //modified by habi 2022 function OnNPCScriptLoad() { SetTimer("TimerTest",10000,1); } function TimerTest() { local msg; local name; local pos; local Distance; local x; local num_streamed_in = 0; local num_connected = 0; x=0; while(x!=MAX_PLAYERS) { if(IsPlayerConnected(x)) { num_connected++; if(IsPlayerStreamedIn(x)) { num_streamed_in++; name=GetPlayerName(x); pos=GetPlayerPos(x); Distance=GetDistanceFromMeToPoint(pos); msg=format("I see %s @ %f units with state:%d health:%d armour:%d weapon:%d", name,Distance,GetPlayerState(x),GetPlayerHealth(x),GetPlayerArmour(x),GetPlayerArmedWeapon(x)); SendChat(msg); if(GetPlayerState(x) == PLAYER_STATE_DRIVER) { msg=format("I see %s driving vehicle: %d",name,GetPlayerVehicleID(x)); SendChat(msg); } } } x++; } msg=format("I have %d connected players with %d streamed in",num_connected,num_streamed_in); SendChat(msg); }
Related Functions
The following functions may be helpful as they relate to this function in one way or another.