Dieing System Help - 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: Dieing System Help (
/showthread.php?tid=407213)
Dieing System Help -
jakejohnsonusa - 13.01.2013
Ok so I'm not really sure where to begine for this, but I want to make a system for my RP GM that detects when a players health falls bellow 40... and when it does they begin to slowly loose health until they die. How can I make this and where in the GM would I put it?
Thanks: jakejohnsonusa
Re: Dieing System Help -
Threshold - 13.01.2013
https://sampwiki.blast.hk/wiki/OnPlayerTakeDamage
Under OnPlayerTakeDamage, check if their health is below 40, and then start a repeating timer which lowers their health slowly, and will end/kill itself once they die.
Re: Dieing System Help -
jakejohnsonusa - 13.01.2013
How should I set a timer that would do this though? Like every 3000 milliseconds the HP drops by 1 (so in 2minnutes they would die). How can I write a Timer like this, I always mess up timers...
Thanks: jakejohnsonusa
+1 Rep for the help so far!
Re: Dieing System Help -
Threshold - 13.01.2013
Sorry for the late response, the post above was the last one I made before going out, so this is an example of how you might do it:
pawn Код:
new Dying[MAX_PLAYERS]; //Will detect whether they are dying or not
public OnPlayerConnect(playerid)
{
Dying[playerid] = 0; //Player is not currently dying
return 1;
}
public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid) //Called when a player takes damage
{
new Float:hp;
GetPlayerHealth(playerid, hp); //Get the player's health
if(hp < 40.0) //If their health is lower than 40
{
if(Dying[playerid] == 0) //If they are not already dying (We don't want to set a timer twice)
{
SetTimerEx("DeathTimer", 3000, true, "i", playerid); //Set a timer every 3 seconds to go off (repeating)
Dying[playerid] = 1; //They are now dying
SendClientMessage(playerid, 0xFF0000FF, "You are injured and losing health slowly."); //Change this message however you want, or remove it, the choice is yours
}
}
return 1;
}
public OnPlayerDeath(playerid, killerid, reason) //Called when a player dies
{
if(Dying[playerid] == 1)
{
KillTimer(DeathTimer(playerid));
Dying[playerid] = 0;
}
return 1;
}
forward DeathTimer(playerid);
public DeathTimer(playerid) //Our timer that will activate every 3 seconds
{
if(Dying[playerid] == 1) //If they are dying
{
new Float:hp;
GetPlayerHealth(playerid, hp);
if(hp < 40) //If health is still below 40 *Bug prevention*
{
SetPlayerHealth(playerid, hp - 1); //Take 1 off their health
}
else
{
Dying[playerid] = 0; //Health is not below 40, they are no longer dying
KillTimer(DeathTimer(playerid)); //They are no longer dying
}
}
else if(Dying[playerid] == 0)
{
KillTimer(DeathTimer(playerid)); //If they are not dying, they no longer need the timer, so kill it to prevent bugging.
}
return 1;
}