• 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 Summon with same life as the caster TFS 1.3

Icaraii

Well-Known Member
Joined
Jan 5, 2020
Messages
469
Solutions
1
Reaction score
58
Hey guys,

I would like a spell, where the summon get the same life as the caster and if it's possible, when the caster lose health, the summon loses same amount of health, when player heals or get healed the summon get the same amount of heal. Summon last for 30 seconds.
 
Solution
untested. make the spell self-cast
Lua:
function onCastSpell(creature, variant)
    local summon = Game.createMonster("green djinn", creature:getPosition())
    if summon then
        summon:setMaster(creature)
        local healthAmount = creature:getMaxHealth()
        summon:setMaxHealth(healthAmount)
        summon:setHealth(healthAmount)
        return true
    end
    return false
end
What kind of Outfit
How to make the Monster appear
What kind of dmg
Ohh I see, I thought I would do the monster by myself, like the normal tibia summon.

Well, it can be the green djinn outfit.
To summon the monster it cost 1000 mana.
The monster can use the normal green djinn spells and damage.
 
untested. make the spell self-cast
Lua:
function onCastSpell(creature, variant)
    local summon = Game.createMonster("green djinn", creature:getPosition())
    if summon then
        summon:setMaster(creature)
        local healthAmount = creature:getMaxHealth()
        summon:setMaxHealth(healthAmount)
        summon:setHealth(healthAmount)
        return true
    end
    return false
end
 
Last edited:
Solution
untested. make the spell self-cast
Lua:
function onCastSpell(creature, variant)
    local summon = Game.createMonster("green djinn", creature:getPosition())
    if summon then
        summon:setMaster(creature)
        summon:setMaxHealth(creature:getMaxHealth())
        return true
    end
    return false
end
No error on TFS, when I say the words (to cast the spell) it doesn't appear and also nothing happens
 
No error on TFS, when I say the words (to cast the spell) it doesn't appear and also nothing happens
Just tested it on my local server, everything works as expected.
Are you sure you set it to self-cast?

Post your spell.xml line.. maybe something else is wrong.
(Also realised that the monster hp wasn't healing monster to the new max health, so updated script above with that change. So recopy.)
 
XML:
    <instant group="support" spellid="229" name="summon djinn" words="summon djinn" level="5" mana="15" selftarget="1" blockwalls="1" cooldown="2000" groupcooldown="2000" needlearn="0" script="support/summon.lua">
        <vocation name="Crusader" />
    </instant>
 
XML:
    <instant group="support" spellid="229" name="summon djinn" words="summon djinn" level="5" mana="15" selftarget="1" blockwalls="1" cooldown="2000" groupcooldown="2000" needlearn="0" script="support/summon.lua">
        <vocation name="Crusader" />
    </instant>
Nothing wrong there.

Are you using the class 'crusader' when using the spell?
Is spellid 229 used previously?
did you re-confirm the directory and script name?
 
Nothing wrong there.

Are you using the class 'crusader' when using the spell?
Is spellid 229 used previously?
did you re-confirm the directory and script name?
Yes, I'm using crusader, and spellid 229 is not used previously.

Lua:
function onCastSpell(creature, variant)
    local summon = Game.createMonster("green djinn", creature:getPosition())
    if summon then
        summon:setMaster(creature)
        local healthAmount = creature:getMaxHealth()
        summon:setMaxHealth(healthAmount)
        summon:setHealth(healthAmount)
        return true
    end
    return false
end

I put that on the spell, nothing more, should I have put it something else?
 
Yes, I'm using crusader, and spellid 229 is not used previously.

Lua:
function onCastSpell(creature, variant)
    local summon = Game.createMonster("green djinn", creature:getPosition())
    if summon then
        summon:setMaster(creature)
        local healthAmount = creature:getMaxHealth()
        summon:setMaxHealth(healthAmount)
        summon:setHealth(healthAmount)
        return true
    end
    return false
end

I put that on the spell, nothing more, should I have put it something else?
nope, that's it.

idk, this sounds silly.. but do you have enough mana and level 15? xD

I literally copied your spell.xml line minus the crusader bit, and it worked perfectly for me.

Try with some prints.. and check your console.
Lua:
function onCastSpell(creature, variant)
    print("SPELL IS WORKING")
    local summon = Game.createMonster("green djinn", creature:getPosition())
    if summon then
        print("CREATURE SUMMONED")
        summon:setMaster(creature)
        local healthAmount = creature:getMaxHealth()
        summon:setMaxHealth(healthAmount)
        summon:setHealth(healthAmount)
        return true
    end
    print("CREATURE NOT NOT NOT SUMMONED")
    return false
end
 
I'm very dumb, I do not have a green djinn on my server yet, that is why it wasn't working... sorry. But hey, it does not heal itself when I heal myself, is that a way to make this happen?
 
I'm very dumb, I do not have a green djinn on my server yet, that is why it wasn't working... sorry. But hey, it does not heal itself when I heal myself, is that a way to make this happen?
You'd have to edit all of your healing spells to heal your summons.

Here's 'light healing', as an example.

Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_HEALING)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
combat:setParameter(COMBAT_PARAM_DISPEL, CONDITION_PARALYZE)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)

