stats

Started by Eva, May 06, 2016, 08:24 AM

Previous topic - Next topic

Eva

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:


jayant

Check your array, stats or status ?
Check database if your kills,deaths are saving or not.. Check GetStats(..) function as per the error.

KAKAN

remove the try-catch blocks and tell us the line of error.
oh no

Saiyan Attack

You Must Change Your Local array sign ... like local stats = null; replaced with local statss = null;

KAKAN

#4
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.
oh no

ysc3839

Don't use try catch. Because you can't see which line the error was in.

Eva

Quote from: KAKAN on May 06, 2016, 09:49 AM
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.

How do i modifie the onplayercommand part if i use this function?

Mötley

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

KAKAN

Quote from: Ron on May 06, 2016, 11:40 AM
Quote from: KAKAN on May 06, 2016, 09:49 AM
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.

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
oh no

Eva

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

dEaN

lol, why you use Warchief? :D use main.nut its better than Warchief
I think first impressions are important when i pick up a Main.nut script and I'm sticking to the script, I'm putting that organic feeling back in the game.
-Since 2012-

Xmair

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?

Credits to Boystang!

VU Full Member | VCDC 6 Coordinator & Scripter | EG A/D Contributor | Developer of VCCNR | Developer of KTB | Ex-Scripter of EAD

Eva

Quote from: dEaN on May 07, 2016, 01:48 PMlol, why you use Warchief? :D use main.nut its better than Warchief
Warchief? loOol

KAKAN

Quote from: Eva on May 27, 2016, 09:12 PM
Quote from: dEaN on May 07, 2016, 01:48 PMlol, why you use Warchief? :D use main.nut its better than Warchief
Warchief? loOol
Quote from: Xmair on May 07, 2016, 03:17 PMWhat in the actual fuck?
why bump?
oh no