PDA

View Full Version : Health Regen


superbird
01-09-2012, 06:24
Hey I am trying to get health regen working and I have had 2 different outcomes.

1. Health regen works for the way it should but stops altogether all of a sudden.

2. Health regen works for 1 person the whole game.

This is the code that comes up with 2.
public Action:PlayerRegen(Handle:timer, any:user)
{
for (new i=1; i<=MaxClients; i++)
{
if (GetClientHealth(i) <= 500)
{
if (GetClientTeam(i) == 2)
{
SetEntityHealth(i, GetClientHealth(i) + 20);
}
}
if (GetClientHealth(i) >= 500)
{
if (GetClientTeam(i) == 2)
{
SetEntityHealth(i, 500);
}
}
}
}
It is running off a timer, that is starting on round start and being killed on round end.

I am really stumped on this one. I'd assume its something to do with MaxClients. Console is constantly spammed with it looking for the player that's 1 above the current amount of players.

Bacardi
01-09-2012, 06:52
Check always, when loop all players, (or check some random indexs ) indexs from 1 to what is server maxplayers example 30...
IsClientInGame (http://docs.sourcemod.net/api/index.php?fastload=show&id=404&)

You definitely found errors about this in your SM logs.

When loop all players usually done like this

for(new i = 1; i <= MaxClients; i++) // start loop 1 to maxplayers
{
if(IsClientInGame(i)) // Check first this index, is this player who is in server. False when empty, no player !
{
// Then do what ever you like

}
}

*edit
someone correct this if bullshit..

superbird
01-09-2012, 23:44
Thanks I'll give it a whirl.