• 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 pet cast spell on command [TFS 1.2]

Aeronx

Intermediate OT User
Joined
Dec 17, 2015
Messages
735
Solutions
9
Reaction score
119
Hello otlanders, i've been doing some testing on spells for a new system i'm working on.

This spell should be casted by master and executed by summon. Instead is casted on master.

I did some spells for healing or damage and they work perfectly, but for some reason, "taunt" spell
is resisting me. Here's the script:

Code:
function onTargetCreature(cid, target)
local summons = getCreatureSummons(cid)
local target = summons:getMaster():getTarget()
    if summons ~= nil and #summons > 0 then
        for i = 1, #summons do
    return doChallengeCreature(summons[i], target)
     end
    end
    return true
end

local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_RED)
combat:setArea(createCombatArea(AREA_SQUARE1X1))
combat:setCallback(CALLBACK_PARAM_TARGETCREATURE, "onTargetCreature")


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

Also, tested this with the same result. It works but is used on master, not from summon.
Code:
function onTargetCreature(cid, target)
local summons = getCreatureSummons(cid)
local target = summons:getMaster():getTarget()
    if summons ~= nil and #summons > 0 then
        for i = 1, #summons do
    return doChallengeCreature(summons[i], target)
     end
    end
    return true
end

local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_RED)
combat:setArea(createCombatArea(AREA_SQUARE1X1))
combat:setCallback(CALLBACK_PARAM_TARGETCREATURE, "onTargetCreature")


function onCastSpell(cid, var)
    local summons = getCreatureSummons(cid)
    if summons ~= nil and #summons > 0 then
        for i = 1, #summons do
            return combat:execute(summons[i], var)
        end
    end
    return true
end
Any help would be welcome! thanks!
 
Solution
Lua:
local combat = createCombatObject()
local area = createCombatArea(AREA_SQUARE1X1)
setCombatArea(combat, area)
function onCastSpell(creature, var)
    local target = creature:getTarget()
    local summs = creature:getSummons()
        if #summs == 0 then
        creature:getPosition():sendMagicEffect(CONST_ME_POFF)
        creature:sendTextMessage(MESSAGE_STATUS_DEFAULT, "You do not have any summons.")
        return false
    end
   

    for i, summon in ipairs(summs) do
    local specs = Game.getSpectators(summon:getPosition(), false, false, 1, 1, 1, 1)
            for _, mon in pairs(specs) do
                if mon:isMonster() and mon:getMaster() ~= creature then...
Hello otlanders, i've been doing some testing on spells for a new system i'm working on.

This spell should be casted by master and executed by summon. Instead is casted on master.

I did some spells for healing or damage and they work perfectly, but for some reason, "taunt" spell
is resisting me. Here's the script:

Code:
function onTargetCreature(cid, target)
local summons = getCreatureSummons(cid)
local target = summons:getMaster():getTarget()
    if summons ~= nil and #summons > 0 then
        for i = 1, #summons do
    return doChallengeCreature(summons[i], target)
     end
    end
    return true
end

local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_RED)
combat:setArea(createCombatArea(AREA_SQUARE1X1))
combat:setCallback(CALLBACK_PARAM_TARGETCREATURE, "onTargetCreature")


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

Also, tested this with the same result. It works but is used on master, not from summon.
Code:
function onTargetCreature(cid, target)
local summons = getCreatureSummons(cid)
local target = summons:getMaster():getTarget()
    if summons ~= nil and #summons > 0 then
        for i = 1, #summons do
    return doChallengeCreature(summons[i], target)
     end
    end
    return true
end

local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_RED)
combat:setArea(createCombatArea(AREA_SQUARE1X1))
combat:setCallback(CALLBACK_PARAM_TARGETCREATURE, "onTargetCreature")


function onCastSpell(cid, var)
    local summons = getCreatureSummons(cid)
    if summons ~= nil and #summons > 0 then
        for i = 1, #summons do
            return combat:execute(summons[i], var)
        end
    end
    return true
end
Any help would be welcome! thanks!
None of that code makes any logical sense. Try this and see if it works out.
Lua:
function onTargetCreature(cid, target)
    local summons = getCreatureSummons(cid)
    if next(summons) then
        for _, summon in pairs(summons) do
            local target = summon:getMaster():getTarget()
            if target and target:isCreature() then
                doChallengeCreature(summon, target)
            end
        end
    end
end

local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_RED)
combat:setArea(createCombatArea(AREA_SQUARE1X1))
combat:setCallback(CALLBACK_PARAM_TARGETCREATURE, "onTargetCreature")

function onCastSpell(cid, var)
    return combat:execute(cid, var)
end
 
None of that code makes any logical sense. Try this and see if it works out.
Lua:
function onTargetCreature(cid, target)
    local summons = getCreatureSummons(cid)
    if next(summons) then
        for _, summon in pairs(summons) do
            local target = summon:getMaster():getTarget()
            if target and target:isCreature() then
                doChallengeCreature(summon, target)
            end
        end
    end
end

local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_RED)
combat:setArea(createCombatArea(AREA_SQUARE1X1))
combat:setCallback(CALLBACK_PARAM_TARGETCREATURE, "onTargetCreature")

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

Same result as mine, spell is casted on master, not on summon.

This one for exemple is perfectly working.

