Timer isn't working.
#1

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;
}
Reply
#2

pawn Код:
forward MedicTimer();
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!" );
                            }
                        }
                    }
                }
            }
        }
    }
}
Reply
#3

Thanks but that will still heal the enemy etc
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)