Vice City: Multiplayer

Server Development => Scripting and Server Management => Topic started by: Cool on May 26, 2016, 10:10 AM

Title: scriptunload
Post by: Cool on May 26, 2016, 10:10 AM
when scripts unloading error occuring
functions function onScriptUnload(){
local I, player, mp = GetMaxPlayers();
for(I = 0; I < mp; ++I ){ // place it in first line
player = FindPlayer( I )
if (pAway.rawin(oldname[player.ID]))
{
player.Name = ""+oldname[player.ID]+"";
pAway.rawdelete( player.Name );
oldname[player.ID] = null;
}
}
if( sqliteDB ){
DisconnectSQL( sqliteDB );
sqliteDB = null;
}
    DisconnectSQL( secondarydb );
print( "Fuzzie's Account System v3 - SQLite variant has successfully unloaded..." );
}
(https://forum.vc-mp.org/proxy.php?request=http%3A%2F%2Fi68.tinypic.com%2F29b2e5i.png&hash=278c7157b8b064661030ab59dc48d6caa49ffcce)
Title: Re: scriptunload
Post by: DizzasTeR on May 26, 2016, 10:34 AM
player = FindPlayer( I )
Are you checking if the player is even valid and exists? what if there is no player connected at ID 0, 1, 2, 3... because you're I is looping and if there is no player at that I id then player will be null and player.ID will not exist.

so check if the player exists by
if( player ) {
/* your code here */
}

/* other code here */
Title: Re: scriptunload
Post by: . on May 26, 2016, 10:45 AM
Quote from: Doom_Kill3R on May 26, 2016, 10:34 AMAre you checking if the player is even valid and exists?...

Oh man, that was a good laugh. Did you forgot where you are or what? ;D
Title: Re: scriptunload
Post by: KAKAN on May 26, 2016, 12:02 PM
Quote from: . on May 26, 2016, 10:45 AM
Quote from: Doom_Kill3R on May 26, 2016, 10:34 AMAre you checking if the player is even valid and exists?...

Oh man, that was a good laugh. Did you forgot where you are or what? ;D
^^^^^^^^^^^^^

This one should work:-
function onScriptUnload(){
local I, player, mp = GetMaxPlayers();
for(I = 0; I < mp; ++I ){ // place it in first line
player = FindPlayer( I );
if( !player ) continue;
else if (pAway.rawin(oldname[player.ID]))
{
player.Name = ""+oldname[player.ID]+"";
pAway.rawdelete( player.Name );
oldname[player.ID] = null;
}
}
if( sqliteDB ){
 DisconnectSQL( sqliteDB );
 sqliteDB = null;
 }
     DisconnectSQL( secondarydb );
 print( "Fuzzie's Account System v3 - SQLite variant has successfully unloaded..." );
}