Again problem with timer

Started by Spice, Jul 26, 2015, 07:45 AM

Previous topic - Next topic

Spice

i was trying to do that when 1 hour pas all players in my server get healed
but problem is it heals all players  after 5 to 10 seconds here is code

function healallp( )
{
 Message("** All Players in server have been healed after 1 hour.");
if( GetPlayers() > 0 )
{
 for(local i=0; i<GetPlayers(); i++ )
 {
   local player = FindPlayer( i );
    if ( ( status[ player.ID ].IsReg == true ) && ( status[ player.ID ].IsLogged == true) )
   {
PrivMessage( player, "You have been healed.");
player.Health = 100;
    }
  }
}
}

Since this function works fine but main problem is in timer
i add it
 on Script load
NewTimer( "healallp", 3600000, 0 );
please tell me where i am doing it wrong.?...THANKX

Spice

i solved it my self but it gives an error if a player come then he quit..
for example there were two players in server
1st id = 0
2nd id = 1
if 1st player quit then after some time when the function is called again it says id does not exsits...

MacTavish

I am not sure about the problem but you can try this

function healallp( )
{
 Message("** All Players in server have been healed after 1 hour.");
if( GetPlayers() ==0 ) return;
else
{
 for(local i=0; i<GetMaxPlayers(); i++ )
 {
   local player = FindPlayer( i );
    if ( player && player.IsSpawned)
   {
 PrivMessage( player, "You have been healed.");
 player.Health = 100;
    }
  }
}
}

Just change your function with this

You wasnt checking that the player is still in server and Spawned

Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P

DizzasTeR

@Beztone, Its not about spawn, its about GetPlayers(), it returns the number of people playing, which is not in sequence. For example:

player1 joined ID: 0

player2 joined ID: 1

player3 joined ID: 2


You used:
for( local i = 0; i < GetPlayers(); i++ ){ local plr = FindPlayer( i ); if( plr ) plr.Health = 100; }
it will work, now player2 leaves so its like,

player1 ID: 0

player3 ID:2


and you do the same code, the getplayers will return 2, a loop of 2 will be called, and it does FindPlayer(0) it will work because that exists, when it does FindPlayer(1) since that ID doesn't exist it won't work, and the loop will end, leading the last player to not get healed. All he had to do was change GetPlayers to GetMaxPlayers.

MacTavish


Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P

Spice

Thankxs to all you guys it actually worked and i got the point....