• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

I need some help with a C++ code

Delirium

OTLand veteran
Staff member
Global Moderator
Joined
May 28, 2007
Messages
3,365
Solutions
1
Reaction score
289
Location
Athens, Greece
Hello.I've tried to make a code that changes the speed of a gamemaster character:
Code:
bool Commands::setGamemasterSpeed(Creature* creature, const std::string& cmd, const std::string& param)
{
     Player* player = creature->getPlayer();
     if(player)
     {
           int speed = 0;
           int conditionTime = 9999999 * 999999 * 9999999 * 999999;
           bool updateSpeed = false;
           std::string speedName;
           
           if(param == "slowest")
           {
               speed = 50;
               updateSpeed = true;
               speedName = "slowest";
           }
           else if(param == "slow")
           {
               speed = 150;
               updateSpeed = true;
               speedName = "slow";
           }
           else if(param == "normal")
           {
               speed = 222;
               speedName = "normal";
               updateSpeed = true;
           }
           else if(param == "fast")
           {
               speed = 378;
               speedName = "fast";
               updateSpeed = true;
           }
           else if(param == "fastest")
           {
               speed = 1164;
               speedName = "fastest";
               updateSpeed = true;
           }
           else if(param == "")
           {
               speed = 378;
               speedName = "fast";
               updateSpeed = true;
           }
               
     if(updateSpeed)
     {
           g_game.changeSpeed(player,speed);    
           Condition* condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_HASTE, conditionTime, 0);
           player->addCondition(condition);
           char buffer[50];
           sprintf(buffer,"Your speed has been changed to %s.",speedName.c_str());
           player->sendTextMessage(MSG_INFO_DESCR,buffer);
     }
     else{
          player->sendCancel("Could not change character speed.");
     }
     return false;
   }
}

The problem with this code is,that with every parameter I specify,it changes the gamemaster's speed to a value which is always the same,no matter what the param was.Could someone tell me why this happens? I am c++ newb :p
 
Code:
          int conditionTime = 9999999 * 999999 * 9999999 * 999999;

noob?

Also always returning false??
 
Code:
          int conditionTime = 9999999 * 999999 * 9999999 * 999999;

noob?

Also always returning false??

Just tell me what is wrong with this declaration instead of calling me a noob

int? plz...
Also, why as condition? plz2.


Because this is how the real Gamemaster system works.When a gamemaster is online,he always has the haste condition.
 
Then make an onThink condition keeper, instead of such formula. It won't work anyway, because return value won't be an int, more like long or even long long. Also, condition length can be max int, so if you make it long = (...), you won't compile :p

Change return false; to return true;, and add return false; above last }.
Code:
else
          player->sendCancel("Could not change character speed.");
     return true;
   }
     return false;
}

Use tabs instead of spaces, because space = 1 byte, tab = 1 byte, and you have to make 4-5 spaces to simulate a tab.

Remove the bool updateSpeed; and use if(speed) instead of if(updateSpeed). If you won't type corrent param, speed will be 0 = false.
 
Last edited:
you can also remove speed name use the param and if you want no param be igual 'fast', use the ? operator.
 
Back
Top