playerson

Started by KAKAN, Aug 21, 2015, 09:46 AM

Previous topic - Next topic

KAKAN

There is a global variable in my server named playerson, which throws out a error sometimes
Can anyone tell me the use of it?
playerson <- [];
It's used in the following events
function onPlayerJoin( player )
{
playerson.push( player.ID )
}

function onPlayerPart( player, reason )
{
  playerson.remove( player.ID ); //It always throws out an error here, idk what caused the problem
//And the problem is "idx out of range"
}

And yes it is used in some commands too like
Votekick, players, admins

And in some functions too like:-
LMS, Votekick
Can anybody solve my error?
oh no

KAKAN

And yes, I was trying to update the stats onscriptunload, this one also doesn't work help me plz :(
Here is the code for it:-
function onScriptUnload()
{
local player;
for ( local i = 0; i < GetMaxPlayers(); i++ ) 
{
player = FindPlayer( i );
if ( player && stats[player.ID].Logged )
{
stats[ player.ID ].Update( player, sqliteDB );
print ("Stats Updated.")
}
}
}
oh no

Ksna

#2
function onPlayerJoin( player )
{
playerson.push( player.ID );
}

As there is no semicolon  at player.push in your code, this statement is never executed and as there is no player.ID in that array it shows a error in playerson.remove .

print ("Stats Updated.");


KAKAN

without that ; it works, I have many things without ; and those all things work properly
oh no

KAKAN

just marked now, I already have that ; mark, and still then it gives out error
oh no

Ksna

Not seen this line

if ( stats[player.ID].Logged )
{
stats[ player.ID ].Update( player, sqliteDB );
print ("Stats Updated.");
}

soulshaker

Try
function onPlayerJoin( player )
{
playerson.push(player.Name);
}

function onPlayerPart( player, reason )
{
if(playerson.find(player.Name)!=null )
  {
    local idx = playerson.find(player.Name);
    playerson.remove(idx);
  }
}

KAKAN

Thanks, It worked. And now can u tell me what;s the error onscriptunload? and the way to overcome it too.
oh no

DizzasTeR

Just wondering, you are storing all the online players in an array called playerson, then why are you running a for loop at onScriptUnload ? Why not use foreach loop to get only the available players? Great.