Look, here is the code of OnScriptUnload:
function onScriptUnload()
{
for( local i=0; i <= GetMaxPlayers()-1; i++ )
{
local plr = FindPlayer(i);
if(plr) onPlayerPart(plr, 255);
}
DisconnectSQL( MainDatabase );
DisconnectSQL( PropsDB );
DisconnectSQL( acmds );
DisconnectSQL( IPdb );
DisconnectSQL( VehDB );
}
code of OnPlayerPart:
function onPlayerPart( player, reason )
{
SaveStats(player);
}
// OnPlayerPart is working..
code of SaveStats
function SaveStats( player )
{
local id = player.ID;
if ( status[ id ].IsReg == true )
{
QuerySQL( MainDatabase, "UPDATE Account SET Kills='" + player.Score + "', Deaths='" + status[ id ].Deaths + "', Cash='" + player.Cash + "' WHERE Name='" + player.Name.tolower() + "'" );
}
}
When I close the server by myself, player stats can't save. why?
Try This
function SaveStats( player )
{
try{
local id = player.ID;
if ( status[ id ].IsReg == true )
{
QuerySQL( db, "UPDATE Account SET Kills='" + status[ id ].Kills + "', Deaths='" + status[ player.ID ].Deaths + "', Cash='" + status[ id ].Cash + "', Bank='" + status[ id ].Bank + "', Joins='" + status[id].Joins + "' WHERE Name='" + player.Name + "'" );
print( "" + player.Name + " Stats Saved [" + player.ID + "]" );
status[ id ] = null;
}
}
catch(e) print( "Save Stats Error: " + e );
}
You should first question yourself if you need that many databases. You can create multiple tables inside one file, you know?
Have you tried adding debug text to know if your callback is actually called?
Quote from: Thijn on Mar 02, 2015, 07:10 PMYou should first question yourself if you need that many databases. You can create multiple tables inside one file, you know?
Have you tried adding debug text to know if your callback is actually called?
Quote from: ali_vcmp on Mar 02, 2015, 04:16 PMTry This
function SaveStats( player )
{
try{
local id = player.ID;
if ( status[ id ].IsReg == true )
{
QuerySQL( db, "UPDATE Account SET Kills='" + status[ id ].Kills + "', Deaths='" + status[ player.ID ].Deaths + "', Cash='" + status[ id ].Cash + "', Bank='" + status[ id ].Bank + "', Joins='" + status[id].Joins + "' WHERE Name='" + player.Name + "'" );
print( "" + player.Name + " Stats Saved [" + player.ID + "]" );
status[ id ] = null;
}
}
catch(e) print( "Save Stats Error: " + e );
}
This still not working...
I think the reason is that when I close my server, function onScriptUnload not call.
I put a message onscriptunload:
function onScriptUnload()
{
for( local i=0; i <= GetMaxPlayers()-1; i++ )
{
local plr = FindPlayer(i);
if(plr) onPlayerPart(plr, 255);
}
DisconnectSQL( MainDatabase );
DisconnectSQL( PropsDB );
DisconnectSQL( acmds );
DisconnectSQL( IPdb );
DisconnectSQL( VehDB );
print("Script Unloaded..");
}
but I can't see any message on the console when I close the server..
I figured that was happening, well done finding out.
@Stormeus The server needs proper exit codes and needs to gracefully wait till all events are done processing :x
Quote from: BigcaT_ on Mar 03, 2015, 07:29 AMI tried to use onServerStop() , but still not working when I close the server.
Yeah, there's a problem. Unfortunately, there's some issues when the server shuts down. And depending on the loaded modules you might not receive an event through that function. We've discussed (http://forum.vc-mp.org/?topic=247.0) this and stormeus promised to look into this for the next release.
Quote from: S.L.C on Mar 03, 2015, 08:03 AMQuote from: BigcaT_ on Mar 03, 2015, 07:29 AMI tried to use onServerStop() , but still not working when I close the server.
Yeah, there's a problem. Unfortunately, there some issues when the server shuts down. And depending on the loaded modules you might not receive an event through that function. We've discussed (http://forum.vc-mp.org/?topic=247.0) this and stormeus promised to look into this for the next release.
ok. Thanks for telling.
Quote from: Thijn on Mar 03, 2015, 06:42 AM@Stormeus The server needs proper exit codes and needs to gracefully wait till all events are done processing :x
I'm refiling this as a bug because the server is actually supposed to wait for events to finish.
Quote from: stormeus on Mar 03, 2015, 07:04 PMQuote from: Thijn on Mar 03, 2015, 06:42 AM@Stormeus The server needs proper exit codes and needs to gracefully wait till all events are done processing :x
I'm refiling this as a bug because the server is actually supposed to wait for events to finish.
Stormeus how can I use this now?
Quote from: BigcaT_ on Apr 19, 2015, 03:52 AMQuote from: stormeus on Mar 03, 2015, 07:04 PMQuote from: Thijn on Mar 03, 2015, 06:42 AM@Stormeus The server needs proper exit codes and needs to gracefully wait till all events are done processing :x
I'm refiling this as a bug because the server is actually supposed to wait for events to finish.
Stormeus how can I use this now?
Is this still an issue? The last server update should've given plugins a chance to shut down gracefully on both Linux and Windows.
Quote from: stormeus on Apr 19, 2015, 05:53 AMQuote from: BigcaT_ on Apr 19, 2015, 03:52 AMQuote from: stormeus on Mar 03, 2015, 07:04 PMQuote from: Thijn on Mar 03, 2015, 06:42 AM@Stormeus The server needs proper exit codes and needs to gracefully wait till all events are done processing :x
I'm refiling this as a bug because the server is actually supposed to wait for events to finish.
Stormeus how can I use this now?
Is this still an issue? The last server update should've given plugins a chance to shut down gracefully on both Linux and Windows.
stormeus a hacker always DDOS my server, and server can not call ShutDownServer(), it causes the player in server 's stats could not save, I hope to fix onScriptUnload, please!
The server won't save anything if it crashes.
Quote from: BigcaT_ on May 23, 2015, 01:56 PMQuote from: stormeus on Apr 19, 2015, 05:53 AMQuote from: BigcaT_ on Apr 19, 2015, 03:52 AMQuote from: stormeus on Mar 03, 2015, 07:04 PMQuote from: Thijn on Mar 03, 2015, 06:42 AM@Stormeus The server needs proper exit codes and needs to gracefully wait till all events are done processing :x
I'm refiling this as a bug because the server is actually supposed to wait for events to finish.
Stormeus how can I use this now?
Is this still an issue? The last server update should've given plugins a chance to shut down gracefully on both Linux and Windows.
stormeus a hacker always DDOS my server, and server can not call ShutDownServer(), it causes the player in server 's stats could not save, I hope to fix onScriptUnload, please!
It isn't a bug. You should save players' stats when players take some action(such as when a player kill other player, increases its "kill stats" and then save it immediately). This may solve most problem.
Locked.
I am Bigcat,
I deleted the last account.
and created a new account.
And there's one more thing, did the client update yesterday ?
Quote from: Sentral on May 24, 2015, 04:29 AMAnd there's one more thing, did the client update yesterday ?
Nope.
OK.