Health regeneration.
#1

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);
     
    }
Reply
#2

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.
Reply
#3

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)
Reply
#4

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;
}
Reply
#5

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.
Reply
#6

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

The message does get sent. But the health doesn't regenerate over time.

EDIT: Appreciated.
Reply
#8

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

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);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)