• 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 Remove percentage of player's health

darkmu

Well-Known Member
Joined
Aug 26, 2007
Messages
274
Solutions
1
Reaction score
50
Location
Paraná,Brazil
I'm building a small mechanic for King Zelos and I was unsure how to build a spell that removes 60% of the player if it hits him (wave), does anyone have a simple example of how I can do this? I never touched those magic parts.
 
Solution
Sorry, now will be right.

Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITBYFIRE)

combat:setArea(createCombatArea({
{0, 1, 1, 1, 0},
{1, 1, 1, 1, 1},
{1, 1, 3, 1, 1},
{1, 1, 1, 1, 1},
{0, 1, 1, 1, 0},
}))

function spellCallback(param)
local tile = Tile(Position(param.pos))
if tile then
if tile:getTopCreature() and tile:getTopCreature():isPlayer() then
local damage = ((tile:getTopCreature():getMaxHealth())*60)/100
doTargetCombatHealth(0, tile:getTopCreature(), COMBAT_DROWNDAMAGE, -damage, -damage, CONST_ME_NONE)
end
end
end

function onTargetTile(cid, pos)
local param = {}
param.cid = cid
param.pos = pos
param.count = 0
spellCallback(param)
end...
You'll need to create a spell using a param:
Code:
setCombatCallback(combat, CALLBACK_PARAM_TARGETTILE, "onTargetTile")

And you'll need to create the function onTargetTile, and put this:
Lua:
local damage = (creature:getMaxHealth())/60
To set your damage
 
I'm building a small mechanic for King Zelos and I was unsure how to build a spell that removes 60% of the player if it hits him (wave), does anyone have a simple example of how I can do this? I never touched those magic parts.
how did the mechanics of this boss?
 
I'm building a small mechanic for King Zelos and I was unsure how to build a spell that removes 60% of the player if it hits him (wave), does anyone have a simple example of how I can do this? I never touched those magic parts.

I'm testing what i've said to create it too for my server. So I ended up seeing what was wrong, the correct damage calculation would be:

Lua:
local damage = ((tile:getTopCreature():getMaxHealth())*60)/100

tile:getTopCreature() is my "creature", you can change this, according your spell.
 
I'm testing what i've said to create it too for my server. So I ended up seeing what was wrong, the correct damage calculation would be:

Lua:
local damage = ((tile:getTopCreature():getMaxHealth())*60)/100

tile:getTopCreature() is my "creature", you can change this, according your spell.
how did the mechanics of this boss?
 
how did the mechanics of this boss?

You'll need to create a spell using a param:
Code:
setCombatCallback(combat, CALLBACK_PARAM_TARGETTILE, "onTargetTile")

And you'll need to create the function onTargetTile, and put this:
Lua:
local damage = ((tile:getTopCreature():getMaxHealth())*60)/100
To set your damage
:rolleyes:
 
Last edited:
You'll need to create a spell using a param:
Code:
setCombatCallback(combat, CALLBACK_PARAM_TARGETTILE, "onTargetTile")

And you'll need to create the function onTargetTile, and put this:
Lua:
local damage = ((tile:getTopCreature():getMaxHealth())*60)/100
To set your damage
:rolleyes:
tried here but it doesn't work, what's wrong?

local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITBYFIRE)

combat:setArea(createCombatArea({
{0, 1, 1, 1, 0},
{1, 1, 1, 1, 1},
{1, 1, 3, 1, 1},
{1, 1, 1, 1, 1},
{0, 1, 1, 1, 0},
}))

function spellCallback(param)
local damage = ((tile:getTopCreature():getMaxHealth())*60)/100
local tile = Tile(Position(param.pos))
if tile then
if tile:getTopCreature() and tile:getTopCreature():isMonster() then
if tile:getTopCreature():getName():lower() == "White Pale" then
tile:getTopCreature():damage()
end
end
end
end

function onTargetTile(cid, pos)
local param = {}
param.cid = cid
param.pos = pos
param.count = 0
spellCallback(param)
end

setCombatCallback(combat, CALLBACK_PARAM_TARGETTILE, "onTargetTile")

function onCastSpell(creature, var)
return combat:execute(creature, var)
end
 
tried here but it doesn't work, what's wrong?
isMonster( ) ? You need to set isPlayer() in script.

Other change, you need to set a damage, like:
Lua:
doTargetCombatHealth(0, tile:getTopCreature(), COMBAT_DROWNDAMAGE, -damage, -damage, CONST_ME_NONE)

EDIT: Other change that i saw, script is limiting to one monster.
Lua:
if tile:getTopCreature():getName():lower() == "White Pale" then


