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

Lua OnStatsChange overflows

Sytoxian

New Member
Joined
Aug 19, 2010
Messages
40
Reaction score
1
Hey, i made this script for an special monster. It's just extra damage onstatschange.
Code:
function onStatsChange(cid, attacker, type, combat, value)
if isPlayer(attacker) then
   if type == STATSCHANGE_HEALTHLOSS then
     if combat == COMBAT_PHYSICALDAMAGE then
       local value = value + 100
        doTargetCombatHealth(attacker, cid, combat, -value, -value, CONST_ME_DRAWBLOOD)
       return false
     end
   end
end
   return true
end
I get this Error:
Code:
[Error - CreatureEvent::executeStatsChange] Call stack overflow.

Another Question:
Do I have to register every single monster like the following one or is there an easier way?
Code:
<?xml version="1.0" encoding="UTF-8"?>
<monster name="trainer" nameDescription="a trainer" race="blood" experience="0" speed="0" manacost="600">
  <look typeex="5787" head="20" body="30" legs="40" feet="50" corpse="6080"/>
   <health now="9900000" max="9900000"/>
   <targetchange interval="60000" chance="0"/>
   <strategy attack="100" defense="0"/>
   <flags>
     <flag summonable="0"/>
     <flag attackable="1"/>
     <flag hostile="1"/>
     <flag illusionable="0"/>
     <flag convinceable="0"/>
     <flag pushable="0"/>
     <flag canpushitems="1"/>
     <flag staticattack="50"/>
     <flag lightlevel="0"/>
     <flag lightcolor="0"/>
     <flag targetdistance="1"/>
     <flag runonhealth="0"/>
   </flags>
   <script>
     <event name="extradamage"/>
   </script>
   <attacks>
     <attack name="melee" interval="5000" min="0" max="-1"/>
   </attacks>
   <defenses armor="0" defense="0">
     <defense name="healing" interval="1" chance="100" min="2400000" max="2400000"/>
   </defenses>
</monster>

Thanks.
 
Code:
<defense name="healing" interval="1" chance="100" min="2400000" max="2400000"/>
this causes the callstack overflow, you execute every milli second a heal on this monster.
change interval from 1 to 1000 (1 second) or 2000 (which is still more then enough)
 
Code:
<defense name="healing" interval="1" chance="100" min="2400000" max="2400000"/>
this causes the callstack overflow, you execute every milli second a heal on this monster.
change interval from 1 to 1000 (1 second) or 2000 (which is still more then enough)

Actually my guess is the "doTargetCombatHealth" in the creature event is itself triggering the creature event.
This results in an infinite loop and thus a stack overflow.

This seems like something the engine should account for.
Without looking at the source I'd say the best method would be for the creature event to allow the return value to be a number, which would be the new value to use.
If TFS doesn't have this logic, you'd have to differentiate between the stats that you change, and all others, possibly use a different combat type, like drowning or undefined.
Note that would be a workaround and you'd have to make sure you check against those combat types in the event (which you are currently doing)
 
Back
Top