• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua Trouble with doTargetCombatHealth function. [SOLVED]

Siegh

Thronar Developer
Joined
Mar 12, 2011
Messages
1,276
Solutions
1
Reaction score
635
Location
Brazil
Hello :)

I'm using this script as a trap that takes players inside a specific area, teleports them to a designated location, and causes them some damage.

The teleport part works fine, but I'm not being able to "target" the damaging function to the affected player even though I'm using the same selection criteria as the teleporting function. What am I doing wrong?

Thanks in advance!

LUA:
        function fall()
            local square = {
            frompos = {x = 1180, y = 924, z = 12},
            topos = {x = 1180, y = 924, z = 12},
            exitpos = {x = 1179, y = 918, z = 14}
            }          
            for a = square.frompos.x, square.topos.x do
                for b = square.frompos.y, square.topos.y do
                    dmg = 400
                    doTargetCombatHealth(0, getTopCreature(pos).uid, COMBAT_FIREDAMAGE, -dmg*0.75, -dmg, 7)                    
                    pos = {x = a, y = b, z = 12, stackpos = 255}
                    doTeleportThing(getTopCreature(pos).uid,square.exitpos)
                end
            end
        end
        fall()

1772296741706.webp
 
Theres some errors in the code.
1) dmg and pos are declared as globals (use "local")
2) pos is used before being declared (you do doTargetCombathealth before pos is defined)
3) I think getTopCreature is a tile function but i guess it depends on the engine version(?)

Anyways, try this:

LUA:
function fall()
    local square = {
        frompos = {x = 1180, y = 924, z = 12},
        topos = {x = 1180, y = 924, z = 12},
        exitpos = {x = 1179, y = 918, z = 14}
    }         
    for a = square.frompos.x, square.topos.x do
        for b = square.frompos.y, square.topos.y do
            local pos = {x = a, y = b, z = 12, stackpos = 255}
            local creature = getTopCreature(pos)
            if creature and creature.uid > 0 then
                local dmg = 400
                doTargetCombatHealth(0, creature.uid, COMBAT_FIREDAMAGE, -dmg * 0.75, -dmg, 7)                   
                doTeleportThing(creature.uid, square.exitpos)
            end
        end
    end
end
fall()
 
Theres some errors in the code.
1) dmg and pos are declared as globals (use "local")
2) pos is used before being declared (you do doTargetCombathealth before pos is defined)
3) I think getTopCreature is a tile function but i guess it depends on the engine version(?)

Anyways, try this:

LUA:
function fall()
    local square = {
        frompos = {x = 1180, y = 924, z = 12},
        topos = {x = 1180, y = 924, z = 12},
        exitpos = {x = 1179, y = 918, z = 14}
    }        
    for a = square.frompos.x, square.topos.x do
        for b = square.frompos.y, square.topos.y do
            local pos = {x = a, y = b, z = 12, stackpos = 255}
            local creature = getTopCreature(pos)
            if creature and creature.uid > 0 then
                local dmg = 400
                doTargetCombatHealth(0, creature.uid, COMBAT_FIREDAMAGE, -dmg * 0.75, -dmg, 7)                  
                doTeleportThing(creature.uid, square.exitpos)
            end
        end
    end
end
fall()

It worked perfectly, thanks for the help and tips :)

1772298422909.webp
 
Back
Top