Full script:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITBYFIRE)

combat:setArea(createCombatArea({
{0, 1, 1, 1, 0},
{1, 1, 1, 1, 1},
{1, 1, 3, 1, 1},
{1, 1, 1, 1, 1},
{0, 1, 1, 1, 0},
}))

function spellCallback(param)
local damage = ((tile:getTopCreature():getMaxHealth())*60)/100
local tile = Tile(Position(param.pos))
if tile then
if tile:getTopCreature() and tile:getTopCreature():isPlayer() then
doTargetCombatHealth(0, tile:getTopCreature(), COMBAT_DROWNDAMAGE, -damage, -damage, CONST_ME_NONE)
end
end
end

function onTargetTile(cid, pos)
local param = {}
param.cid = cid
param.pos = pos
param.count = 0
spellCallback(param)
end

setCombatCallback(combat, CALLBACK_PARAM_TARGETTILE, "onTargetTile")

function onCastSpell(creature, var)
return combat:execute(creature, var)
end
 
Last edited:
isMonster( ) ? You need to set isPlayer() in script.

Other change, you need to set a damage, like:
Lua:
doTargetCombatHealth(0, tile:getTopCreature(), COMBAT_DROWNDAMAGE, -damage, -damage, CONST_ME_NONE)

EDIT: Other change that i saw, script is limiting to one monster.
Lua:
if tile:getTopCreature():getName():lower() == "White Pale" then


Full script:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITBYFIRE)

combat:setArea(createCombatArea({
{0, 1, 1, 1, 0},
{1, 1, 1, 1, 1},
{1, 1, 3, 1, 1},
{1, 1, 1, 1, 1},
{0, 1, 1, 1, 0},
}))

function spellCallback(param)
local damage = ((tile:getTopCreature():getMaxHealth())*60)/100
local tile = Tile(Position(param.pos))
if tile then
if tile:getTopCreature() and tile:getTopCreature():isPlayer() then
doTargetCombatHealth(0, tile:getTopCreature(), COMBAT_DROWNDAMAGE, -damage, -damage, CONST_ME_NONE)
end
end
end

function onTargetTile(cid, pos)
local param = {}
param.cid = cid
param.pos = pos
param.count = 0
spellCallback(param)
end

setCombatCallback(combat, CALLBACK_PARAM_TARGETTILE, "onTargetTile")

function onCastSpell(creature, var)
return combat:execute(creature, var)
end
Lua:
Lua Script Error: [Spell Interface]
in callback: data/spells/scripts/monster/zeros.lua:onTargetTile
(Unknown scriptfile)
data/spells/scripts/monster/zeros.lua:14: attempt to index global 'tile' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/spells/scripts/monster/zeros.lua:14: in function 'spellCallback'
        data/spells/scripts/monster/zeros.lua:28: in function <data/spells/scripts/monster/zeros.lua:23>
        [C]: at 0x004dab50
 
Only invert the line 14 and 15.

Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITBYFIRE)

combat:setArea(createCombatArea({
{0, 1, 1, 1, 0},
{1, 1, 1, 1, 1},
{1, 1, 3, 1, 1},
{1, 1, 1, 1, 1},
{0, 1, 1, 1, 0},
}))

function spellCallback(param)
local tile = Tile(Position(param.pos))
local damage = ((tile:getTopCreature():getMaxHealth())*60)/100
if tile then
if tile:getTopCreature() and tile:getTopCreature():isPlayer() then
doTargetCombatHealth(0, tile:getTopCreature(), COMBAT_DROWNDAMAGE, -damage, -damage, CONST_ME_NONE)
end
end
end

function onTargetTile(cid, pos)
local param = {}
param.cid = cid
param.pos = pos
param.count = 0
spellCallback(param)
end

setCombatCallback(combat, CALLBACK_PARAM_TARGETTILE, "onTargetTile")

function onCastSpell(creature, var)
return combat:execute(creature, var)
end
 
Only invert the line 14 and 15.

Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITBYFIRE)

combat:setArea(createCombatArea({
{0, 1, 1, 1, 0},
{1, 1, 1, 1, 1},
{1, 1, 3, 1, 1},
{1, 1, 1, 1, 1},
{0, 1, 1, 1, 0},
}))

function spellCallback(param)
local tile = Tile(Position(param.pos))
local damage = ((tile:getTopCreature():getMaxHealth())*60)/100
if tile then
if tile:getTopCreature() and tile:getTopCreature():isPlayer() then
doTargetCombatHealth(0, tile:getTopCreature(), COMBAT_DROWNDAMAGE, -damage, -damage, CONST_ME_NONE)
end
end
end

