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

[REQUEST] Tile that take health with %

henkas

Well-Known Member
Joined
Jul 8, 2015
Messages
989
Solutions
5
Reaction score
54
Hello
so basically it would be great to have system that takes health from you when you step on tile its similar when you step on fire. So it should be something like this when you step on that tile
1sec = 1% dmg
2sec = 2% dmg
3sec = 3% dmg
4sec = 4% dmg
5sec = 5% dmg
6sec = 6% dmg
7sec = 7% dmg
8sec = 8% dmg
9sec = 9% dmg
10sec = 10% dmg
so if you stay on that tile for 5sec it takes 5% health from and etc, when you reach 10sec it stays on that 10% dmg, it wont grow anymore because 10% is max, when you walk away from that tile and step again it starts over from 1% and etc.

USING TFS 1.2 8.60
 
I gave it a try.
Code:
local stepAid = 6000   --ActionId of the tile

function tileDamage(creature, stepAid, pos, damage)    
    local player = Creature(creature):getPlayer()
    if player == nil then
        return false
    end
    if pos == player:getPosition() then
    if damage > 10 then
        damage = 10
    end
    local percent = (player:getBaseMaxHealth() * damage) / 100
    print("Damage %: "..damage)
    doTargetCombatHealth(0, player, COMBAT_LIFEDRAIN, -percent, -percent, CONST_ME_DRAWBLOOD)
    newDamage = damage + 1
    addEvent(tileDamage, 1 * 1000, player.uid, stepAid, player:getPosition(), newDamage)
    else
        return false
    end
end

function onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if player == nil then
        return false
    end
    local pos = Tile(player:getPosition())
    if item.actionid == stepAid then
        addEvent(tileDamage, 1 * 1000, player.uid, stepAid, player:getPosition(), 1)
    end
    return true
end

