Timer isn't working. - 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: Timer isn't working. (
/showthread.php?tid=349009)
Timer isn't working. -
cloudysky - 07.06.2012
Ok recently I've been trying to make something where the gamemode detects when a player is close to another player and gives them health. I tried using OnPlayerUpdate, but that ended up lagging the server. Now I've tried a timer, and it isn't working. If someone could take a look at it I would appreciate that.
pawn Код:
forward MedicTimer(playerid)
under OnGamemodeInit
pawn Код:
SetTimer( "MedicTimer", 1000, true);
pawn Код:
public MedicTimer(playerid)
{
foreach(Player, i)
{
if(IsPlayerConnected(i))
{
if(PlayerInfo[i][Medic] == 1 && PlayerInfo[i][Army] == 1)
{
if(playerid == i) return 0;
{
new Float:x, Float:y, Float:z;
GetPlayerPos(i, x, y, z);
if(IsPlayerInRangeOfPoint(playerid, 1.0, x, y, z))
{
SendClientMessage(playerid, COLOUR_GREEN, "HEALED" );
SendClientMessage(playerid, COLOUR_GREEN, "Thank the medic, who risked his life to save yours!" );
}
else
{
if(PlayerInfo[playerid][Medic] == 1 || PlayerInfo[playerid][Enemy] == 1 || PlayerInfo[playerid][OutOfMedKits] == 1)
{
return 0;
}
}
}
}
}
}
return 1;
}
Re: Timer isn't working. -
MadeMan - 07.06.2012
pawn Код:
public MedicTimer()
{
foreach(Player, playerid)
{
if(IsPlayerConnected(playerid))
{
if(PlayerInfo[playerid][Medic] == 1 && PlayerInfo[playerid][Army] == 1)
{
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
foreach(Player, i)
{
if(IsPlayerConnected(i) && i != playerid)
{
if(IsPlayerInRangeOfPoint(i, 1.0, x, y, z))
{
new Float:health;
GetPlayerHealth(i, health);
if(health < 100.0)
{
SetPlayerHealth(i, 100.0);
SendClientMessage(i, COLOUR_GREEN, "HEALED" );
SendClientMessage(i, COLOUR_GREEN, "Thank the medic, who risked his life to save yours!" );
}
}
}
}
}
}
}
}
Re: Timer isn't working. -
cloudysky - 07.06.2012
Thanks but that will still heal the enemy etc