Vice City: Multiplayer

Server Development => Scripting and Server Management => Topic started by: Cool on Nov 05, 2015, 04:06 PM

Title: does not exists
Post by: Cool on Nov 05, 2015, 04:06 PM
error 0 does not exists on getstats all my stats function
error line if ( ( kills > 0 ) && ( deaths > 0 ) )function SaveStats( player )
{
   local id = player.ID;
   {
       QuerySQL( db, "UPDATE Account SET Kills='" + stats[ id ].Kills + "', Deaths='" + stats[ player.ID ].Deaths + "', Cash='" + stats[ id ].Cash + "', Bank='" + stats[ id ].Bank + "', Joins='" + stats[ id ].Joins +  "' WHERE Name='" + player.Name.tolower() + "'" );
   print( "Saved Stats of Player " + player.Name + "[" + player.ID + "]" );
   stats[ id ] = null;
   }
   }
function GetStats( p )
{
   local stats = null;
   {
   local id = p.ID;
   local kills = stats[ id ].Kills, deaths = stats[ 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: " + stats[id].Kills + ", Deaths: " + stats[id].Deaths + ".";
   }
   }
   return stats;
   }
 
function ExecStats()
{
try{
for(local i = 0; i < GetMaxPlayers(); i++)
    {
        local player = FindPlayer( i ),q;
    if ( player )
    {
    local id = player.ID
   local  q = QuerySQL( db, "UPDATE Account SET Kills='" + stats[ player.ID ].Kills + "', Deaths='" + stats[ player.ID ].Deaths + "', Cash='" + stats[ player.ID ].Cash + "', Bank='" + stats[ player.ID ].Bank + "' WHERE Name='" + player.Name.tolower() + "'" );
 FreeSQLQuery( q );
print("Executed stats")
     }
}
}
catch(e) print("Executing stats error "+e);
}
Title: Re: does not exists
Post by: rulk on Nov 05, 2015, 04:25 PM
In GetStats you've got a extra brace { under
local stats = null;
Title: Re: does not exists
Post by: Cool on Nov 05, 2015, 04:28 PM
i removed but same error :P
Title: Re: does not exists
Post by: KAKAN on Nov 05, 2015, 04:31 PM
function GetStats( p )
{
    local stats = "";
    {
    local id = p.ID;
    local kills = stats[ id ].Kills, deaths = stats[ id ].Deaths, ratio = format( "%.2f", kills.tofloat() / deaths.tofloat() );
if( p )
{
    if ( kills > 0 ) stats = "Kills: " + kills + ", Deaths: " + deaths + ", Ratio: " + ratio + ".";
    else  stats = "Kills: " + stats[id].Kills + ", Deaths: " + stats[id].Deaths + ".";
    }
}
    return stats;
    }
