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?
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.")
}
}
}
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.");
without that ; it works, I have many things without ; and those all things work properly
just marked now, I already have that ; mark, and still then it gives out error
Not seen this line
if ( stats[player.ID].Logged )
{
stats[ player.ID ].Update( player, sqliteDB );
print ("Stats Updated.");
}
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);
}
}
Thanks, It worked. And now can u tell me what;s the error onscriptunload? and the way to overcome it too.
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.