• 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++] - getStorage, setStorage

Oskar1121

Excellent OT User
Joined
Jul 15, 2009
Messages
706
Reaction score
713
Location
Poland
Hello,
I have a big problem. I have found in creature.cpp two functions:
PHP:
bool Creature::getStorage(const uint32_t key, std::string& value) const
{
    StorageMap::const_iterator it = storageMap.find(key);
    if(it != storageMap.end())
    {
        value = it->second;
        return true;
    }

    value = "-1";
    return false;
}

bool Creature::setStorage(const uint32_t key, const std::string& value)
{
    storageMap[key] = value;
    return true;
}
But when I use this function in this way:
PHP:
target->getAttackedCreature()->getStorage(key, value)
Then the program finds errors
PHP:
 C:\Users\Oskar\Desktop\0.3.6pl1.r83\creature.cpp In member function `virtual void Creature::onAttackedCreatureKilled(Creature*)': 
1211 C:\Users\Oskar\Desktop\0.3.6pl1.r83\creature.cpp invalid use of member (did you forget the `&' ?) 
1211 C:\Users\Oskar\Desktop\0.3.6pl1.r83\creature.cpp base operand of `->' is not a pointer
My question is: how to use this function in creature.cpp?
 
not sure what are you doing, but this has compiled fine
[cpp]//
if(getMaster() && getMaster()->getAttackedCreature()) { //This happens if the monster is summoned during combat
std::string val;
if(getMaster()->getAttackedCreature()->getStorage(100, val))
selectTarget(getMaster()->getAttackedCreature());
}[/cpp]
 
I have:
PHP:
void Creature::onAttackedCreatureKilled(Creature* target)
{
	if(target == this)
		return;

	double gainExp = target->getGainedExperience(this);
	onGainExperience(gainExp, target, false);
	char result[100];
	std::string val;
    sprintf(result, "%f", gainExp);
	target->getAttackedCreature()->setStorage(1000, result);
	std::cout << target->getAttackedCreature()->getStorage(1000, val) << std::endl;
}
But in console still shows number 1. Why? But when i check in LUA storage value then show good value.
 
[cpp]void Creature::onAttackedCreatureKilled(Creature* target)
{
if(target == this)
return;

double gainExp = target->getGainedExperience(this);
onGainExperience(gainExp, target, false);
std::stringstream s;
s << gainExp;
target->getAttackedCreature()->setStorage(1000, s.str());
std::string val;
target->getAttackedCreature()->getStorage(1000, val);
std::cout << val << std::endl;
}[/cpp]
 
Back
Top