Health Regeneration [HELP +rep]
#1

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
Reply
#2

put on globaltimer

PHP код:
for(new iMAX_PLAYERSi++)
{
    if(
IsPlayerConnected(i))
    {
        new 
Float:health;
        
GetPlayerHealth(ihealth);
        if(
health 20)
        {
            
SetPlayerHealth(ihealth+2);
            
GameTextForPlayer(i"Healt regeneration..."11006);
        }
    }

Reply
#3

what do you mean put on globaltimer? do you mean

public GlobalTimer() ??
Reply
#4

yes, if u have this public in ur mode
Reply
#5

what if i don't have it ?
Reply
#6

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"10001);
//and put code to new timer public
public GlobalTimer()
{
 
//code

Reply
#7

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.
    }
}
Reply
#8

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!
Reply
#9

warning 204: symbol is assigned a value that is never used: "glbltimer"

but its working!

Thank you ! +rep !
Reply
#10

adios1, in public

PHP код:
GameModeExitFunc() 
add

PHP код:
KillTimer(glbltimer); 
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)