Try this one tho and tell the results.
Title: Re: does not exists
Post by: rulk on Nov 05, 2015, 04:33 PM
This is @KAKAN's version, he forgot to remove the extra brace, i spotted two :-)
function GetStats( p )
{
    local stats = "";
    local id = p.ID;
    local kills = stats[ id ].Kills, deaths = stats[ id ].Deaths, ratio = format( "%.2f", kills.tofloat() / deaths.tofloat() );
    if ( kills > 0 ) stats = "Kills: " + kills + ", Deaths: " + deaths + ", Ratio: " + ratio + ".";
    else  stats = "Kills: " + stats[id].Kills + ", Deaths: " + stats[id].Deaths + ".";
    return stats;
}
Title: Re: does not exists
Post by: Cool on Nov 05, 2015, 04:35 PM
your and rulk function both have same error 0 does not exists
Title: Re: does not exists
Post by: KAKAN on Nov 05, 2015, 04:35 PM
Oh, yea, maybe that's the problem.
@King aka Noob, Try rulk's one.
And if it doesn't works, post the command for which you're using GetStats
Title: Re: does not exists
Post by: KAKAN on Nov 05, 2015, 04:37 PM
Quote from: King on Nov 05, 2015, 04:35 PMyour and rulk function both have same error 0 does not exists
Okay, then lets goto debugging mode.
Try adding this before the kills > 0 thing.
print( kills )
EDIT:-
Wait, I found the bug.
Use this one and try:-
function GetStats( p )
{
    local stats = "";
    local id = p.ID;
    local kills = stats[ id ].Kills, deaths = stats[ id ].Deaths, ratio = format( "%.2f", kills.tofloat() / deaths.tofloat() );
    if( !stats[ id ].Logged ) stats = "Kills: 0, Deaths: 0, Ratio: 0.";
else{
    if ( kills > 0 ) stats = "Kills: " + kills + ", Deaths: " + deaths + ", Ratio: " + ratio + ".";
    else  stats = "Kills: " + stats[id].Kills + ", Deaths: " + stats[id].Deaths + ".";
}
    return stats;
}
Title: Re: does not exists
Post by: Cool on Nov 05, 2015, 04:37 PM
else if ( cmd == "stats" )
  {
  try{
    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: does not exists
Post by: rulk on Nov 05, 2015, 04:38 PM
change
local stats = "";

To
local stats = 0;

because your declaring stats as a string when it should be a integer.

edit, stats should be a string (doh), the error 0 dose not exists sound like kills and deaths are not set as integers
Title: Re: does not exists
Post by: Cool on Nov 05, 2015, 04:42 PM
is there any mistake possible in class
///  Player Class
class PlayerStats
{
LastUsedIP = "0.0.0.0";
Cash = 0;
Bank = 0;
Kills = 0;
Deaths = 0;
Level = 0;
Logged = false;
Title: Re: does not exists
Post by: rulk on Nov 05, 2015, 04:44 PM
apart from missing a brace at the bottom, no.

///  Player Class
class PlayerStats
{
    LastUsedIP = "0.0.0.0";
    Cash = 0;
     Bank = 0;
     Kills = 0;
     Deaths = 0;
     Level = 0;
    Logged = false;
}
Title: Re: does not exists
Post by: Cool on Nov 05, 2015, 04:46 PM
no i have more functions so i closed in last
Title: Re: does not exists
Post by: DizzasTeR on Nov 05, 2015, 04:49 PM
The class vars seem to be of Fuzzie's account system, so tell me I never remember that Fuzzie used 'stats' for declaring array, he used 'pstats'

Change all your stats to pstats.
Title: Re: does not exists
Post by: Cool on Nov 05, 2015, 04:57 PM
Done but same error
Title: Re: does not exists
Post by: rulk on Nov 05, 2015, 05:02 PM
you haven't created the stats array then, its trying to find index zero of the array, which does'nt exists
stats <- array( 100, null );
Title: Re: does not exists
Post by: Cool on Nov 05, 2015, 05:12 PM
same error
Title: Re: does not exists
Post by: rulk on Nov 05, 2015, 05:13 PM
where did you create the array in OnScriptLoad ?
Title: Re: does not exists
Post by: Cool on Nov 05, 2015, 05:15 PM
yes
Title: Re: does not exists
Post by: rulk on Nov 05, 2015, 05:16 PM
if i recreate the error by using
function onScriptLoad( )
{
     stats <- array( 100, null );

     stats[ 0 ] = pstats( 10, 10 );

     if ( stats[ 0 ].kills > 0 ) print("yes");
}



class pstats
{
     constructor( ... )
     {
          kills = vargv[0];
          deaths = vargv[1];
     }

     kills = null;
     deaths = null;
}
Title: Re: does not exists
Post by: rulk on Nov 05, 2015, 05:19 PM
i can't think what else could be the problem chap, see if anyone else can
Title: Re: does not exists
Post by: Cool on Nov 05, 2015, 05:21 PM
same error and printed on console yes
Title: Re: does not exists
Post by: Cool on Nov 05, 2015, 05:40 PM
not working already i try
Title: Re: does not exists
Post by: KAKAN on Nov 05, 2015, 05:40 PM
Okay mate.
Now lets goto debugging mode.
Add this before the error line and tell the results.
print( kills );Tell us what's the output
Title: Re: does not exists
Post by: Cool on Nov 05, 2015, 05:44 PM
same line but error is kills does not exists
Title: Re: does not exists
Post by: Cool on Nov 05, 2015, 06:03 PM
Thanks i solved it Thanks for reply if any came i will unlock topic :D
Title: Re: does not exists
Post by: Cool on Nov 05, 2015, 06:30 PM
@KAKAN  cash is inserting in db but not showing in hand whats reason
Title: Re: does not exists
Post by: KAKAN on Nov 05, 2015, 06:39 PM
Use player.Cash for inserting to the player's cash which is shown in the player's screen, else use this function if u FAS
function IncCash( player, amount ){
player.Cash += amount.tointeger()
if( stats[ player.ID ].Logged ) stats[ player.ID ].Cash += amount.tointeger()
}
For decrasing cash use this:-
function DecCash( player, amount ){
player.Cash -= amount.tointeger()
if( stats[ player.ID ].Logged ) stats[ player.ID ].Cash -= amount.tointeger()
}
Title: Re: does not exists
Post by: Cool on Nov 05, 2015, 06:43 PM
Logged does not exists
Title: Re: does not exists
Post by: KAKAN on Nov 05, 2015, 07:03 PM
What do you use then?
Have a look on your script.
else use this:-
function IncCash( player, amount ){
player.Cash += amount.tointeger()
stats[ player.ID ].Cash += amount.tointeger()
}
//And this:-
function DecCash( player, amount ){
player.Cash -= amount.tointeger()
stats[ player.ID ].Cash -= amount.tointeger()
}
Title: Re: does not exists
Post by: Cool on Nov 05, 2015, 07:06 PM
i used logged but why idk