• 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!

[C++] addStorageValue(key, value)

Powers

New Member
Joined
May 10, 2010
Messages
19
Reaction score
0
hello, I want the player after receiving the experience to save time in storage (addStorageValue(key, value))

Code:
uint32_t key = 41757;
std::string value;
value = time/1000;

attackerPlayer->addStorageValue(key, value.c_str());

not save digits, only letters (ex: S) ..

what I did wrong?:(
 
I want to know somthing, this isnt the method to apply a storage, second when do you want it to set the time, when killing a monster and getting exp?
 
Code:
uint32_t key = 41757;
std::string value;
std::ostringstream ss;
int temp;
temp = time/1000;
ss << temp;
value = ss.str();
attackerPlayer->addStorageValue(key, value.c_str());
 
converting may i say okay, but language of ot not okay :p

Okay here is what you need to do

0.3.6
PHP:
#include <sstream> //should be placed at the top of file you editing, unless it was defined in another header included in file

//Setting time to storage

    std::stringstream textt;   
    uint32_t keyy = 11234;   // key stored at

     textt << OTSYS_TIME()/1000 ;   // puting the time in seconds in the stream
     this->setStorage(keyy,textt.str()); // set storage to a unsigned long int "keyy"

0.4
PHP:
#include <sstream> //should be placed at the top of file you editing, unless it was defined in another header included in file

//Setting time to storage

        std::stringstream textt;   
        const std::string keyy = "exp_time";   // key stored , should be a string, so getPlayerstorageValue(cid,"exp_time")

	textt << OTSYS_TIME()/1000 ;   // puting the time in seconds in the stream
	this->setStorage("exp_time",textt.str());  // set storage a constant string "exp_time"

Why i use (this) not (player),because i added this to the Player.cpp file on the addExperience thing, so if you executed the doPlayerAddExperince command this will occur.
 
Last edited:
hello, I found another way with using boost:

std::string value;
int32_t valueTimes = time/1000;

try {
value = boost::lexical_cast<std::string>(valueTimes);
} catch( boost::bad_lexical_cast const& ) {
value = "0";
// std::cout << "Error: input string was not valid" << std::endl;
}

who is more efficient?

// thanks for your help, the examples also work!
 
Back
Top