onPlayerPart prob

Started by Eva, May 08, 2016, 07:38 PM

Previous topic - Next topic

Eva

I have this error in console when a player leaves the server, and i cant figure out why.
Here is the console error:

here is line 239:


And here is my OnplayerPart:
function onPlayerPart( player, reason,  )
  {
    if( stats[ player.ID ].Level != 0 )
   {
     if ( stats[ player.ID ].Team )
     {
   local plr = GetPlayer( stats[ player.ID ].Teamp );
   EMessage( ">>" + player.Name + " left the Team." );
   stats[ plr.ID ].Teamp = null;
   stats[ player.ID ] = null;
}
stats[ player.ID ].Update( player, sqliteDB );
                   print( ">> " + player.Name + "'s data saved." );
                   // Remember to save regularly
                   SunshineAutos.SaveDatabase("scripts/sunshine.db");
                   print( ">> " + player.Name + "'s carsdata saved." );
                   

    if ( stats[ player.ID ].LMS )
    {
        EMessage( ">> " + player.Name + " is out of the LMS round." );
        LMSCount--;
        if ( LMSCount == 1 ) CheckEnd2();
    }
  }
  stats[ player.ID ] = null;
  playerson.remove( player.ID );
  EchoMessage( "** [" + player.ID + "] " + player.Name + " has left the server." );
}

Also i cant get stats to save to the db same for rulks sunshine, exept acc does get saved. Im using ADM script as the base.



Thijn

Post your onPlayerJoin

Eva

Quote from: Thijn on May 08, 2016, 08:16 PMPost your onPlayerJoin

Here it is Thijn
function onPlayerJoin( player )
{
     if ( CheckBan( player ) == 1 ) NewTimer( "Kick", 3000, 1, player.ID );
     playerson.push( player.ID );
  stats[ player.ID ] = PlayerClass( player.Name, sqliteDB );
stats[ player.ID ].Join( player );
EchoMessage( "** [" + player.ID + "] " + player.Name + " has joined the server." );
MessagePlayer( "[#FFFF00]Your LMS Stats: Played: " + stats[ player.ID ].Played + " Won: " + stats[ player.ID ].Wins + " Lost: " + stats[ player.ID ].Lost + " .", player);
C.ShowForPlayer( player );
  AddAlias( player );
                     local country = geoip_country_name_by_addr(player.IP);
                     if (country != null) // the plugin returned a meaningful result
                     Message("[#FFFF00]* " + player.Name + " [#00ff00]Has connected from " + country + ". [" + geoip_country_code_by_addr(player.IP) + "]");
                     }
function Update( player, dbGlobal )
       {
      ::QuerySQL( dbGlobal, "UPDATE Accounts SET Cash=" + Cash + ", Bank=" + Bank + ", Kills=" + Kills + ", Deaths=" + Deaths + ", Level=" + Level + ", LastUsedIP='" + LastUsedIP + "' WHERE Name='" + player.Name + "' AND NameLower='" + player.Name.tolower() + "'" );
       }

KAKAN

@Ron, remove that line and add this:
local idx = playerson.find( player.ID );
if( idx != null ) playerson.remove( idx );
oh no

Eva

Quote from: KAKAN on May 09, 2016, 05:31 AM@Ron, remove that line and add this:
local idx = playerson.find( player.ID );
if( idx != null ) playerson.remove( idx );
Thanks KAKAN the error in console is solved. :)
Still stats and cars dont get saved into databases

KAKAN

Quote from: Ron on May 09, 2016, 07:35 AMThanks KAKAN the error in console is solved. :)
Still stats and cars dont get saved into databases

I can't do anything if you don't show me the required code.
oh no

Eva

#6
What do you need? here is on player part
stats[ player.ID ].Update( player, sqliteDB );
                   print( ">> " + player.Name + "'s data saved." );
                   // Remember to save regularly
                   SunshineAutos.SaveDatabase("scripts/sunshine.db");
                   print( ">> " + player.Name + "'s carsdata saved." );
                   
 
    if ( stats[ player.ID ].LMS )
    {
        EMessage( ">> " + player.Name + " is out of the LMS round." );
        LMSCount--;
        if ( LMSCount == 1 ) CheckEnd2();
    }
  }
  stats[ player.ID ] = null;
  playerson.remove( player.ID );
  EchoMessage( "** [" + player.ID + "] " + player.Name + " has left the server." );
}

