Vice City: Multiplayer

Server Development => Scripting and Server Management => Topic started by: KAKAN on Aug 21, 2015, 09:46 AM

Title: playerson
Post by: KAKAN on Aug 21, 2015, 09:46 AM
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?
Title: Re: playerson
Post by: KAKAN on Aug 21, 2015, 09:51 AM
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.")
}
}
}
Title: Re: playerson
Post by: Ksna on Aug 21, 2015, 12:47 PM
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.");

Title: Re: playerson
Post by: KAKAN on Aug 21, 2015, 01:11 PM
without that ; it works, I have many things without ; and those all things work properly
Title: Re: playerson
Post by: KAKAN on Aug 21, 2015, 01:15 PM
just marked now, I already have that ; mark, and still then it gives out error
Title: Re: playerson
Post by: Ksna on Aug 21, 2015, 01:25 PM
Not seen this line

if ( stats[player.ID].Logged )
{
stats[ player.ID ].Update( player, sqliteDB );
print ("Stats Updated.");
}
Title: Re: playerson
Post by: soulshaker on Aug 21, 2015, 08:09 PM
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);
  }
}
Title: Re: playerson
Post by: KAKAN on Aug 22, 2015, 01:20 AM
Thanks, It worked. And now can u tell me what;s the error onscriptunload? and the way to overcome it too.
Title: Re: playerson
Post by: DizzasTeR on Aug 22, 2015, 04:33 AM
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.