Vice City: Multiplayer

Server Development => Scripting and Server Management => Topic started by: Cool on Oct 20, 2015, 03:36 PM

Title: server closed
Post by: Cool on Oct 20, 2015, 03:36 PM
Is there any way to save stats when players in server and close server to save players stats when ever i am in server i close server my stats not saved if i exit so then its save my stats
Title: Re: server closed
Post by: KAKAN on Oct 20, 2015, 03:39 PM
Tell us what u use to save stats in OnPlayerPart(...)
This is an example snip:-
function onScriptUnLoad() {
local i, maxplayers = GetMaxPlayers()
for(i = 0; i < maxplayers; i++){
//....
}
}
That script won't work, you need to edit it
Title: Re: server closed
Post by: Cool on Oct 20, 2015, 03:46 PM
save stats i added onplayerpart but not workfunction onPlayerPart( player,  reason )
{
       local Text = "Unknown";
   switch ( reason )
  {
case PARTREASON_DISCONNECTED:
Text = "Quit";
break;
case PARTREASON_TIMEOUT:
Text = "Timeout / Crash";
break;
  }
  if ( stats[ player.ID ].Team == true )
 {
  local plr = FindPlayer( stats[ player.ID ].Partner );
  if ( plr ) {
   ePrivMessage( plr, "[!] " + player.Name + " left the team." );
   stats[ plr.ID ].Partner = null;
   stats[ plr.ID ].Team = false;
  }
 }
local w = stats[ player.ID ].Lost;
QuerySQL( db, format( "UPDATE LMS SET Lost=%i WHERE Name='" + player.Name.tolower() + "'", w ) );
local b = stats[ player.ID ].Played;
QuerySQL( db, format( "UPDATE LMS SET Played=%i WHERE Name='" + player.Name.tolower() + "'", b ) );
local f = stats[ player.ID ].Wins;
QuerySQL( db, format( "UPDATE LMS SET Won=%i WHERE Name='" + player.Name.tolower() + "'", f ) ); 
print( ">> " + player.Name + "'s data saved." );

if ( GetPlayers()-1 == 0 )
                {
                        meter.Paused = true;
                        timer_status = false;
                        print( "Timer Paused" );
                }

     if ( stats[ player.ID ].LMS )
        {
          Message( ">> " + player.Name + " is out of the LMS round." );
          LMSCount--;
          if ( LMSCount == 1 ) CheckEnd2();
        }
  EchoMessage( ICOL_RED + "[" + player.ID + "] " + player.Name + " left the Server. (" + Text + ")" );
  SaveStats( player );
stats[ player.ID ] = null;
}
i thinking you talking about this on your example snippet your example thats same function ExecStats()
{
        local id, q;
    for(local i = 0; i < GetMaxPlayers(); i++)
    {
        local plr = FindPlayer( i ),q;
    if ( plr )
    {
id = plr.ID
    q = QuerySQL( db, "UPDATE Account SET Kills='" + status[ id ].Kills + "', Deaths='" + status[ id ].Deaths + "', Cash='" + status[ id ].Cash + "', Bank='" + status[ id ].Bank + "' WHERE Name='" + plr.Name.tolower() + "'" );
FreeSQLQuery( q );
    }
}
}
Title: Re: server closed
Post by: KAKAN on Oct 20, 2015, 04:00 PM
Post savestats function too.
So that I can know if your savestats contains LMS updates too.
Title: Re: server closed
Post by: Cool on Oct 20, 2015, 04:10 PM
no save stats does not contain lms stats 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 + "' WHERE Name='" + player.Name.tolower() + "'" );
   print( "Saved Stats of Player " + player.Name + "[" + player.ID + "]" );
   status[ id ] = null;
   }
   }
   catch(e) print( "Save Stats Error: " + e );
}
Title: Re: server closed
Post by: MatheuS on Oct 20, 2015, 05:42 PM
Quote from: Noob on Oct 20, 2015, 04:10 PMno save stats does not contain lms stats 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 + "' WHERE Name='" + player.Name.tolower() + "'" );
   print( "Saved Stats of Player " + player.Name + "[" + player.ID + "]" );
   status[ id ] = null;
   }
   }
   catch(e) print( "Save Stats Error: " + e );
}