function onGetFormulaValues(player, level, magicLevel)
    local min = (level / 5) + (magicLevel * 1.4) + 8
    local max = (level / 5) + (magicLevel * 1.8) + 11
    
    local summons = player:getSummons()
    if #summons > 0 then
        for i = 1, #summons do
            summons[i]:addHealth(math.random(min, max))
        end
    end
    
    return min, max
end

combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onCastSpell(creature, variant)
    return combat:execute(creature, variant)
end
 
You'd have to edit all of your healing spells to heal your summons.

Here's 'light healing', as an example.

Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_HEALING)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
combat:setParameter(COMBAT_PARAM_DISPEL, CONDITION_PARALYZE)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)

function onGetFormulaValues(player, level, magicLevel)
    local min = (level / 5) + (magicLevel * 1.4) + 8
    local max = (level / 5) + (magicLevel * 1.8) + 11
   
    local summons = player:getSummons()
    if #summons > 0 then
        for i = 1, #summons do
            summons[i]:addHealth(math.random(min, max))
        end
    end
   
    return min, max
end

combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onCastSpell(creature, variant)
    return combat:execute(creature, variant)
end
ok, thanks for teaching me, I will do it to the other spells. And how about the summon has the same speed as player?
 
summon:changeSpeed((player:getSpeed() - summons:getSpeed()))
Lua Script Error: [Spell Interface]
data/spells/scripts/support/summon.lua:eek:nCastSpell
data/spells/scripts/support/summon.lua:8: attempt to index global 'player' (a nil value)
stack traceback:
[C]: in function '__index'
data/spells/scripts/support/summon.lua:8: in function <data/spells/scripts/support/summon.lua:1>
this error appear when I put the speed line

Lua:
function onCastSpell(creature, variant)
    local summon = Game.createMonster("skeleton", creature:getPosition())
    if summon then
        summon:setMaster(creature)
        local healthAmount = creature:getMaxHealth()
        summon:setMaxHealth(healthAmount)
        summon:setHealth(healthAmount)
        summon:changeSpeed((player:getSpeed() - summons[i]:getSpeed()))
        return true
    end
    return false
end
 
this error appear when I put the speed line

Lua:
function onCastSpell(creature, variant)
    local summon = Game.createMonster("skeleton", creature:getPosition())
    if summon then
        summon:setMaster(creature)
        local healthAmount = creature:getMaxHealth()
        summon:setMaxHealth(healthAmount)
        summon:setHealth(healthAmount)
        summon:changeSpeed((player:getSpeed() - summons[i]:getSpeed()))
        return true
    end
    return false
end
I edited my above post 4 minutes ago xP
re-copy, please.
 
Back
Top