Hello i was trying this stats snippet but it doesnt work right.
This i have in functions:
function GetStats( p )
{
try{
local stats = null;
if ( stats[ p.ID ].IsReg == true )
{
local id = p.ID;
local kills = stats[ 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: " + stats[id].Kills + ", Deaths: " + stats[id].Deaths + ".";
}
}
else
{
stats = "This Nick-Name is not registered!";
}
return stats;
}
catch(e) print( "GetStats Error: " + e );
}
This on playercommand
else if ( cmd == "stats" )
{
try
{
if ( stats[ player.ID ].Logged == 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 );
}
This are the error in console and in game:
(https://forum.vc-mp.org/proxy.php?request=http%3A%2F%2F217.120.23.210%2Fimages%2F1.png&hash=dd2d272dbf66a5ecbbf6f3b90b8299f4bee7c58d)
(https://forum.vc-mp.org/proxy.php?request=http%3A%2F%2F217.120.23.210%2Fimages%2F2.png&hash=e07b1b6c0f97631b3e923e662c63b68d27a56290)
Check your array, stats or status ?
Check database if your kills,deaths are saving or not.. Check GetStats(..) function as per the error.
remove the try-catch blocks and tell us the line of error.
You Must Change Your Local array sign ... like local stats = null; replaced with local statss = null;
Quote from: Saiyan Attack on May 06, 2016, 09:22 AMYou Must Change Your Local array sign ... like local stats = null; replaced with local statss = null;
Aah, yeah, you're right.
@Ron , here is the function for yo:
http://pastebin.com/NLStCk2V
Usage: player.Stats();
Well, it would be even better if you include it in your account system's class.
Don't use try catch. Because you can't see which line the error was in.
Quote from: KAKAN on May 06, 2016, 09:49 AMQuote from: Saiyan Attack on May 06, 2016, 09:22 AMYou Must Change Your Local array sign ... like local stats = null; replaced with local statss = null;
Aah, yeah, you're right.
@Ron , here is the function for yo:
http://pastebin.com/NLStCk2V
Usage: player.Stats();
Well, it would be even better if you include it in your account system's class.
How do i modifie the onplayercommand part if i use this function?
It should not mater registered or not, If you are using a class just use this.
:P I use this to make sure classes are working
else if ( cmd == "stats" )
{
if ( text )
{
local plr = FindPlayer( text );
if ( !plr ) MessagePlayer( "Player " + text + " is not online." );
else
{
local Stats = Account[ plr.ID ];
MessagePlayer( plr.Name + "'s stats:", player );
MessagePlayer( "Kills: " + Stats.Kills + ", Deaths: " + Stats.Deaths, player );
MessagePlayer( "Cash: " + Stats.Cash, player );
}
}
else MessagePlayer( "Usage: /stats <player>", player );
}
Quote from: Ron on May 06, 2016, 11:40 AMQuote from: KAKAN on May 06, 2016, 09:49 AMQuote from: Saiyan Attack on May 06, 2016, 09:22 AMYou Must Change Your Local array sign ... like local stats = null; replaced with local statss = null;
Aah, yeah, you're right.
@Ron , here is the function for yo:
http://pastebin.com/NLStCk2V
Usage: player.Stats();
Well, it would be even better if you include it in your account system's class.
How do i modifie the onplayercommand part if i use this function?
Updated that example, see it again, here's the link:
http://pastebin.com/NLStCk2V
Quote from: Mötley on May 06, 2016, 01:37 PMIt should not mater registered or not, If you are using a class just use this.
:P I use this to make sure classes are working
else if ( cmd == "stats" )
{
if ( text )
{
local plr = FindPlayer( text );
if ( !plr ) MessagePlayer( "Player " + text + " is not online." );
else
{
local Stats = Account[ plr.ID ];
MessagePlayer( plr.Name + "'s stats:", player );
MessagePlayer( "Kills: " + Stats.Kills + ", Deaths: " + Stats.Deaths, player );
MessagePlayer( "Cash: " + Stats.Cash, player );
}
}
else MessagePlayer( "Usage: /stats <player>", player );
}
This didnt work 100% but after a little tweak it does now thnx :)
This is the working one:
else if ( cmd == "stats" )
{
if ( text )
{
local plr = FindPlayer( text );
if ( !plr ) MessagePlayer( "[#FCF805]Player " + text + " is not online." );
else
{
local Stats = stats[ player.ID ];
MessagePlayer( plr.Name + "'s [#FCF805]stats:", player );
MessagePlayer( "[#FCF805]Kills: " + Stats.Kills + ", Deaths: " + Stats.Deaths, player );
MessagePlayer( "[#FCF805]Cash: " + Stats.Cash, player );
}
}
else MessagePlayer( "[#FCF805]Usage: /stats <player>", player );
}
lol, why you use Warchief? :D use main.nut its better than Warchief
Quote from: dEaN on May 07, 2016, 01:48 PMlol, why you use Warchief? :D use main.nut its better than Warchief
What in the actual fuck?
Quote from: dEaN on May 07, 2016, 01:48 PMlol, why you use Warchief? :D use main.nut its better than Warchief
Warchief? loOol