• 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
 
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
Indeed it has right actionid because im using same action id that i used on Ramirow script
 
I know my script probably isn't done in a proper way, but look:
Code:
Febble has logged in.
Damage %: 1
Damage %: 2
Damage %: 3
Damage %: 4
Damage %: 5
Damage %: 6
Damage %: 7
Damage %: 8
Damage %: 9
Damage %: 10
Damage %: 10
Damage %: 10

Code:
15:51 You lose 9 hitpoints.
15:51 You lose 18 hitpoints.
15:51 You lose 28 hitpoints.
15:51 You lose 37 hitpoints.
15:51 You lose 47 hitpoints.
15:51 You lose 56 hitpoints.
15:51 You lose 66 hitpoints.
15:51 You lose 75 hitpoints.
15:51 You lose 85 hitpoints.
15:51 You lose 94 hitpoints.
15:51 You lose 94 hitpoints.
15:51 You lose 94 hitpoints.

----EDIT----
I still don't know why it crashes on your side ._.
 
Ramirow was using itemid not actionid. xP
That's why I mentioned to check it. :oops:
Untitled.png

And that time i replaced that stepaid to mine which is 7900 and now im using same actionid on yours
<movevent event="StepIn" actionid="7900" script="tileDamage.lua" />
<movevent event="StepOut" actionid="7900" script="tileDamage.lua" />
 
Untitled.png

And that time i replaced that stepaid to mine which is 7900 and now im using same actionid on yours
<movevent event="StepIn" actionid="7900" script="tileDamage.lua" />
<movevent event="StepOut" actionid="7900" script="tileDamage.lua" />
uP7HvsD.png


LJ6A1Ku.png

:p:p:p:p:p:p:p:p:p
 
Still nothing :D
Did some teamviewer session.. and something is wrong with source when taking health away it crashes server.. :/

tried in movements and actions, and also disabled some onHealthChange script to try to narrow down the problem, but it seems to be a source issue.

If it's not a source issue, can someone tell us what we're doing wrong?

This is the current working code. (with damage reduction green texted.)

Lua:
global_creatures_tileDamage = {}

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

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

function onStepOut(creature, item, position, fromPosition)
    local cid = creature:getId()
    global_creatures_tileDamage[cid] = 0
    return true
end
 
Did some teamviewer session.. and something is wrong with source when taking health away it crashes server.. :/

tried in movements and actions, and also disabled some onHealthChange script to try to narrow down the problem, but it seems to be a source issue.

If it's not a source issue, can someone tell us what we're doing wrong?

This is the current working code. (with damage reduction green texted.)

Lua:
global_creatures_tileDamage = {}

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

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

function onStepOut(creature, item, position, fromPosition)
    local cid = creature:getId()
    global_creatures_tileDamage[cid] = 0
    return true
end

Sorry mate, didn't have much time yesterday :( Anyways, tested your script on my TFS 1.2 and works perfectly (even tough it removes health with a weird purple color number)
If that crashes his server, I used the doTargetCombatHealth as that's what ground traps use to deal damage, this worked fine also:
Code:
doTargetCombatHealth(0, cid, COMBAT_PHYSICALDAMAGE, -damage, -damage, CONST_ME_DRAWBLOOD)

So, the script does work for tfs 1.2
 
Sorry mate, didn't have much time yesterday :( Anyways, tested your script on my TFS 1.2 and works perfectly (even tough it removes health with a weird purple color number)
If that crashes his server, I used the doTargetCombatHealth as that's what ground traps use to deal damage, this worked fine also:
Code:
doTargetCombatHealth(0, cid, COMBAT_PHYSICALDAMAGE, -damage, -damage, CONST_ME_DRAWBLOOD)

So, the script does work for tfs 1.2
This one also gives crash
 
It's weird that it crashes while using for example 'doTargetCombatHealth' as I have checked the link and it has that same function applied to traps in movements, would you be so kind to see if a trap placed on the map actually works or crashes the server too? If it does crash, then the source is bugged I might say
 
It's weird that it crashes while using for example 'doTargetCombatHealth' as I have checked the link and it has that same function applied to traps in movements, would you be so kind to see if a trap placed on the map actually works or crashes the server too? If it does crash, then the source is bugged I might say
To bad i deleted all traps from movevents same with sprites so no chance i can test it, sorry.
 
Back
Top