server closed

Started by Cool, Oct 20, 2015, 03:36 PM

Previous topic - Next topic

Cool

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

KAKAN

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
oh no

Cool

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 );
    }
}
}

KAKAN

Post savestats function too.
So that I can know if your savestats contains LMS updates too.
oh no

Cool

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 );
}

MatheuS

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
if( !sucess ) tryAgain();
Thanks to the VCMP community. It was the happiest period of my life.

Cool


KAKAN

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.
oh no

Cool


Xmair

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.

Credits to Boystang!

VU Full Member | VCDC 6 Coordinator & Scripter | EG A/D Contributor | Developer of VCCNR | Developer of KTB | Ex-Scripter of EAD

Cool

so where i add this any one will tell me

Xmair

#11
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.
}

Credits to Boystang!

VU Full Member | VCDC 6 Coordinator & Scripter | EG A/D Contributor | Developer of VCCNR | Developer of KTB | Ex-Scripter of EAD

Spidey

gta vc and san are my favourite games

DizzasTeR

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.

Xmair

Ah shit, I didn't used onPlayerPart xD

Credits to Boystang!

VU Full Member | VCDC 6 Coordinator & Scripter | EG A/D Contributor | Developer of VCCNR | Developer of KTB | Ex-Scripter of EAD