Code:
function onCastSpell(cid, variant)
    local summon = cid:getMaster() ~= 0
    if not summon then
        return false
    end
  
   local creature = Creature(cid)
    local summons = cid:getSummons()
    local target = creature:getTarget()
    local targetPos = target:getPosition()
    if summons ~= nil and #summons > 0 then
        for i = 1, #summons do
        local sumpos = summons[i]:getPosition()
        local min = 10
        local max = 20
                sumpos: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
                end
    return true
end
 
Same result as mine, spell is casted on master, not on summon.

This one for exemple is perfectly working.

Code:
function onCastSpell(cid, variant)
    local summon = cid:getMaster() ~= 0
    if not summon then
        return false
    end
 
   local creature = Creature(cid)
    local summons = cid:getSummons()
    local target = creature:getTarget()
    local targetPos = target:getPosition()
    if summons ~= nil and #summons > 0 then
        for i = 1, #summons do
        local sumpos = summons[i]:getPosition()
        local min = 10
        local max = 20
                sumpos: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
                end
    return true
end
ok how about this
Lua:
function onTargetCreature(creature, target)
    if creature and target then
        local cid = creature:getId()
        local summons = getCreatureSummons(cid)
        if next(summons) then
            for _, summon in pairs(summons) do
                local target = summon:getTarget()
                if target and target:isCreature() then
                    doChallengeCreature(summon, target)
                end
            end
        end
    end
end
local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_RED)
combat:setArea(createCombatArea(AREA_SQUARE1X1))
combat:setCallback(CALLBACK_PARAM_TARGETCREATURE, "onTargetCreature")
function onCastSpell(creature, var)
    return combat:execute(creature, var)
end

hmm i just noticed something.
Lua:
//doChallengeCreature(cid, target)
 
Last edited by a moderator:
same, casted on master not summon >.<

I've been struggling with this for hours now lol
 
Let's try this instead
Lua:
function onTargetCreature(creature, target)
    if creature and target then
        local cid = creature:getId()
        local summons = getCreatureSummons(cid)
        if next(summons) then
            if target:isCreature() then
                for _, summon in pairs(summons) do
                    doChallengeCreature(summon:getId(), target)
                end
            end
        end
    end
end

local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_RED)
combat:setArea(createCombatArea(AREA_SQUARE1X1))
combat:setCallback(CALLBACK_PARAM_TARGETCREATURE, "onTargetCreature")

function onCastSpell(creature, var)
    return combat:execute(creature, var)
end
 
nope, same.. did some testing on my own meanwhile, but still nothing.

May the problem be on combat:execute(creaure, var)? creature on spellcast is master not summon,
that may be the reason.
 
nope, same.. did some testing on my own meanwhile, but still nothing.

May the problem be on combat:execute(creaure, var)? creature on spellcast is master not summon,
that may be the reason.
Possibly but in the mean time lets alter this method and see what prints out.
Lua:
function onTargetCreature(creature, target)
   if creature and target then
       local summons = creature:getSummons()
       if next(summons) then
           if target:isCreature() then
               for _, summon in pairs(summons) do
                   print(summon:getName(), target:getName())
                   doChallengeCreature(summon:getId(), target)
               end
           end
       end
   end
end
 
yeah, summons can cast challenge spell. But i want to choose when they cast it. That's why im trying this spell.. no luck so far. Still testing things.

bump.. still not solved after trying nearly everything. Anyone that can give some light to the issue?

Thanks!
 
Last edited by a moderator:
Hope this can be useful:
Lua:
local area = createCombatArea(AREA_SQUARE1X1)
function monsterChallenge(creature)
    local summons = creature:getSummons()
    local target = Game.getSpectators(summons[1]:getPosition(), false, false, -1, +1, -1, +1)
    local monster = Monster(target[i])
    if target and monster then
        if summons ~= nil and #summons > 0 then
            for i = 1, #summons do
                return monster:selectTarget(summons[1])
            end
        end
    end
    doAreaCombatHealth(summons[1], COMBAT_HEALINGDAMAGE, summons[1]:getPosition(), area, 0, 0, CONST_ME_MAGIC_RED)
    return true
end

function onCastSpell(creature, var)
    return monsterChallenge(creature)
end
 
The spell doesnt even work.

I see you tried to make the monsters change targed. But the spells doesnt work at all.
 
Lua:
local combat = createCombatObject()
local area = createCombatArea(AREA_SQUARE1X1)
setCombatArea(combat, area)
function onCastSpell(creature, var)
    local target = creature:getTarget()
    local summs = creature:getSummons()
        if #summs == 0 then
        creature:getPosition():sendMagicEffect(CONST_ME_POFF)
        creature:sendTextMessage(MESSAGE_STATUS_DEFAULT, "You do not have any summons.")
        return false
    end
   

    for i, summon in ipairs(summs) do
    local specs = Game.getSpectators(summon:getPosition(), false, false, 1, 1, 1, 1)
            for _, mon in pairs(specs) do
                if mon:isMonster() and mon:getMaster() ~= creature then
                    mon:getPosition():sendMagicEffect(CONST_ME_REDSMOKE)
                    doChallengeCreature(summon, mon)
                end
            end
        doAreaCombatHealth(summon, COMBAT_HEALINGDAMAGE, summon:getPosition(), area, 0, 0, CONST_ME_MAGIC_RED)
        doCombat(summon, combat, var)
    end
   
return false
end
 
Solution
Wooo! finally! that worked great. I see what you did there. Close enough! Really thank you! Closed thread.
 
Back
Top