• 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 TFS 1.4.2 Spell Request

helmut7414

New Member
Joined
Mar 3, 2012
Messages
22
Solutions
1
Reaction score
4
Hello Otlanders,
I need a little bit help with a spell I am working on but I can´t get it to work. it should be a monster spell
To explain it I need a spell which only do damage when the vocation matches I have tryed a lot but can´t get it to work. Seems like I can not get any target info when the spell is triggered.

Lua:
function onCastSpell(cid, var)
    if target:getVocation() == 2 then
        return doCombat(cid, combat, var)
    end
    return false
end

I would appreciate it if someone could help me.
Best regards
helmut
 
Last edited:
Hello Otlanders,
I need a little bit help with a spell I am working on but I can´t get it to work. it should be a monster spell
To explain it I need a spell which only do damage when the vocation matches I have tryed a lot but can´t get it to work. Seems like I can not get any target info when the spell is triggered.

Lua:
function onCastSpell(cid, var)
    if target:getVocation() == 2 then
        return doCombat(cid, combat, var)
    end
    return false
end

I would appreciate it if someone could help me.
Best regards
helmut

there is no target variable on the code you are showing us, nor there is a target parameter in the function

Im not sure if you can use target as a parameter in the function onCastSpell

but you can also do something like this:

local target = cid:getTarget()
 
Thanks for the tipps I landed with this input by:
Lua:
local condition = Condition(COMBAT_PHYSICALDAMAGE)
condition:setParameter(CONDITION_PARAM_DELAYED, 1)
condition:addDamage(1, 1, -2000)
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HEARTS)
combat:addCondition(condition)

function onCastSpell(creature, variant)
    for _, target in ipairs(combat:getTargets(creature, variant)) do
        if target:getVocation():getId() == 0 then -- Knight
            combat:execute(creature, variant)
            return true
        else 
            return false
        end
    end
end

But it doesn´t matter what vocation id i put in there the monster still doing the condition to all vocations. Someone any idea how I can fix this?
 
Thanks for the tipps I landed with this input by:
Lua:
local condition = Condition(COMBAT_PHYSICALDAMAGE)
condition:setParameter(CONDITION_PARAM_DELAYED, 1)
condition:addDamage(1, 1, -2000)
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HEARTS)
combat:addCondition(condition)

function onCastSpell(creature, variant)
    for _, target in ipairs(combat:getTargets(creature, variant)) do
        if target:getVocation():getId() == 0 then -- Knight
            combat:execute(creature, variant)
            return true
        else 
            return false
        end
    end
end

But it doesn´t matter what vocation id i put in there the monster still doing the condition to all vocations. Someone any idea how I can fix this?
try doing some tests, in the line above

if target:getVocation():getId() == 0 then -- Knight

put the code print("player vocation: " .. target:getVocation():getId())

and check if the vocation you are getting in this line is the one you want
 
try doing some tests, in the line above

if target:getVocation():getId() == 0 then -- Knight

put the code print("player vocation: " .. target:getVocation():getId())

and check if the vocation you are getting in this line is the one you want
I have done this and it returns: player vocation: 4
But the spell is appling the condition even if
if target:getVocation():getId() == 0 then

I am getting the vocation correct but the problem i faceing is that even if the target is not vocationId 0 that the spell applies the condition
Post automatically merged:

Holy.... I have got it


Lua:
function onCastSpell(creature, variant)
    local combat = Combat()
    local targets = combat:getTargets(creature, variant)
    local validTarget = false  -- Flag to track if at least one valid target is found
   
    for _, target in ipairs(targets) do
        local condition = Condition(COMBAT_PHYSICALDAMAGE)
        condition:setParameter(CONDITION_PARAM_DELAYED, 1)
        condition:addDamage(1, 1, -2000)

        combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
        combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HEARTS)
        combat:addCondition(condition)
        print("player vocation: " .. target:getVocation():getId())
        if target:getVocation():getId() == 2 then
            validTarget = true  -- Set flag to true
        end
        if validTarget then
           
            return combat:execute(creature, variant)
        else
            return false
        end
    end
end

This is working. Now it will apply the condition only to vocation 2

Mark it as Solved
 
Last edited:
Back
Top