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

Solved Spell help [TFS 1.2]

Aeronx

Intermediate OT User
Joined
Dec 17, 2015
Messages
735
Solutions
9
Reaction score
119
Hello everyone! Im trying to do a spell that is used by summons based on player lvl and mlvl.

Got this so far. but its not working. Error on doCombat.

Code:
local combat = {}
for i = 1, 9999 do
    combat[i] = createCombatObject()
    setCombatParam(combat[i], COMBAT_PARAM_TYPE, COMBAT_DEATHDAMAGE)
    setCombatParam(combat[i], COMBAT_PARAM_EFFECT, CONST_ME_YALAHARIGHOST)
    setCombatParam(combat[i], COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_DEATH)
    setCombatArea(combat[i], createCombatArea({{0, 1, 0},
                                               {1, 2, 1},
                                               {0, 1, 0}}))
end

function onCastSpell(cid, creature, var)
    local creature = Creature(cid)
    local owner = creature:getMaster()
    if not owner then
    return false
    end
    local level = owner:getLevel()
    local magic = owner:getMagicLevel()
     doCombat(cid, combat[(level * 2) + (magic*10)], var)
    return true
end

Thanks eveyone for help! :)

bump! Any help? Thanks
 
Last edited by a moderator:
Solution
after some editing, i got it working. This works perfectly! Thanks to everybody that helped.
Final code.
Code:
function onCastSpell(cid, variant)
    local summon = cid:getMaster() ~= 0
    if not summon then
        return false
    end
   
   local creature = Creature(cid)
    local owner = creature:getMaster()
    local target = owner:getTarget() 
    local targetPos = target:getPosition()
    local level = owner:getLevel()
    local maglevel = owner:getMagicLevel()
        local min = (level / 5) + (maglevel * 1.4) + 8
        local max = (level * 2) + (maglevel*10)
                creature:getPosition():sendDistanceEffect(target:getPosition(), CONST_ANI_DEATH)
                doAreaCombatHealth(cid, COMBAT_DEATHDAMAGE...
You were going in some weird ass direction trying to achieve what you want, I did this:
Lua:
local combat = createCombatObject()
    setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_DEATHDAMAGE)
    setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_YALAHARIGHOST)
    setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_DEATH)
    setCombatArea(combat, createCombatArea({{0, 1, 0},
                                               {1, 2, 1},
                                               {0, 1, 0}}))
                                              
