• 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++ [0.4] Checking storage and using it while damage

GarQet

Own3d!
Joined
Feb 10, 2009
Messages
1,381
Solutions
14
Reaction score
81
Hello everyone!

Im looking for small help. Im not that good in C++ as in LUA and I have a huge problem.
I wanted to create small additional thing in C++ but this thing randomly crashes server. Randomly means like few minutes after start server, few hours or days... I don't even know what error of crash says...
I will be appreciate for any help.

first error: https://i.gyazo.com/cd9b40512ac1f89c0758cd231fd2357b.png
second error: https://i.gyazo.com/78cefc6fbf1caa1200461c531eb8267c.png

Script:
COMBAT.CPP
Code:
bool Combat::CombatHealthFunc(Creature* caster, Creature* target, const CombatParams& params, void* data)
{
   int64_t change = 0;
   if(Combat2Var* var = (Combat2Var*)data)
   {
       change = var->change;
       if(!change)
           change = random_range(var->minChange, var->maxChange, DISTRO_NORMAL);
   }

   Player* targetPlayer = target->getPlayer();
   if(targetPlayer) {
       std::string value;
       caster->getStorage(666, value);
       int32_t plus = atoi(value.c_str());      
       int32_t multiplier = g_config.getNumber(ConfigManager::ADDITIONAL_DAMAGE);
       if(params.isSpell && caster && random_range(1, 1000, DISTRO_NORMAL) <= (S_CRITICAL + (plus * multiplier))) {
           change = (int64_t)(change * (1.2 + ((plus * multiplier) * 0.01)));
       }
   }
      
   if(g_game.combatBlockHit(params.combatType, caster, target, change, params.blockedByShield, params.blockedByArmor))
       return false;

   if(change < 0 && caster && caster->getPlayer() && target->getPlayer())
       change = change / 2;

   if(!g_game.combatChangeHealth(params.combatType, caster, target, change, params.effects.hit, params.effects.color))
       return false;

   CombatConditionFunc(caster, target, params, NULL);
   CombatDispelFunc(caster, target, params, NULL);
   return true;
}

Can any help me somehow? Please :)
 
What exactly is caster->getStorage(666, value); supposed to do? I wouldn't recomend using storage, as you could just probably use a custom condition id, but they way you're using it now, I guess that line would just return a boolean value and then do nothing more. Don't you get any compiling errors?
 
What exactly is caster->getStorage(666, value); supposed to do? I wouldn't recomend using storage, as you could just probably use a custom condition id, but they way you're using it now, I guess that line would just return a boolean value and then do nothing more. Don't you get any compiling errors?
Its an additional extras for people who made quests on server. So if someone will do it he gaining one point of storage. I don't have any other idea how to implement this. By using LUA and statschange it also crashing server cause of stack overflow.
While compiling im not receving any errors. Also I just bitly edited the script to check if caster is Player but it continue to random crash server :/
Do u have any idea how to implement this?
 
Back
Top