Vice City: Multiplayer

Server Development => Scripting and Server Management => Topic started by: Finch on Mar 15, 2015, 04:00 AM

Title: Levelup Command
Post by: Finch on Mar 15, 2015, 04:00 AM
Hi i have create a levelup command its not working its always say p does not exist or id does not exist

else if ( cmd == "levelup" )
{
        local id = p.ID;
   local kills = status[ id ].Kills;
        if (kills < 500) rPrivMessage( "[Error] You need to have 500 kills to get level up", player );
else
{
      if (kills > 500) rPrivMessage( "[Error] Your level is up Congratz", player );
      QuerySQL(db,"UPDATE Account SET Level='" 2  "' WHERE Name='" + player.Name.tolower() + "'");
}
}



Fucntion of Stats

function GetStats( p )
{
       try{
   local stats = null;
   if ( status[ p.ID ].IsReg == true )
   {
   local id = p.ID;
   local kills = status[ 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: " + status[id].Kills + ", Deaths: " + status[id].Deaths + ".";
   }
   }
   else
   {
       stats = "This Nick-Name is not registered!";
   }
   return stats;
   }
   catch(e) print( "GetStats Error: " + e );
}
Title: Re: Levelup Command
Post by: MacTavish on Mar 15, 2015, 04:13 AM
Change p.ID to player.ID in both codes
Title: Re: Levelup Command
Post by: Finch on Mar 15, 2015, 05:31 AM
thnx for that but new problem level not setted
QuerySQL(db,"UPDATE Account SET Level='" 2  "' WHERE Name='" + player.Name.tolower() + "'");
Title: Re: Levelup Command
Post by: MacTavish on Mar 15, 2015, 05:44 AM
Change Level='" 2  "'  to  Level='2'
Title: Re: Levelup Command
Post by: Finch on Mar 15, 2015, 05:51 AM
thnx again but again help expresion expected here
 
else if ( cmd == "levelup" )
{
        local id = player.ID;
   local kills = status[ id ].Kills;
        if (kills < 500) rPrivMessage( "[Error] You need to have 500 kills to get level up", player );
else
{
      if (kills > 1000) rPrivMessage( "[Error] Your level is up Congratz", player );
       QuerySQL(db,"UPDATE Account SET  Level='2' WHERE Name='" + player.Name.tolower() + "'");
else
{
      if (kills > 5000) rPrivMessage( "[Error] Your level is up Congratz", player );
       QuerySQL(db,"UPDATE Account SET  Level='3' WHERE Name='" + player.Name.tolower() + "'");
else
{
      if (kills > 10000) rPrivMessage( "[Error] Your level is up Congratz", player );
       QuerySQL(db,"UPDATE Account SET  Level='4' WHERE Name='" + player.Name.tolower() + "'");
}
}
}
Title: Re: Levelup Command
Post by: Kratos_ on Mar 15, 2015, 05:53 AM
Quote from: Finch on Mar 15, 2015, 05:31 AMthnx for that but new problem level not setted

It will throw the error too on the console that " Wrong Number of Parameters " . And , changing Level = '2' is the solution as Beztone stated above . At least learn to post the screenshot of the error . Use switch case & check the kills at the boundary for example just at 500 kills .
If the condition is satisfied then do the auto updation to the player level . If you're writing kills > 500 , then player will hit the command from 501-1000 kills for the 2nd level & SQL query will execute in the server for no reason as player has already achieved that level .
Title: Re: Levelup Command
Post by: Finch on Mar 15, 2015, 06:03 AM
(https://forum.vc-mp.org/proxy.php?request=http%3A%2F%2Fi61.tinypic.com%2F1tanfm.png&hash=e8de1fbc71c5e08e479e541afad81a0359379d1d)



(https://forum.vc-mp.org/proxy.php?request=http%3A%2F%2Fi62.tinypic.com%2F2mfrr6.png&hash=c53f07befe4a619a05395c327c52c516933451ba)
Title: Re: Levelup Command
Post by: Kratos_ on Mar 15, 2015, 06:16 AM

You're writing wrong condition . There is no condition made for kills between 500 & 1000 . Also , you're nesting the if else ladder which isn't required here . I updated my upper post . Have a look at it .
Title: Re: Levelup Command
Post by: MacTavish on Mar 15, 2015, 07:01 AM
function glevel( kills )
{
switch ( kills )
{
case 500: return "2";
case 1000: return "3";
case 5000: return "4";
case 10000; return "5";
}
}

command
else if ( cmd == "levelup" )
{
        local id = player.ID;
    local kills = status[ id ].Kills;
        if (kills > 500 )
{
rPrivMessage( "[Congo] Your level is up Congratz", player );
       QuerySQL(db,"UPDATE Account SET  Level='"+glevel( kills )+"' WHERE Name='" + player.Name.tolower() + "'");
}
else rPrivMessage( "[Error] Not Enough Kills Need Atleast 500 kills", player );
}


Donno my switch works or not but give a try :)
Title: Re: Levelup Command
Post by: Kratos_ on Mar 15, 2015, 08:14 AM
I noticed that he is asking for LevelUp Command than Auto-Updation to Level . Using boundaries is good for the auto-update but bad for the command . Since , the player must have exactly 500 kills to achieve the level through cmd & if he kills someone accidently & gets 501 kills then he couldn't get the level upgrade through command . Anyway , I tried to do something below :-

Function :-

function deserve_level( player )
{
local id = player.ID, kills = status[id].Kills, deserve_lvl;
if (kills < 500 ) deserve_lvl = 1;
else if( kills >= 500 && kill <= 999 ) deserve_lvl = 2;
else if( kills >= 1000 && kills <= 4999 ) deserve_lvl = 3;
else if( kills >= 5000 && kills <= 9999 ) deserve_lvl = 4;
else if( kills >= 10000 && kills <= 14999 ) deserve_lvl = 5;
else if( kills >= 15000 ) deserve_lvl = 6;
return deserve_lvl;
}

Command:-

else if ( cmd == "levelup" )
{
        local current_lvl = status[player.ID].Level, deserve_lvl = deserve_level( player );
        if( current_lvl == deserve_lvl ) MessagePlayer(" [Error] : Sorry, your level has already been upgraded as per your kills ", player );
        else if( current_lvl < deserve_lvl )
        {
        status[player.ID].Level = deserve_lvl;
        QuerySQL(db,"UPDATE Account SET  Level='" + deserve_lvl + "' WHERE Name='" + player.Name.tolower() + "'");
        MessagePlayer(" Congrats , your level has been upgraded to : " + deserve_lvl + "", player );
        }
}
Title: Re: Levelup Command
Post by: BigcaT_ on Mar 15, 2015, 10:36 AM
else if( cmd == "levelup" )
{
if(status[player.ID].IsReg && status[player.ID].IsLogged && GetLevel(player) < 9)
{
local level = GetLevel(player), kill = player.Score;
if( kill >= level * 500 )
{
local l = level + 1;
QuerySQL(MainDatabase, "UPDATE Account SET Level='" + l + "' WHERE Name='" + player.Name.tolower() + "'");
RMTA( player.Name + "'s level up! new level - " + l );
}
else
{
local a = ( level * 500 ) - kill;
EM("You don't have enough kill, there are still "+a+" kills short.",player);
          }
}
else EM("You don't need to level up!",player);
    }
You don't need to use 'case', just use numbers * numbers.
That's the levelup command of my server.
Title: Re: Levelup Command
Post by: Finch on Mar 15, 2015, 10:38 AM
Well Bigcat what is EM or RMTA ??
Thnx Beztone and Kratos
Problem Solved