KillTimer()
#1

Hey!

If I use KillTimer when the timer do not active it crashes my server?

Nonameman
Reply
#2

Can you show us the line where you use SetTimer or SetTimerEx pls?
Reply
#3

Quote:
Originally Posted by Last_Stand_Guardian
Посмотреть сообщение
Can you show us the line where you use SetTimer or SetTimerEx pls?
pawn Код:
new pvptimer;

dcmd_pvp(playerid, params[])
{
    #pragma unused params
    new
        Pvp = GetPVarInt(playerid, "Pvp");
    if(Pvp == 0)
    {
        KillTimer(pvptimer);
        SetPVarInt(playerid, "Pvp", 1);
        SendClientMessage(playerid, colorPVP, "PVP Bekapcsolva!");
    }
    else if(Pvp == 1)
    {
        SendClientMessage(playerid, colorPVP, "Vбrnod kell 5 percet hogy kikapcsoljon a PVP!");
        pvptimer = SetTimerEx("PvpOff", 5*60*1000, false, "d", playerid);
    }
    return 1;
}

forward PvpTimer(playerid);
public PvpTimer(playerid)
{
    SetPVarInt(playerid, "Pvp", 0);
    SendClientMessage(playerid, colorPVP, "PVP Kikapcsolva!");
    return 1;
}
Reply
#4

Try this :
Код:
new pvptimer[MAX_PLAYERS];
Код:
dcmd_pvp(playerid, params[])
{    
	#pragma unused params    

	new Pvp = GetPVarInt(playerid, "Pvp");    
	if(Pvp == 0)    
	{        
		KillTimer(pvptimer);        //if the value starts at 0 then the timer is not even running
		SetPVarInt(playerid, "Pvp", 1);        
		SendClientMessage(playerid, colorPVP, "PVP Bekapcsolva!");    
	}    
	if(Pvp == 1)    
	{        
		SendClientMessage(playerid, colorPVP, "Vбrnod kell 5 percet hogy kikapcsoljon a PVP!");        
		pvptimer[playerid] = SetTimerEx("PvpOff", 300000, 0, "i", playerid);    
	}    
	return 1;
}
Код:
forward PvpTimer(playerid);

public PvpTimer(playerid)
{    
	SetPVarInt(playerid, "Pvp", 0);    
	SendClientMessage(playerid, colorPVP, "PVP Kikapcsolva!");    
	return 1;
}
Reply
#5

Quote:
Originally Posted by DJDhan
Посмотреть сообщение
Try this :
Код:
new pvptimer;
Код:
dcmd_pvp(playerid, params[])
{    
	#pragma unused params    

	new Pvp = GetPVarInt(playerid, "Pvp");    
	if(Pvp == 0)    
	{        
		KillTimer(pvptimer);        
		SetPVarInt(playerid, "Pvp", 1);        
		SendClientMessage(playerid, colorPVP, "PVP Bekapcsolva!");    
	}    
	if(Pvp == 1)    
	{        
		SendClientMessage(playerid, colorPVP, "Vбrnod kell 5 percet hogy kikapcsoljon a PVP!");        
		pvptimer = SetTimerEx("PvpOff", 300000, 0, "i", playerid);    
	}    
	return 1;
}
Код:
forward PvpTimer(playerid);

public PvpTimer(playerid)
{    
	SetPVarInt(playerid, "Pvp", 0);    
	SendClientMessage(playerid, colorPVP, "PVP Kikapcsolva!");    
	return 1;
}
With IF and ELSEIF this will do the same thing I think.
Reply
#6

The problem is that PVars are by default 0 up to the moment when we set them to an another value.
So when you use this command you're firstly trying to kill a timer who haven't started yet.
Try:
pawn Код:
new pvptimer = -1;
pawn Код:
if(pvptimer != -1) KillTimer(pvptimer);
Secondly:
You should use: new pvptimer[MAX_PLAYERS] = -1; or PVars to save the timerid, because when you kill this timer, you kill it for everybody xD ^^
Reply
#7

Quote:
Originally Posted by Last_Stand_Guardian
Посмотреть сообщение
The problem is that PVars are by default 0 up to the moment when we set them to an another value.
So when you use this command you're firstly trying to kill a timer who haven't started yet.
Try:
pawn Код:
new pvptimer = -1;
pawn Код:
if(pvptimer != -1) KillTimer(pvptimer);
Secondly:
You should use: new pvptimer[MAX_PLAYERS] = -1; or PVars to save the timerid, because when you kill this timer, you kill it for everybody xD ^^
Thanks.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)