Vice City: Multiplayer

Server Development => Scripting and Server Management => Topic started by: :P on Oct 05, 2015, 06:10 PM

Title: Stats not saving
Post by: :P on Oct 05, 2015, 06:10 PM
my stats not saving when i restart server my stats are go back to 0 why and not saving in db i checked db is 0 no fault in cmds i give you all things about stats getstats execstats login register ect.. no console error
function GetStats( p )
{
       try{
   local stats = null;
   if ( status[ p.ID ].IsReg == true )
   {
   local id = p.ID;
   local kills = status[ id ].Kills, deaths = status[ id ].Deaths;
   if ( ( kills > 0 ) && ( deaths > 0 ) )
   {
       local ratio = format( "%.2f", kills.tofloat() / deaths.tofloat() );
   stats = "Kills: " + kills + ", Deaths: " + deaths + ", Ratio: " + ratio + ".";
   }
   else
   {
       stats = "Kills: " + status[id].Kills + ", Deaths: " + status[id].Deaths + ".";
   }
   }
   else
   {
       stats = "This Nick-Name is not registered!";
   }
   return stats;
   }
   catch(e) print( "GetStats Error: " + e );
}


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

function Login( player, pass )
{
       local q = QuerySQL( db, "SELECT * FROM Account WHERE Name='" + player.Name + "'" );
   if ( GetSQLColumnData( q, 0 ) != null )
              {
   status[ player.ID ].Kills = GetSQLColumnData( q, 4 );
   status[ player.ID ].Deaths = GetSQLColumnData( q, 5 );
   status[ player.ID ].Cash = GetSQLColumnData( q, 6 );
   status[ player.ID ].Bank = GetSQLColumnData( q, 7 );
   }
   GetSQLNextRow( q );
               MessagePlayer( GREEN+">> You've Successfully Logged-In!", player );
       MessagePlayer(YELLOW+">> Name : [ " + player.Name + " ]"+GREEN+"  Level : [ " + GetLevel(player) + " ] State : [ " + GetLevelTag(player) + ""+GREEN+" ]",player);
       status[ player.ID ].IsLogged = true;
   QuerySQL(db, "UPDATE Account SET IP='" + player.IP + "' WHERE Name='" + player.Name + "'");
       Message(GREEN+"--> [ "+ player.Name + " ] Logged-In Successfully." );
       FreeSQLQuery( q );
}

function Register( player, pass )
{
     try{
local password = e(pass);
QuerySQL( db, "REPLACE INTO Account ( Name, IP, Level, Pass, Kills, Deaths, Cash, Bank ) VALUES ( '" + player.Name.tolower() + "', '" + player.IP + "', 1, '" + password + "', 0, 0, 0, 0 )" );
QuerySQL( db, "REPLACE INTO Bstats ( Name, User, Body, Torso, LeftArm, RightArm, LeftLeg, RightLeg, Head ) VALUES ( '" + player.Name.tolower() + "', '" + player.Name + "', 0, 0, 0, 0, 0, 0, 0 )" );
     QuerySQL( db, "REPLACE INTO Wstats ( Name, User, Fist, BrassKnuckle, ScrewDriver, GolfClub, NightStick, Knife, BaseballBat, Hammer, Cleaver, Machete, Katana, Chainsaw, Grenade, RemoteGrenade, TearGas, Molotov, Missile, Colt45, Python, Shotgun, Spaz , Stubby, Tec9, Uzi, Ingrams, MP5, M4, Ruger, SniperRifle, LaserScope, RocketLauncher, FlameThrower, M60 ) VALUES ( '" + player.Name.tolower() + "', '" + player.Name + "', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )" );
player.Cash = 2000;
status[ player.ID ].IsLogged = true;
status[ player.ID ].IsReg = true;
ePrivMessage( "You've Registered!", player );
ePrivMessage( "Nick:[ " + player.Name + " ] Password:[ " + pass + " ]", player );
EMessage( ">> " + player.Name + " is a Registered Nick-Name Now!" );
}
catch(e) print( "Reg Function Error: " + e );

}
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 + "'" );
   print( "Saved Stats of Player " + player.Name + "[" + player.ID + "]" );
   status[ id ] = null;
   }
   }
   catch(e) print( "Save Stats Error: " + e );
}

else if ( cmd == "stats" )
  {
     
try
{
if ( status[ player.ID ].IsReg == false ) ePrivMessage( "[Error] - You're not registered.", player );
else
{
    if ( !text ) EMessage( ">> " + player.Name + "'s Stats: " + GetStats( player ) );
else if ( text )
{
    local plr = GetPlayer( text );
if ( !plr ) ePrivMessage( "Invalid Player Nick/ID!", player );
else PrivMessage( plr.Name + "'s Stats: " + GetStats( plr ), player );
}

}
}
catch(e) print( "Stats Cmd Error: " + e );
  }
Title: Re: Stats not saving
Post by: SAzEe21 on Oct 05, 2015, 09:27 PM
Did you add ExecStats Timer in onScriptLoads.
If you didn't add, add this one..
NewTimer("ExecStats", 180000, 0 );

And, you didn't post AccInfo functions?
Title: Re: Stats not saving
Post by: Mashreq on Oct 06, 2015, 02:22 AM
I wonder why do you do like this?
In some places you are using .tolower() and in some places you are not using .tolower() form while checking in database as well as while you registers it is saved in .tolower () form.

