Health Regeneration [HELP +rep] -
adios1 - 02.04.2013
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
Re: Health Regeneration [HELP +rep] -
brawrr - 02.04.2013
put on globaltimer
PHP код:
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);
}
}
}
Re: Health Regeneration [HELP +rep] -
adios1 - 02.04.2013
what do you mean put on globaltimer? do you mean
public GlobalTimer() ??
Re: Health Regeneration [HELP +rep] -
brawrr - 02.04.2013
yes, if u have this public in ur mode
Re: Health Regeneration [HELP +rep] -
adios1 - 02.04.2013
what if i don't have it ?
Re: Health Regeneration [HELP +rep] -
brawrr - 02.04.2013
u can create timer for that func or put this code in created timer
PHP код:
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
}
Re : Health Regeneration [HELP +rep] -
DaRk_RaiN - 02.04.2013
Long story short, set a timer when the player spawns
pawn Код:
//Under OnPlayerSpawn
SetTimerEx( "HPUpdate" ,500,1, "i" ,playerid);//This will be the timer which updates the Health
pawn Код:
//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.
}
}
Re: Health Regeneration [HELP +rep] -
MP2 - 02.04.2013
No. You don't want to create a timer for EVERY player, because that's going to eat up your CPU.
You want a SINGLE global timer (as brawrr rightly said) that is set to 1 second (which most servers have anyway) and in there you loop through all players and do stuff.
As for how brawrr said how to create the global timer, you don't need to assign it to a variable - because you don't need it. You only need to store timer IDs if you wish to use KillTimer(), which you never will because the timer will ALWAYS be running!
Re: Health Regeneration [HELP +rep] -
adios1 - 02.04.2013
warning 204: symbol is assigned a value that is never used: "glbltimer"
but its working!
Thank you ! +rep !
Re: Health Regeneration [HELP +rep] -
brawrr - 02.04.2013
adios1, in public
PHP код:
GameModeExitFunc()
add
PHP код:
KillTimer(glbltimer);