SA-MP Forums Archive
Help with Anti Avoid Death - 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: Help with Anti Avoid Death (/showthread.php?tid=527851)



Help with Anti Avoid Death - GeekSiMo - 24.07.2014

I got some teleports commands and a /heal command to refill health, i want to add : that the player must wait 10 seconds before using them from the last damage.
/heal command:
pawn Код:
CMD:heal(playerid,params[])
{
    GivePlayerMoney(playerid, -500);
    SetPlayerHealth(playerid, 100.0);
    return 1;
}
+Rep for helpers!!!


Re: Help with Anti Avoid Death - Battlezone - 24.07.2014

pawn Код:
//in the beginning
new bool:recentlydamaged[MAX_PLAYERS];

//Under OnPlayerTakeDamage:
recentlydamaged[playerid] = true;
SetTimerEx("RecentDTimer", 10000, 0, "d", playerid);

//the timer
forward RecentDTimer(playerid);
public RecentDTimrt(playerid) return recentlydamaged[playerid] = false;

//your cmd
CMD:heal(playerid,params[])
{
    if(recentlydamaged[playerid]) return SendClientMessage(playerid, -1, "ERROR: You have been recently damaged");
    GivePlayerMoney(playerid, -500);
    SetPlayerHealth(playerid, 100.0);
    return 1;
}



Re: Help with Anti Avoid Death - Wizzy951 - 24.07.2014

I believe in this particular case using timers is not a necessary, you can use gettime() instead.


Re: Help with Anti Avoid Death - Battlezone - 24.07.2014

Yeah, that would be more efficient


Re: Help with Anti Avoid Death - GeekSiMo - 24.07.2014

or Gettickcount ,??


Re: Help with Anti Avoid Death - Battlezone - 24.07.2014

pawn Код:
//in the beginning
new count[MAX_PLAYERS];

//Under OnPlayerTakeDamage:
count[playerid] = GetTickCount();

//your cmd
CMD:heal(playerid,params[])
{
    if(GetTickCount() - count[playerid]  > 10000) return SendClientMessage(playerid, -1, "ERROR: You have been recently damaged");
    GivePlayerMoney(playerid, -500);
    SetPlayerHealth(playerid, 100.0);
    return 1;
}



Re: Help with Anti Avoid Death - GeekSiMo - 24.07.2014

Thanks!!! +Rep !