Health regeneration. -
rangerxxll - 07.03.2013
I'm trying to make "Talents" into my script, and one talent is Regeneration. I've made this code, but it doesn't seem to work. I want the player (Assuming they have the regeneration talent.) to regenerate 20 health every 15 seconds.
What's wrong with the code?
pawn Код:
forward Regeneration(playerid);
public Regeneration(playerid)
{
new Float:Health;
GetPlayerHealth(playerid, Health);
if(Health < 100)
{
SetPlayerHealth(playerid, Health+20);
}
}
//This is under OnPlayerSpawn.
if(PlayerInfo[playerid][pTalent] == 2)
{
SendClientMessage(playerid,COLOR_GREEN, "(Regeneration Talent): You now regenerate 20 health every 15 seconds.");
SetTimerEx("Regeneration", 15000, true, "%i", playerid);
}
Respuesta: Health regeneration. -
Strier - 07.03.2013
pawn Код:
SetTimer("Regeneration", 15000, true); //under ongamemodeinit
forward Regeneration(playerid);
public Regeneration(playerid)
{
if(PlayerInfo[playerid][pTalent] == 2)
{
new Float:Health;
GetPlayerHealth(playerid, Health)
if(Health < 100)
{
SetPlayerHealth(playerid, GetPlayerHealth(playerid, Health)+20);
}
}
return 1;
}
Imo this should work, didn't test it.
Re: Respuesta: Health regeneration. -
kaisersouse - 07.03.2013
Quote:
Originally Posted by Strier
pawn Код:
SetTimer("Regeneration", 15000, true); //under ongamemodeinit
forward Regeneration(playerid); public Regeneration(playerid) { if(PlayerInfo[playerid][pTalent] == 2) { new Float:Health; GetPlayerHealth(playerid, Health) if(Health < 100) { SetPlayerHealth(playerid, GetPlayerHealth(playerid, Health)+20); } } }
Imo this should work, didn't test it.
|
It won't, because SetTimerwon't send playerid and you've told him to put in under OnGameModeInit (which also doesn't handle playerid)
Respuesta: Health regeneration. -
Strier - 07.03.2013
Thanks kaiser.
Fix:
pawn Код:
SetTimer("Regeneration", 15000, true); //under ongamemodeinit
forward Regeneration();
public Regeneration()
{
for(new playerid = 0; playerid < MAX_PLAYERS; playerid++)
{
if(PlayerInfo[playerid][pTalent] == 2)
{
new Float:Health;
GetPlayerHealth(playerid, Health)
if(Health < 100)
{
SetPlayerHealth(playerid, GetPlayerHealth(playerid, Health)+20);
}
}
}
return 1;
}
Re: Health regeneration. -
LarzI - 07.03.2013
Does the message get sent? If not, then there's something wrong with your talents variable. If it is, then I'm not really sure why it doesn't work.
Re: Respuesta: Health regeneration. -
kaisersouse - 07.03.2013
Quote:
Originally Posted by Strier
Thanks kaiser.
Fix:
pawn Код:
SetTimer("Regeneration", 15000, true); //under ongamemodeinit
forward Regeneration(); public Regeneration() { for(new i = 0; i < MAX_PLAYERS; i++) { if(PlayerInfo[i][pTalent] == 2) { new Float:Health; GetPlayerHealth(i, Health) if(Health < 100) { SetPlayerHealth(i, GetPlayerHealth(i, Health)+20); } } } return 1; }
|
Close. I've fixed it above.
Re: Health regeneration. -
rangerxxll - 07.03.2013
The message does get sent. But the health doesn't regenerate over time.
EDIT: Appreciated.
Re: Health regeneration. -
kaisersouse - 07.03.2013
Quote:
Originally Posted by rangerxxll
The message does get sent. But the health doesn't regenerate over time.
EDIT: Appreciated.
|
Strier's code (the version I edited...do NOT use 'playerid' as the control variable in loop) should work for you
Re: Health regeneration. -
LarzI - 07.03.2013
Oh god I'm stupid, sorry. You're not supposed to have the percentage-symbol infront of 'i' in SetTimerEx.
pawn Код:
SetTimerEx("Regeneration", 15000, true, "i", playerid);