SA-MP Forums Archive
[help] lose hp when near NPC how can i do ? - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: [help] lose hp when near NPC how can i do ? (/showthread.php?tid=180392)



[help] lose hp when near NPC how can i do ? - andruz99 - 01.10.2010

Can anyone help me, im trying to do like if you are near certin NPC then you will lose hp how can i do like that?


Re: [help] lose hp when near NPC how can i do ? - Mauzen - 01.10.2010

pawn Код:
//Somewhere in your script, best would be after you created the npc
SetTimerEx("DamagePlayersInRange", damage_interval, 1, "iff", npcid, range, damage);

forward public DamagePlayersInRange(npcid, Float:range, Float:damage);
public DamagePlayersInRange(npcid, Float:range, Float:damage)
{
    new Float:x, Float:y, Float:z;
    new Float:hp;
    GetPlayerPos(npcid, x, y, z);
    for(new i = 0; i < MAX_PLAYERS; i ++)
    {
        if(!IsPlayerConnected(i)) continue;
        if(IsPlayerInRangeOfPoint(i, range, x, y, z))
        {
            GetPlayerHealth(i, hp);
            SetPlayerHealth(i, hp - damage);
        }
}
Untested as always