Vice City: Multiplayer

Server Development => Scripting and Server Management => Topic started by: Eva on May 06, 2016, 08:24 AM

Title: stats
Post by: Eva on May 06, 2016, 08:24 AM
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)
Title: Re: stats
Post by: jayant on May 06, 2016, 08:52 AM
Check your array, stats or status ?
Check database if your kills,deaths are saving or not.. Check GetStats(..) function as per the error.
Title: Re: stats
Post by: KAKAN on May 06, 2016, 08:54 AM
remove the try-catch blocks and tell us the line of error.
Title: Re: stats
Post by: Saiyan Attack on May 06, 2016, 09:22 AM
You Must Change Your Local array sign ... like local stats = null; replaced with local statss = null;
Title: Re: stats
Post by: 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.
Title: Re: stats
Post by: ysc3839 on May 06, 2016, 09:57 AM
Don't use try catch. Because you can't see which line the error was in.
Title: Re: stats
Post by: Eva 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?
Title: Re: stats
Post by: Mötley on May 06, 2016, 01:37 PM
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 );
    }
Title: Re: stats
Post by: KAKAN on May 06, 2016, 03:37 PM
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
Title: Re: stats
Post by: Eva on May 06, 2016, 08:43 PM
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 );
    }
Title: Re: stats
Post by: dEaN on May 07, 2016, 01:48 PM
lol, why you use Warchief? :D use main.nut its better than Warchief
Title: Re: stats
Post by: Xmair on May 07, 2016, 03:17 PM
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?
Title: Re: stats
Post by: 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
Title: Re: stats
Post by: KAKAN on May 28, 2016, 03:40 AM
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?