Kill a timer within a function?
#1

Hello, I wonder how to do a SetTimerEx and the kill it again? I don't want to place the timer in the public scope becuse i want different timers for each player when they call my function.
It's like :
Код:
New TimerCounter[MAX_PLAYERS];

YCMD:starttimer(){
TimerCounter[playerid] = SetTimerEx("Timer", 1000, true, "i", playerid);
}

Public Timer(playerid){
   if(timercounter[playerid] < 10){
   SendClientMessage(playerid, COLOR_YELLOW, "Timer have passed one scound");
   TimerCounter[playerid] ++;
   }
   else{
   SendClientMessage(playerid, COLOR_YELLOW, "Ten secounds have now passed and the timer have been killed");
   }
}
(notice that's not the code it's just a thing i made to get you to understand my problem)
Thanks for all answers!
Reply
#2

ok post what you need and POST THE SCRIPT so we can see what you need to add/delete from there please.
Reply
#3

Quote:
Originally Posted by [A]ndrei
Посмотреть сообщение
ok post what you need and POST THE SCRIPT so we can see what you need to add/delete from there please.
I just want to know how to kill a timer but here's the code then(it's my system to load your hp when you die on my rp server)i call this function on player spawn if the player is dead:
Код:
stock HospitalSpawn(playerid){
	new Timer:HospitalTimer;
	if(playerinfo[playerid][dead] == 2){
		HospitalTimer = SetTimerEx("HospitalLoad", 200, 1, "i", playerid);
	}
}
public HospitalLoad(playerid){
	if(playerinfo[playerid][health] < 100){
	GivePlayerHpEx(playerid, 1);
           }
            else{
  	KillTimer(HospitalTimer);
  	playerinfo[playerid][dead] = 1;//more code to spawn the player will be added here
           }
}
(hate the indentation in this site when you can't use [TAB], someone know a way to do it?)
Reply
#4

Use KillTimer to kill a timer.
Reply
#5

Quote:
Originally Posted by HellSphinX
Посмотреть сообщение
Use KillTimer to kill a timer.


I was asking for killing a timer that's not in the public scope that's another thing.
Reply
#6

didn't get you. Can you explain me it so I can help you? Which timer do you want to kill?
Reply
#7

Since you create a global array to store the timer ID for every player, the KillTimer does not have to be in the stock function that you use to create the timer.

But one thing that your code in the 1st post gets wrong is what SetTimerEx returns. SetTimerEx returns the timer's ID, not anything else. If you want to decrement a variable in there, you should create another array to store the data for players.

pawn Код:
new playerTimerID[MAX_PLAYERS],
    playerTimerVariable[MAX_PLAYERS];

stock MakeSomeTimer(playerid)
{
    playerTimerVariable[playerid] = 10;
    playerTimerID[playerid] = SetTimerEx("SomeTimer", 1000, true, "i", playerid);
}

forward SomeTimer(playerid);
public SomeTimer(playerid)
{
    playerTimerVariable[playerid] --;
    if(playerTimerVariable[playerid] == 0)
    {
        KillTimer(playerTimerID[playerid]);
    }
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)