function onStepOut(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if player == nil then
        return false
    end
    player:setStorageValue(stepAid, -1)
    stopEvent(tileDamage)
    return true
end

Then register the tileId in movements.xml, example:
Code:
<movevent event="StepIn" itemid="10495" script="tileDamage.lua" />
<movevent event="StepOut" itemid="10495" script="tileDamage.lua" />
 
I gave it a try.
Code:
local stepAid = 6000   --ActionId of the tile

function tileDamage(creature, stepAid, pos, damage)   
    local player = Creature(creature):getPlayer()
    if player == nil then
        return false
    end
    if pos == player:getPosition() then
    if damage > 10 then
        damage = 10
    end
    local percent = (player:getBaseMaxHealth() * damage) / 100
    print("Damage %: "..damage)
    doTargetCombatHealth(0, player, COMBAT_LIFEDRAIN, -percent, -percent, CONST_ME_DRAWBLOOD)
    newDamage = damage + 1
    addEvent(tileDamage, 1 * 1000, player.uid, stepAid, player:getPosition(), newDamage)
    else
        return false
    end
end

function onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if player == nil then
        return false
    end
    local pos = Tile(player:getPosition())
    if item.actionid == stepAid then
        addEvent(tileDamage, 1 * 1000, player.uid, stepAid, player:getPosition(), 1)
    end
    return true
end

function onStepOut(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if player == nil then
        return false
    end
    player:setStorageValue(stepAid, -1)
    stopEvent(tileDamage)
    return true
end

Then register the tileId in movements.xml, example:
Code:
<movevent event="StepIn" itemid="10495" script="tileDamage.lua" />
<movevent event="StepOut" itemid="10495" script="tileDamage.lua" />
Thanks for trying. Well nothing is happening console i clean, i registered, added correct tile id created tileDamage lua, but nothing is happening.
 
Weird, worked for me fine, also using TFS 1.2 but not 8.6. Maybe someone can fix it up? Don't know what's wrong/different in your version

EDIT

Oh, maybe it's because lifedrain type damage didn't exist? Don't remember.
Try changing it to COMBAT_PHYSICALDAMAGE
 
Weird, worked for me fine, also using TFS 1.2 but not 8.6. Maybe someone can fix it up? Don't know what's wrong/different in your version

EDIT

Oh, maybe it's because lifedrain type damage didn't exist? Don't remember.
Try changing it to COMBAT_PHYSICALDAMAGE
Same.
 
no console errors? use command prompt to check the errors
Isnt it linux function? Im on windows
All you can see is this
test.png

Once it reach Damge : 1 it crash
 
This is my best effort..
I don't work with tfs 1.2 :/

XML:
<movevent event="StepIn" actionid="10495" script="tileDamage.lua" />
<movevent event="StepOut" actionid="10495" script="tileDamage.lua" />
Lua:
local creatures = {}

local function tileDamage(cid, damage_multiplier)
    local creature = Creature(cid)
    if creature == nil then
        return true
    end
    if damage_multiplier ~= creatures[creature] then
        return true
    end
    local damage = (creature:getMaxHealth() / 100) * damage_multiplier
    creature:addHealth(-damage)
    creatures[creature] = damage_multiplier + 1
    addEvent(tileDamage, 1000, cid, damage_multiplier + 1)
end

function onStepIn(creature, item, position, fromPosition)
    local cid = creature:getId()
    creatures[Creature(cid)] = 1
    addEvent(tileDamage, 0, cid, 1)
    return true
end

function onStepOut(creature, item, position, fromPosition)
    local cid = creature:getId()
    creatures[Creature(cid)] = 0
    return true
end
 
Last edited:
This is my best effort..
I don't work with tfs 1.2 :/

XML:
<movevent event="StepIn" actionid="10495" script="tileDamage.lua" />
<movevent event="StepOut" actionid="10495" script="tileDamage.lua" />
Lua:
local creatures = {}

local function tileDamage(cid, damage_multiplier)
    local creature = Creature(cid)
    if creature == nil then
        return true
    end
    if damage_multiplier ~= creatures[creature] then
        return true
    end
    local damage = (creature:getMaxHealth() / 100) * damage_multiplier
    creature:addHealth(-damage)
    creatures[creature] = damage_multiplier + 1
    addEvent(tileDamage, 1000, cid, damage_multiplier + 1)
end

function onStepIn(creature, item, position, fromPosition)
    local cid = creature:getId()
    creatures[Creature(cid)] = 1
    addEvent(tileDamage, 0, cid, 1)
    return true
end

function onStepOut(creature, item, position, fromPosition)
    local cid = creature:getId()
    creatures[Creature(cid)] = 0
    return true
end
No crashes but nothing is happening it doesnt have errors either.
 
Will give it one more try, if you don't mind, i'm not a good scripter but it does feel like a challenge
Challenging yourself is the best way to learn. <3
No crashes but nothing is happening it doesnt have errors either.
If this doesn't work, I'm not sure why it's not working.

Make sure the tile in-game has ActionID from movements.xml

XML:
<movevent event="StepIn" actionid="10495" script="tileDamage.lua" />
<movevent event="StepOut" actionid="10495" script="tileDamage.lua" />
Lua:
local creatures = {}

function tileDamage(cid, damage_multiplier)   
    local creature = Creature(cid)
    if creature == nil then
        return true
    end
    if damage_multiplier ~= creatures[cid] then
        return true
    end
    local percent = (creature:getMaxHealth() / 100) * damage_multiplier
    creature:addHealth(-percent)
    creatures[cid] = damage_multiplier + 1
    addEvent(tileDamage, 1000, cid, damage_multiplier + 1)
end

function onStepIn(creature, item, position, fromPosition)
    local cid = creature:getId()
    creatures[cid] = 1
    addEvent(tileDamage, 0, cid, 1)
    return true
end

function onStepOut(creature, item, position, fromPosition)
    local cid = creature:getId()
    creatures[cid] = 0
    return true
end
 
Challenging yourself is the best way to learn. <3

If this doesn't work, I'm not sure why it's not working.

Make sure the tile in-game has ActionID from movements.xml

XML:
<movevent event="StepIn" actionid="10495" script="tileDamage.lua" />
<movevent event="StepOut" actionid="10495" script="tileDamage.lua" />
Lua:
local creatures = {}

function tileDamage(cid, damage_multiplier)
    local creature = Creature(cid)
    if creature == nil then
        return true
    end
    if damage_multiplier ~= creatures[cid] then
        return true
    end
    local percent = (creature:getMaxHealth() / 100) * damage_multiplier
    creature:addHealth(-percent)
    creatures[cid] = damage_multiplier + 1
    addEvent(tileDamage, 1000, cid, damage_multiplier + 1)
end

function onStepIn(creature, item, position, fromPosition)
    local cid = creature:getId()
    creatures[cid] = 1
    addEvent(tileDamage, 0, cid, 1)
    return true
end

function onStepOut(creature, item, position, fromPosition)
    local cid = creature:getId()
    creatures[cid] = 0
    return true
end
Thanks bro (L I don't really know why it doesn't work, tested it now. I do know where it does exit the event. At this line:
Code:
if damage_multiplier ~= creatures[cid] then
        return true
end
It falls into that check in every time you step on it, that's why it doesn't work I guess...
 
Back
Top