and here savestats:
function SaveStats( player )
{
       try{
   local id = player.ID;
   if ( status[ id ].IsReg == true )
   {
       QuerySQL( sqliteDB, "UPDATE Account SET Kills='" + status[ id ].Kills + "', Killed='" + status[ id ].Killed + "', Deaths='" + status[ player.ID ].Deaths + "', Cash='" + status[ id ].Cash + "', Bank='" + status[ id ].Bank + "', Joins='" + status[id].Joins + "' WHERE Name='" + player.Name + "'" );
   print( "Saved Stats of Player " + player.Name + "[" + player.ID + "]" );
   status[ id ] = null;
   }
   }
   catch(e) print( "Save Stats Error: " + e );
}

DizzasTeR

Quote from: Ron on May 09, 2016, 02:05 PMstats[ player.ID ].Update( player, sqliteDB ); if ( status[ id ].IsReg == true )

Makes so damn sense.

Eva

Quote from: Doom_Kill3R on May 09, 2016, 02:25 PM
Quote from: Ron on May 09, 2016, 02:05 PMstats[ player.ID ].Update( player, sqliteDB ); if ( status[ id ].IsReg == true )
Well sorry im kinda new to this. and try to learn
but if i get you right, it should be if ( stats[ player.id ].IsReg == true )
Makes so damn sense.

KAKAN

use this:
stats[ player.ID ].Update( player, sqliteDB );
                   print( ">> " + player.Name + "'s data saved." );
                   // Remember to save regularly
                   SunshineAutos.SaveDatabase("scripts/sunshine.db");
                   print( ">> " + player.Name + "'s carsdata saved." );
                   
    if ( stats[ player.ID ].LMS )
    {
        EMessage( ">> " + player.Name + " is out of the LMS round." );
        LMSCount--;
        if ( LMSCount == 1 ) CheckEnd2();
    }
  }
  stats[ player.ID ] = null;
  local idx = playerson.find( player.ID );
   if( idx != null ) playerson.remove( idx );
  EchoMessage( "** [" + player.ID + "] " + player.Name + " has left the server." );
}
oh no

Mötley

when using
if ( status[ id ].IsReg == true )
It's good practice to use in this method

if (( status[ id ].IsReg) == true )

Thijn

Quote from: Mötley on May 09, 2016, 05:08 PMwhen using
if ( status[ id ].IsReg == true )
It's good practice to use in this method

if (( status[ id ].IsReg) == true )
Why would it?

Mötley

#12
Really!?
That's the worst check I have ever seen.
You should always use this method as checking what you want from it.

You should get the class veritable then add the second check as follows. anything else with checking true or false
if ( status[ id ].IsReg == true )or what ever could create errors as well as I have seen this happen for myself, the class gets basically a call for


status[ id ].IsReg  then the class needs to check true or false. Why would you do this way when its not as hard on the classes this way when it can get the class id then get/check the actual value in that class


if (( status[ id ].IsReg) == true )
*There is more in detail I could go into but I am busy..

Thijn

Ah I just noticed the == true. That part is retarded.
if ( status.IsReg )
Works just fine.
Unless your code is totally fucked and IsReg doesn't actually return true/false...

Mötley

#14
I find It's best to run the class then get the value. instead of just checking the class in general..

example

local
      Level = Account.[player.id].Level,
      Stats = Account[player.id].Stats;

Then you could run checks off of the value its already getting on its own.
if (cmd == "kick") {
      if (Level < 1) {
        MessagePlayer("Invalid cmd type /cmds", player);
        return true;
      }



This will return the value in the class

if (( status[ id ].IsReg) == true )

Gets the class value without working the class improperly as you have already gotten the value, now what did the value return ? etc. instead on making a call on the class for does the value already == true

I prefer to not go into stronger detail as I will begin to get confusing ,,.