SA-MP Forums Archive
Kill timer help. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Kill timer help. (/showthread.php?tid=607507)



Kill timer help. - karoliko - 20.05.2016

Hello i have a system that make you can buy weapons only for some time.
I want to make if the user death or when is changing map, to kill this timer.
Code:
public OnPlayerSpawn(playerid)
{
    SetTimerEx("TiempoCompra", 20000, false, "i", playerid); //Time to buy weapons.
    SendClientMessage(playerid,Verde,"[Informaciуn] {FFFFFF}Tienes un periodo de tiempo para equiparte, usa la tecla (H) para desplegar el menъ.");
}
forward TiempoCompra(playerid);
public TiempoCompra(playerid)
{
    TextDrawHideForPlayer(playerid, Carrito[0]); //Textdraws
    TextDrawHideForPlayer(playerid, Carrito[1]); // ""
    TextDrawHideForPlayer(playerid, Carrito[2]); // ""
    TextDrawHideForPlayer(playerid, Carrito[3]); // ""
    TextDrawHideForPlayer(playerid, Carrito[4]); // ""
    PuedeComprar[playerid] = 0; //Make the player cannot buy anything.
    SendClientMessage(playerid,Rojo,"[Informaciуn] {FFFFFF}El periodo de tiempo para equiparte ha expirado.");
    return 1;
}



Re: Kill timer help. - F1N4L - 20.05.2016

Code:
new Timer[MAX_PLAYERS];

public OnPlayerSpawn(playerid)
{
    Timer[playerid] = SetTimerEx("TiempoCompra", 20000, false, "i", playerid); //Time to buy weapons.
    SendClientMessage(playerid,Verde,"[Informaciуn] {FFFFFF}Tienes un periodo de tiempo para equiparte, usa la tecla (H) para desplegar el menъ.");
}
public OnPlayerDeath(playerid, killerid, reason)
{
	KillTimer(Timer[playerid]);
	return 1;
}
forward TiempoCompra(playerid);
public TiempoCompra(playerid)
{
    TextDrawHideForPlayer(playerid, Carrito[0]); //Textdraws
    TextDrawHideForPlayer(playerid, Carrito[1]); // ""
    TextDrawHideForPlayer(playerid, Carrito[2]); // ""
    TextDrawHideForPlayer(playerid, Carrito[3]); // ""
    TextDrawHideForPlayer(playerid, Carrito[4]); // ""
    PuedeComprar[playerid] = 0; //Make the player cannot buy anything.
    SendClientMessage(playerid,Rojo,"[Informaciуn] {FFFFFF}El periodo de tiempo para equiparte ha expirado.");
    return 1;
}
@EDIT

This timer does not need KillTimer!


Re: Kill timer help. - karoliko - 20.05.2016

Cuando cambia de ronda o cuando mueres, a veces hay mбs de un timer en marcha...


Re: Kill timer help. - F1N4L - 20.05.2016

ЎEs correcto!
Code:
new Timer[MAX_PLAYERS];
new bool:PuedeComprar[MAX_PLAYERS];

public OnPlayerSpawn(playerid)
{
	PuedeComprar[playerid] = true;
    Timer[playerid] = SetTimerEx("TiempoCompra", 20000, false, "i", playerid); //Time to buy weapons.
    SendClientMessage(playerid,Verde,"[Informaciуn] {FFFFFF}Tienes un periodo de tiempo para equiparte, usa la tecla (H) para desplegar el menъ.");
}
public OnPlayerDeath(playerid, killerid, reason)
{
	if(PuedeComprar[player] == true)
	{
		KillTimer(Timer[playerid]);
		TiempoCompra(playerid);
	}
	
	return 1;
}
forward TiempoCompra(playerid);
public TiempoCompra(playerid)
{
    TextDrawHideForPlayer(playerid, Carrito[0]); //Textdraws
    TextDrawHideForPlayer(playerid, Carrito[1]); // ""
    TextDrawHideForPlayer(playerid, Carrito[2]); // ""
    TextDrawHideForPlayer(playerid, Carrito[3]); // ""
    TextDrawHideForPlayer(playerid, Carrito[4]); // ""
    PuedeComprar[playerid] = false; //Make the player cannot buy anything.
    SendClientMessage(playerid,Rojo,"[Informaciуn] {FFFFFF}El periodo de tiempo para equiparte ha expirado.");
    return 1;
}



Re: Kill timer help. - karoliko - 20.05.2016

El primer post me sirviу, Ўmuchas gracias!