Levelup Command

Started by Finch, Mar 15, 2015, 04:00 AM

Previous topic - Next topic

Finch

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 );
}
Beztone is a scripter but he is too stupid

MacTavish


Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P

Finch

thnx for that but new problem level not setted
QuerySQL(db,"UPDATE Account SET Level='" 2  "' WHERE Name='" + player.Name.tolower() + "'");
Beztone is a scripter but he is too stupid

MacTavish

Change Level='" 2  "'  to  Level='2'

Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P

Finch

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() + "'");
}
}
}
Beztone is a scripter but he is too stupid

Kratos_

#5
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 .
In the middle of chaos , lies opportunity.

Finch

Beztone is a scripter but he is too stupid

Kratos_


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 .
In the middle of chaos , lies opportunity.

MacTavish

#8
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 :)

Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P

Kratos_

#9
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 );
        }
}
In the middle of chaos , lies opportunity.

BigcaT_

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.

Finch

Well Bigcat what is EM or RMTA ??
Thnx Beztone and Kratos
Problem Solved
Beztone is a scripter but he is too stupid