function onCastSpell(cid, variant)
    local summon = cid:getMaster() ~= 0
    if not summon then
        return false
    end
    local owner = cid:getMaster()
    local level = owner:getLevel()
    local maglevel = owner:getMagicLevel()
    function onGetFormulaValues(player, level, maglevel)
        local min = (level / 5) + (maglevel * 1.4) + 8
        local max = (level * 2) + (maglevel*10)
        return -min, -max
    end
    setCombatCallBack(combat, CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")
    doCombat(cid, combat, var)
    return true
end
and try to favour meta methods over the old style if you can
 
@Aled Not working.
Code:
Lua Script Error: [Spell Interface]
data/spells/scripts/test.lua:onCastSpell
data/spells/scripts/test.lua:22: attempt to call global 'setCombatCallBack' (a nil value)
stack traceback:
        [C]: in function 'setCombatCallBack'
        data/spells/scripts/test.lua:22: in function <data/spells/scripts/test.lua:9>
 
This is probably a better way to do what you want
Lua:
                                   local area ={{0, 1, 0},
                                               {1, 2, 1},
                                               {0, 1, 0}}                           
function onCastSpell(cid, variant)
    local summon = cid:getMaster() ~= 0
    if not summon then
        return false
    end
    local owner = cid:getMaster()
    local level = owner:getLevel()
    local maglevel = owner:getMagicLevel()
        local min = (level / 5) + (maglevel * 1.4) + 8
        local max = (level * 2) + (maglevel*10)
    doAreaCombatHealth(cid, COMBAT_DEATHDAMAGE, cid:getPosition(), area, min, max, CONST_ME_YALAHARIGHOST)
    return true
end
though I don't know if that function exists in TFS 1.2 one sec
edit: should work, let me know, might need to change min and max to -min and -max, don't know
 
Last edited:
I did a little change, cause it was casting on himself, instead of target. Now no error but no DMG and animation is only shown on monster, not doing area.
Code:
                                 local area ={{0, 1, 0},
                                               {1, 1, 1},
                                               {0, 1, 0}}                        
function onCastSpell(cid, variant)
    local summon = cid:getMaster() ~= 0
    if not summon then
        return false
    end
    local owner = cid:getMaster()
    local level = owner:getLevel()
    local maglevel = owner:getMagicLevel()
        local min = (level / 5) + (maglevel * 1.4) + 8
        local max = (level * 2) + (maglevel*10)
        local target = owner:getTarget()
    doAreaCombatHealth(target, COMBAT_DEATHDAMAGE, target:getPosition(), area, -min, -max, CONST_ME_YALAHARIGHOST)
    return true
end

Also, tested this. Not working at all.
Code:
local combat = createCombatObject()
    setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_DEATHDAMAGE)
    setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_YALAHARIGHOST)
    setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_DEATH)
    setCombatArea(combat, createCombatArea({{0, 1, 0},
                                               {1, 2, 1},
                                               {0, 1, 0}}))
                                          function onGetFormulaValues(player, level, maglevel)
        local min = (level / 5) + (maglevel * 1.4) + 8
        local max = (level * 2) + (maglevel*10)
        return -min, -max
    end
    setCombatCallBack(combat, CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")     
function onCastSpell(cid, variant)
    local summon = cid:getMaster() ~= 0
    if not summon then
        return false
    end
    local owner = cid:getMaster()
    local level = owner:getLevel()
    local maglevel = owner:getMagicLevel()

    doCombat(cid, combat, var)
    return true
end

EDIT: I've been doing some testing, and if i set on monster spell min max damage, it deals damage. So the spell is not getting the formula to monster cast.
 
Last edited:
Sorry, I didn't know you wanted it to cast on target, change to
Lua:
                                  local area ={{0, 1, 0},
                                               {1, 3, 1},
                                               {0, 1, 0}}                        
function onCastSpell(cid, variant)
    local summon = cid:getMaster() ~= 0
    if not summon then
        return false
    end
    local target = cid:getTarget()
    local owner = cid:getMaster()
    local level = owner:getLevel()
    local maglevel = owner:getMagicLevel()
        local min = (level / 5) + (maglevel * 1.4) + 8
        local max = (level * 2) + (maglevel*10)
    cid:getPosition():sendDistanceEffect(target:getPosition(), CONST_ANI_DEATH)
    doAreaCombatHealth(cid, COMBAT_DEATHDAMAGE, target:getPosition(), area, -min, -max, CONST_ME_YALAHARIGHOST)
    return true
end
 
Not working, no error so far. I've been doing some research, and i dont think is that easy for summon to attack with spells based on masters level, mlevel.

Anyone that can give some insight on this matter? Really appreciate it!

Thank you everyone!
 
I mean it doesnt damage the target. Doesnt show the distance nor hit animation. No erros tho.
 
I mean it doesnt damage the target. Doesnt show the distance nor hit animation. No erros tho.
I don't know why that stupid function isn't working but I found a workaround for you
Lua:
function onCastSpell(cid, variant)
    local summon = cid:getMaster() ~= 0
    if not summon then
        return false
    end
    local target = cid:getTarget()  
   local targetPos = target:getPosition()
    local owner = cid:getMaster()
    local level = owner:getLevel()
    local maglevel = owner:getMagicLevel()
        local min = (level / 5) + (maglevel * 1.4) + 8
        local max = (level * 2) + (maglevel*10)
                cid:getPosition():sendDistanceEffect(target:getPosition(), CONST_ANI_DEATH)
                doAreaCombatHealth(cid, COMBAT_DEATHDAMAGE, Position(targetPos.x,targetPos.y,targetPos.z), {1}, -min, -max, CONST_ME_YALAHARIGHOST)
                doAreaCombatHealth(cid, COMBAT_DEATHDAMAGE, Position(targetPos.x-1,targetPos.y,targetPos.z), {1}, -min, -max, CONST_ME_YALAHARIGHOST)
                doAreaCombatHealth(cid, COMBAT_DEATHDAMAGE, Position(targetPos.x+1,targetPos.y,targetPos.z), {1}, -min, -max, CONST_ME_YALAHARIGHOST)
                doAreaCombatHealth(cid, COMBAT_DEATHDAMAGE, Position(targetPos.x,targetPos.y-1,targetPos.z), {1}, -min, -max, CONST_ME_YALAHARIGHOST)
                doAreaCombatHealth(cid, COMBAT_DEATHDAMAGE, Position(targetPos.x,targetPos.y+1,targetPos.z), {1}, -min, -max, CONST_ME_YALAHARIGHOST)
    return true
end
 
Last edited:
I don't know why that stupid function isn't working but I found a workaround for you
Lua:
function onCastSpell(cid, variant)
    local summon = cid:getMaster() ~= 0
    if not summon then
        return false
    end
    local target = cid:getTarget()
    local owner = cid:getMaster()
    local level = owner:getLevel()
    local maglevel = owner:getMagicLevel()
        local min = (level / 5) + (maglevel * 1.4) + 8
        local max = (level * 2) + (maglevel*10)
                cid:getPosition():sendDistanceEffect(target:getPosition(), CONST_ANI_DEATH)
                doAreaCombatHealth(cid, COMBAT_DEATHDAMAGE, Position(targetPos.x,targetPos.y,targetPos.z), {1}, -min, -max, CONST_ME_YALAHARIGHOST)
                doAreaCombatHealth(cid, COMBAT_DEATHDAMAGE, Position(targetPos.x-1,targetPos.y,targetPos.z), {1}, -min, -max, CONST_ME_YALAHARIGHOST)
                doAreaCombatHealth(cid, COMBAT_DEATHDAMAGE, Position(targetPos.x+1,targetPos.y,targetPos.z), {1}, -min, -max, CONST_ME_YALAHARIGHOST)
                doAreaCombatHealth(cid, COMBAT_DEATHDAMAGE, Position(targetPos.x,targetPos.y-1,targetPos.z), {1}, -min, -max, CONST_ME_YALAHARIGHOST)
                doAreaCombatHealth(cid, COMBAT_DEATHDAMAGE, Position(targetPos.x,targetPos.y+1,targetPos.z), {1}, -min, -max, CONST_ME_YALAHARIGHOST)
    return true
end

Please use creature / player insted of cid when it comes to 1.1 and above.
The creature id is no longer getting pushed but rather a userdata value, if you want the creature id (cid) from the userdata value use player:getId()
In this case of spells, creature is used.
 
Not working either. targetPos nil value. Also you need to do this: local target = owner:getTarget() instead of cid:getTarget() (Its a summon, it doesnt have a target, unless master has a target)

Still, only shoot effect, no animation, no damage.
 
after some editing, i got it working. This works perfectly! Thanks to everybody that helped.
Final code.
Code:
function onCastSpell(cid, variant)
    local summon = cid:getMaster() ~= 0
    if not summon then
        return false
    end
   
   local creature = Creature(cid)
    local owner = creature:getMaster()
    local target = owner:getTarget() 
    local targetPos = target:getPosition()
    local level = owner:getLevel()
    local maglevel = owner:getMagicLevel()
        local min = (level / 5) + (maglevel * 1.4) + 8
        local max = (level * 2) + (maglevel*10)
                creature:getPosition():sendDistanceEffect(target:getPosition(), CONST_ANI_DEATH)
                doAreaCombatHealth(cid, COMBAT_DEATHDAMAGE, Position(targetPos.x,targetPos.y,targetPos.z), {1}, -min, -max, CONST_ME_YALAHARIGHOST)
                doAreaCombatHealth(cid, COMBAT_DEATHDAMAGE, Position(targetPos.x-1,targetPos.y,targetPos.z), {1}, -min, -max, CONST_ME_YALAHARIGHOST)
                doAreaCombatHealth(cid, COMBAT_DEATHDAMAGE, Position(targetPos.x+1,targetPos.y,targetPos.z), {1}, -min, -max, CONST_ME_YALAHARIGHOST)
                doAreaCombatHealth(cid, COMBAT_DEATHDAMAGE, Position(targetPos.x,targetPos.y-1,targetPos.z), {1}, -min, -max, CONST_ME_YALAHARIGHOST)
                doAreaCombatHealth(cid, COMBAT_DEATHDAMAGE, Position(targetPos.x,targetPos.y+1,targetPos.z), {1}, -min, -max, CONST_ME_YALAHARIGHOST)
    return true
end
 
Solution
Back
Top