If your account names are registered in database in the .tolower() form. Try replacing the following functions.

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

function Login( player, pass )
{
         local q = QuerySQL( db, "SELECT * FROM Account WHERE Name='" + player.Name.tolower() + "'" );
      if ( GetSQLColumnData( q, 0 ) != null )
              {
      status[ player.ID ].Kills = GetSQLColumnData( q, 4 );
      status[ player.ID ].Deaths = GetSQLColumnData( q, 5 );
      status[ player.ID ].Cash = GetSQLColumnData( q, 6 );
      status[ player.ID ].Bank = GetSQLColumnData( q, 7 );
      }
               MessagePlayer( GREEN+">> You've Successfully Logged-In!", player );
         MessagePlayer(YELLOW+">> Name : [ " + player.Name + " ]"+GREEN+"  Level : [ " + GetLevel(player) + " ] State : [ " + GetLevelTag(player) + ""+GREEN+" ]",player);
         status[ player.ID ].IsLogged = true;
      QuerySQL(db, "UPDATE Account SET IP='" + player.IP + "' WHERE Name='" + player.Name + "'");
          Message(GREEN+"--> [ "+ player.Name + " ] Logged-In Successfully." );
         FreeSQLQuery( q );
}

As well as please post your AccInfo function
Title: Re: Stats not saving
Post by: :P on Oct 06, 2015, 03:34 PM
now stats are saving but money and bank restarts after server money and bank reseted
Accinfo
function AccInfo( player )
{
      try{
  EchoMessage( ICOL_ORANGE + "** [" + player.ID + "] " + player.Name + " Joined the Server." );
  if ( CheckBan( player ) == 1 ) Kick( player, "Server", "Banned From Server" );
  status[ player.ID ] = PlayerStats();
  local id = player.ID;
  local ip = player.IP;
  if ( GetLevel( player ) > 0 )
  {
      if ( ip != GetIP( player ) )
  {
      ePrivMessage( "Welcome to the Server " + player.Name + "!", player );
  ePrivMessage( "You're not Logged-In. Please login by /login <password>", player );
  status[ player.ID ].IsReg = true;
  status[ player.ID ].IsLogged = false;
  }
  else if ( ip == GetIP( player ) )
  {
       local q = QuerySQL( db, "SELECT * FROM Account WHERE Name='" + player.Name.tolower() + "'" );
   if ( GetSQLColumnData( q, 0 ) != null )
              {
   status[ player.ID ].Kills = GetSQLColumnData( q, 4 );
   status[ player.ID ].Deaths = GetSQLColumnData( q, 5 );
   status[ player.ID ].Cash = GetSQLColumnData( q, 6 );
   status[ player.ID ].Bank = GetSQLColumnData( q, 7 );
   status[ player.ID ].Level = GetSQLColumnData( q, 2 );
   }
   GetSQLNextRow( q );
   ePrivMessage( "Welcome to the Server " + player.Name + "!", player );
   ePrivMessage( "You've auto-logged in onto the server!", player );
   status[ player.ID ].IsReg = true;
   status[ player.ID ].IsLogged = true;
   EchoMessage( ICOL_BROWN + ">> " + player.Name + " Auto-Logged In." );
   
  }
 
  }
  else
  {
      ePrivMessage( "Welcome to the Server " + player.Name + "!", player );
  ePrivMessage( "You're not registered with us. Register by /register <password>", player );   
  }
  WriteIniString( "Files/ServData.ini", "IP", player.Name, player.IP );
  }
  catch(e) print( "AccInfo Error: " + e );
}
Title: Re: Stats not saving
Post by: Mashreq on Oct 06, 2015, 04:14 PM
Can you show us your database structure of the table - Account?
Try removing your GetSQLNextRow( q ); in your AccInfo function.
Title: Re: Stats not saving
Post by: KAKAN on Oct 06, 2015, 06:33 PM
R u on a clan?
INIs will get corrupted if your name has big brackets( [ ] )
Title: Re: Stats not saving
Post by: :P on Oct 07, 2015, 07:19 AM
server.ini will corrupted if i remove getsqlrow
Title: Re: Stats not saving
Post by: :P on Oct 07, 2015, 10:22 AM
when i am not logged in and i spawn getting console error  Isreg does not exists
error line if ( status[ player.ID ].IsReg == false )and classed i added
function onPlayerSpawn( player )
{
    Message( ">> " + player.Name + " has spawned." );
if ( ( status[ player.ID ].IsReg == true ) && ( status[ player.ID ].IsLogged == false ) )
{
    Kick( player, "Server", "Failed To Login!" );
}
if ( status[ player.ID ].IsReg == false )
    {
    Announce( "/c register", player );
    ePrivMessage("Register First To Access Services",player);
    cKick(player);
}
if ( ( status[ player.ID ].IsReg ) && ( status[ player.ID ].IsLogged ) )
    {
    player.Cash = status[ player.ID ].Cash;
    }  
}
Title: Re: Stats not saving
Post by: :P on Oct 08, 2015, 07:19 AM
thanks mashreq my all stats works fine and for is reg error i change kick  to player.kick(): and works