function onTargetTile(cid, pos)
local param = {}
param.cid = cid
param.pos = pos
param.count = 0
spellCallback(param)
end

setCombatCallback(combat, CALLBACK_PARAM_TARGETTILE, "onTargetTile")

function onCastSpell(creature, var)
return combat:execute(creature, var)
end
Lua:
Lua Script Error: [Spell Interface]
in callback: data/spells/scripts/monster/zeros.lua:onTargetTile
(Unknown scriptfile)
data/spells/scripts/monster/zeros.lua:15: attempt to index a nil value
stack traceback:
        [C]: in function '__index'
        data/spells/scripts/monster/zeros.lua:15: in function 'spellCallback'
        data/spells/scripts/monster/zeros.lua:28: in function <data/spells/scripts/monster/zeros.lua:23>
        [C]: at 0x004dab50
 
Only invert the line 14 and 15.

Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITBYFIRE)

combat:setArea(createCombatArea({
{0, 1, 1, 1, 0},
{1, 1, 1, 1, 1},
{1, 1, 3, 1, 1},
{1, 1, 1, 1, 1},
{0, 1, 1, 1, 0},
}))

function spellCallback(param)
local tile = Tile(Position(param.pos))
local damage = ((tile:getTopCreature():getMaxHealth())*60)/100
if tile then
if tile:getTopCreature() and tile:getTopCreature():isPlayer() then
doTargetCombatHealth(0, tile:getTopCreature(), COMBAT_DROWNDAMAGE, -damage, -damage, CONST_ME_NONE)
end
end
end

function onTargetTile(cid, pos)
local param = {}
param.cid = cid
param.pos = pos
param.count = 0
spellCallback(param)
end

setCombatCallback(combat, CALLBACK_PARAM_TARGETTILE, "onTargetTile")

function onCastSpell(creature, var)
return combat:execute(creature, var)
end

Just one question, is there a possibility to transform these spells as if they were normal attacks? You lose 3 hitpoints due to an attack by a King Zelos. For when he unleashes the magic and hits the player he simply appears: You lose 1791 hitpoints, in which case there would be a possibility to put You lose 1791 hitpoints by a King Zelos.
 
Sorry, now will be right.

Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITBYFIRE)

combat:setArea(createCombatArea({
{0, 1, 1, 1, 0},
{1, 1, 1, 1, 1},
{1, 1, 3, 1, 1},
{1, 1, 1, 1, 1},
{0, 1, 1, 1, 0},
}))

function spellCallback(param)
local tile = Tile(Position(param.pos))
if tile then
if tile:getTopCreature() and tile:getTopCreature():isPlayer() then
local damage = ((tile:getTopCreature():getMaxHealth())*60)/100
doTargetCombatHealth(0, tile:getTopCreature(), COMBAT_DROWNDAMAGE, -damage, -damage, CONST_ME_NONE)
end
end
end

function onTargetTile(cid, pos)
local param = {}
param.cid = cid
param.pos = pos
param.count = 0
spellCallback(param)
end

setCombatCallback(combat, CALLBACK_PARAM_TARGETTILE, "onTargetTile")

function onCastSpell(creature, var)
return combat:execute(creature, var)
end
Post automatically merged:

Just one question, is there a possibility to transform these spells as if they were normal attacks? You lose 3 hitpoints due to an attack by a King Zelos. For when he unleashes the magic and hits the player he simply appears: You lose 1791 hitpoints, in which case there would be a possibility to put You lose 1791 hitpoints by a King Zelos.
Sorry, but doing this I don't know, I'm still studying about this type of script.

The biggest problem with this type of script is the damage is variable.

I'm going to owe that. :/
 
Solution
I'll leave mine here as well, but it will mark yours as the best answer. Thank you.

XML:
<instant name="XXXXX" words="XXXXXX" direction="1" selftarget="1" exhaustion="2000" needlearn="1"  script="x.lua"" />

Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITBYFIRE)

combat:setArea(createCombatArea({
{1},
{1},
{1},
{1},
{3},
}))

function onTargetTile(cid, pos)   
    local tile = Tile(Position(pos))   
    
    if tile:getTopCreature() and tile:getTopCreature():isPlayer() then
        local damage = ((tile:getTopCreature():getMaxHealth())*60)/100
        doTargetCombatHealth(0, tile:getTopCreature(), COMBAT_DROWNDAMAGE, -damage, -damage, CONST_ME_NONE)
    end
end
combat:setCallback(CALLBACK_PARAM_TARGETTILE, "onTargetTile")

function onCastSpell(creature, var)
    return combat:execute(creature, var)
end
 
Back
Top