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);
}
In GetStats you've got a extra brace { under
local stats = null;
i removed but same error :P
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.
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;
}
your and rulk function both have same error 0 does not exists
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
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;
}
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 );
}
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
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;
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;
}
no i have more functions so i closed in last
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.
Done but same error
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 );
same error
where did you create the array in OnScriptLoad ?
yes
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;
}
i can't think what else could be the problem chap, see if anyone else can
same error and printed on console yes
not working already i try
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
same line but error is kills does not exists
Thanks i solved it Thanks for reply if any came i will unlock topic :D
@KAKAN cash is inserting in db but not showing in hand whats reason
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()
}
Logged does not exists
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()
}
i used logged but why idk