• 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 How to make trap damage blocked by armor?

X X X

Newb
Joined
Jul 26, 2015
Messages
148
Reaction score
13
Tried this on various distros, TFS1.2 as well as Nostalrius/Sabrehaven, same behavior: The trap always does 30 damage to monsters no matter what, it seems that "blockarmor" is not applied. Not sure how it can be applied,

Pretty straightforward, here is my code for "damage.lua" in movements:
Lua:
function onStepIn(creature, item, position, fromPosition)
    local tile = Tile(position)
    if tile:hasFlag(TILESTATE_PROTECTIONZONE) then
        return
    end
   
    if item:getId() == 2145 then
        item:transform(2146, 1)
        item:decay()
        doTargetCombatHealth(0, creature, COMBAT_PHYSICALDAMAGE, -60, -60)
    elseif item:getId() == 2146 or item:getId() == 2148 then
        doTargetCombatHealth(0, creature, COMBAT_PHYSICALDAMAGE, -60, -60)
    elseif item:getId() == 3482 then
        if not creature:isPlayer() then
            doTargetCombatHealth(0, creature, COMBAT_PHYSICALDAMAGE, -30, -30) --this one is for the open trap
        else
            position:sendMagicEffect(CONST_ME_POFF)
        end
        item:transform(3481, 1)
        item:decay()
    elseif item:getId() == 3944 then
        doTargetCombatHealth(0, creature, COMBAT_POISONDAMAGE, -30, -30)
        item:transform(3945, 1)
        item:decay()
    end
end

For spells I know you can do "combat:setParameter(COMBAT_PARAM_BLOCKARMOR, 1)" but I don't thank that works in this case.
 
Solution
I haven't tested what @highsanta suggested, it should work, but it would be really messy to add all of that stuff about declaring local combats. If you want to retain your current script structure without having a whole bunch of different local combats declared, you can make a small source edit.

The problem is, the function doTargetCombatHealth() isn't set to pass any parameters related to blocking armor. You can see this in luascript.cpp. So, we need to edit this function in luascript.cpp. Find "int LuaScriptInterface::luaDoTargetCombatHealth(lua_State* L)", then underneath:
C++:
CombatParams params;
params.combatType = combatType;
params.impactEffect = getNumber<uint8_t>(L, 6);
Add:
C++:
params.blockedByArmor = getBoolean(L, 8...
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
combat:setParameter(COMBAT_PARAM_BLOCKARMOR, true)
combat:setParameter(COMBAT_PARAM_USECHARGES, true)

function onGetFormulaValues(player, skill, attack, factor)
    local min = 30
    local max = 30
    return -min, -max
end

combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

function onStepIn(creature, item, position, fromPosition)

return combat:execute(creature, variant)
    
end
 
I haven't tested what @highsanta suggested, it should work, but it would be really messy to add all of that stuff about declaring local combats. If you want to retain your current script structure without having a whole bunch of different local combats declared, you can make a small source edit.

The problem is, the function doTargetCombatHealth() isn't set to pass any parameters related to blocking armor. You can see this in luascript.cpp. So, we need to edit this function in luascript.cpp. Find "int LuaScriptInterface::luaDoTargetCombatHealth(lua_State* L)", then underneath:
C++:
CombatParams params;
params.combatType = combatType;
params.impactEffect = getNumber<uint8_t>(L, 6);
Add:
C++:
params.blockedByArmor = getBoolean(L, 8, false);
Recompile.
Now, in your lua script, add "true" as the 8th parameter to pass to the C++ function:

Lua:
if not creature:isPlayer() then
            doTargetCombatHealth(0, creature, COMBAT_PHYSICALDAMAGE, -30, -30, 0, 0, true) --must add the two zeroes so 'true' is passed as the 8th parameter
        else
            position:sendMagicEffect(CONST_ME_POFF)
        end
That's it. This can be applied now anywhere you have doTargetCombatHealth.
 
Solution
Heyy that worked perfectly, thank you! Now just need to add 0, 0, true to any other doTargetCombatHealth and it will be blocked by armor, nice!
 
Back
Top