PDA

View Full Version : Timer isn't working.


cloudysky
07/06/2012, 03:15 PM
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.

forward MedicTimer(playerid)

under OnGamemodeInit
SetTimer( "MedicTimer", 1000, true);

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;
}

MadeMan
07/06/2012, 05:33 PM
forward MedicTimer();


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!" );
}
}
}
}
}
}
}
}

cloudysky
07/06/2012, 06:58 PM
Thanks but that will still heal the enemy etc