02.04.2013, 16:44
Hey guys How can I regenerate the HP of my character? for example only have 20% HP or lower, then it'll automatically regen my HP for like 2% per second until it reaches my HP to 50% only
for(new i; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
new Float:health;
GetPlayerHealth(i, health);
if(health < 20)
{
SetPlayerHealth(i, health+2);
GameTextForPlayer(i, "Healt regeneration...", 1100, 6);
}
}
}
for create globaltiomer u need:
new glbltimer; //top
forward GlobalTimer(); //top
//in public OnGameModeInit() add:
glbltimer = SetTimer("GlobalTimer", 1000, 1);
//and put code to new timer public
public GlobalTimer()
{
//code
}
//Under OnPlayerSpawn
SetTimerEx( "HPUpdate" ,500,1, "i" ,playerid);//This will be the timer which updates the Health
//Put this at the bottom of your script
forward HPUpdate(playerid);
public HPUpdate(playerid)
{
new Float:HP//We're using this to define the player's health, it should be a float
GetPlayerHealth(playerid,HP);//This will get the player's current health
if(HP >= 50 ) return 1;//If the health is greater than 50 the timer will return here.
if(HP < 50 )//If the health is less than 50 the
{
SetPlayerHealth(playerid, HP + 5);//We'll be giving the player 5 Health point every half a second, you could change that.
}
}
GameModeExitFunc()
KillTimer(glbltimer);