try removing the .tolower from player.Name
Title: Re: server closed
Post by: Cool on Oct 20, 2015, 05:52 PM
same prob
Title: Re: server closed
Post by: KAKAN on Oct 20, 2015, 06:17 PM
Man, don't remove .tolower().
Just add this in your script:-
function onScriptUnload(){
local I, p,  mp = GetMaxPlayers();
for(I=0; I< mp; I++){
p = FindPlayer(I);
if( p ) SaveStats( player );
}
}
Untested, but it should work.
Title: Re: server closed
Post by: Cool on Oct 20, 2015, 06:25 PM
not works :-\
Title: Re: server closed
Post by: Xmair on Oct 21, 2015, 05:15 AM
Dafuq are you doing at onScriptUnload @KAKAN , onScriptUnload/onServerStop cannot be used for making loops for "players or other shit".
As I tried almost every thing on the official events.
Title: Re: server closed
Post by: Cool on Oct 21, 2015, 07:03 AM
so where i add this any one will tell me
Title: Re: server closed
Post by: Xmair on Oct 21, 2015, 07:22 AM
Try.
function onScriptLoad()
{
//You can post your other things here.
NewTimer("ExecStats",30000,0)//We will make a timer for the function "ExecStats" on every 30 seconds with an infinite timer.
}
function ExecStats()
{
try{//This will try if this code works.
local plr; q//We will make a null array to store the players and query.
for(local i = 0; i < GetMaxPlayers(); i++) //A basic loop for all players.
{
plr = FindPlayer( i ),q;//We will find the players. and keep "q" still null. This will fill up the "plr" array.
     if ( plr )//If there are players.
     {
     q = QuerySQL( db, "UPDATE Account SET Kills='" + status[ player.ID ].Kills + "', Deaths='" + status[ player.ID ].Deaths + "', Cash='" + status[ player.ID ].Cash + "', Bank='" + status[ player.ID ].Bank + "' WHERE Name='" + plr.Name.tolower() + "'" );//Finally we will save the stats. This will fill up the "q" array.
 FreeSQLQuery( q ); //We will free the query or it will produce lag.
print("Executed stats") //We print that we have the stats saved.
     }
}
}
catch(e) print("Executing stats error "+e);//If the code isn't working, It'll throw out a "[SCRIPT] Executing stats error ....."
}
Happy scripting :)
Note: You may ask your players to leave or kick them all with a simple command.
function onPlayerCommand(player,cmd,text)
{
try{
cmd=cmd.tolower()//This is not a must but it is good to add it. Ex : A player types : /KicKAlL, It won't work so if we add it, It'll work.
if ( cmd == "kickall" )//We will check if the command given by the player matches our command.
{
if ( IsNoob(player,cmd) ) return 0;//You can post your level function here but I think you use warchiefs so I'll put IsNoob here.
else if ( GetPlayers() <= 1 ) MessagePlayer("[#00ff00]Command[#ffffff]: Not enough players",player);//If there is only 1 player.
else//If nothing is wrong, Than continue.
{
Message("[#00ff00]Admin command: [#ffffff]Admin "+player.Name+" has kicked everyone from the game.")//We will give a message.
local plr;//We will make a null array.
for(local i = 0; i < GetMaxPlayers(); i++)//A basic loop again.
{
plr = FindPlayer(i)//We will find players.
if ( plr ) plr.Kick(); // If players are online, We'll kick them.
}
}
}
else MessagePlayer("[#00ff00]Command: [#ffffff]The command doesn't exists",player);//We'll check if there is no command like that and we will give an error to the player.
}
catch(e) print("Onplayercommand error "+e)//It will throw out an error if the commands don't work.
}
Title: Re: server closed
Post by: Spidey on Oct 21, 2015, 10:19 AM
does it works
Title: Re: server closed
Post by: DizzasTeR on Oct 21, 2015, 10:53 AM
function onScriptUnload()
{
local Max_Players = GetMaxPlayers();
for( local i = 0; i < Max_Players; ++i )
    {
local player = FindPlayer( i );
        if( player) onPlayerPart( player, 1 );
    }
}

Just use this code, also this will only work if you close your server yourself! If your server crashes, there is no way to save your stats then.

Quote from: Xmair on Oct 21, 2015, 05:15 AM...onScriptUnload/onServerStop cannot be used for making loops for "players or other shit".
As I tried almost every thing on the official events.

You're wrong @Xmair.
Title: Re: server closed
Post by: Xmair on Oct 21, 2015, 10:58 AM
Ah shit, I didn't used onPlayerPart xD
Title: Re: server closed
Post by: Cool on Oct 21, 2015, 11:33 AM
so on the topic end my problem not solved  so topic locked thanks for your reply