• 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 TSF 1.3 How to: Spell only cast if player is using item x

Icaraii

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

I would like to edit some spells in my server so it only be casted if player is using some specific item, for example:

Player can only cast exori if player is using sword id 1111, sword id 2222, axe 1111 or axe id 2222. If player ain't using one of these itens appear message "you can't use this spell"

And, what if I would like for the player to be using 2 itens at the same time? For example:

Sword 1111, sword id 2222, axe 1111 or axe id 2222 in weapon hand and shield 1111, shield 2222 or shield 3333 in shield hand?

I will be glad if someone can help me
 
Last edited:
Solution
It kinda is. I tested and it's part of what I need, and works perfectly. But I would also like to know how to check 2 itens, for example:

Sword 1111, sword id 2222, axe 1111 or axe id 2222 in weapon hand and shield 1111, shield 2222 or shield 3333 in shield hand, if player has one of those sword and also one of those shield equiped, he can use the spell. If has only one of them, he can't use the spell.
Post automatically merged:

would it be something like this?

Lua:
function onCastSpell(creature, var)
    local weapons = {
        1111,
    }

    for slot = CONST_SLOT_LEFT do
        local playerWeapon = creature:getSlotItem(slot)
        if playerWeapon and table.contains(weapons, playerWeapon:getId()) then
            return...
I think you are looking for this one
 
I think you are looking for this one
It kinda is. I tested and it's part of what I need, and works perfectly. But I would also like to know how to check 2 itens, for example:

Sword 1111, sword id 2222, axe 1111 or axe id 2222 in weapon hand and shield 1111, shield 2222 or shield 3333 in shield hand, if player has one of those sword and also one of those shield equiped, he can use the spell. If has only one of them, he can't use the spell.
Post automatically merged:

would it be something like this?

Lua:
function onCastSpell(creature, var)
    local weapons = {
        1111,
    }

    for slot = CONST_SLOT_LEFT do
        local playerWeapon = creature:getSlotItem(slot)
        if playerWeapon and table.contains(weapons, playerWeapon:getId()) then
            return combat:execute(creature, var)
        end
    local shields = {
        1111,
    }

    for slot = CONST_SLOT_RIGHT do
        local playerShield = creature:getSlotItem(slot)
        if playerShield and table.contains(shields, playerShield:getId()) then
            return combat:execute(creature, var)
        end
    end

    creature:sendTextMessage(MESSAGE_STATUS_SMALL, "You need a special weapon to cast this spell.")
    return false
end
 
Last edited:
It kinda is. I tested and it's part of what I need, and works perfectly. But I would also like to know how to check 2 itens, for example:

Sword 1111, sword id 2222, axe 1111 or axe id 2222 in weapon hand and shield 1111, shield 2222 or shield 3333 in shield hand, if player has one of those sword and also one of those shield equiped, he can use the spell. If has only one of them, he can't use the spell.
Post automatically merged:

would it be something like this?

Lua:
function onCastSpell(creature, var)
    local weapons = {
        1111,
    }

    for slot = CONST_SLOT_LEFT do
        local playerWeapon = creature:getSlotItem(slot)
        if playerWeapon and table.contains(weapons, playerWeapon:getId()) then
            return combat:execute(creature, var)
        end
    local shields = {
        1111,
    }

    for slot = CONST_SLOT_RIGHT do
        local playerShield = creature:getSlotItem(slot)
        if playerShield and table.contains(shields, playerShield:getId()) then
            return combat:execute(creature, var)
        end
    end

    creature:sendTextMessage(MESSAGE_STATUS_SMALL, "You need a special weapon to cast this spell.")
    return false
end
Might not be the best way and requiers weapon to be in left hand and shield in right hand but works okay xD
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
combat:setParameter(COMBAT_PARAM_BLOCKARMOR, 1)
combat:setParameter(COMBAT_PARAM_USECHARGES, 1)
combat:setArea(createCombatArea(AREA_SQUARE1X1))

function onGetFormulaValues(player, skill, attack, factor)
    local level = player:getLevel()
    local min = (level / 5) + (skill + attack) * 0.5
    local max = (level / 5) + (skill + attack) * 1.5
    return -min * 1.1, -max * 1.1 -- TODO : Use New Real Formula instead of an %
end

combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")
function onCastSpell(creature, var)
    local weapons = {2321, 5342}
    local shields = {6391, 2523}

        local slotWeapon = CONST_SLOT_LEFT
        local slotShield = CONST_SLOT_RIGHT
        
        local playerWeapon = creature:getSlotItem(slotWeapon)
        local playerShield = creature:getSlotItem(slotShield)
        if playerWeapon and table.contains(weapons, playerWeapon:getId()) then
        if playerShield and table.contains(shields, playerShield:getId()) then
            return combat:execute(creature, var)
        end
    end

    creature:sendTextMessage(MESSAGE_STATUS_SMALL, "You need a special weapon to cast this spell.")
    return false
end
 
Solution
Might not be the best way and requiers weapon to be in left hand and shield in right hand but works okay xD
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
combat:setParameter(COMBAT_PARAM_BLOCKARMOR, 1)
combat:setParameter(COMBAT_PARAM_USECHARGES, 1)
combat:setArea(createCombatArea(AREA_SQUARE1X1))

function onGetFormulaValues(player, skill, attack, factor)
    local level = player:getLevel()
    local min = (level / 5) + (skill + attack) * 0.5
    local max = (level / 5) + (skill + attack) * 1.5
    return -min * 1.1, -max * 1.1 -- TODO : Use New Real Formula instead of an %
end

combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")
function onCastSpell(creature, var)
    local weapons = {2321, 5342}
    local shields = {6391, 2523}

        local slotWeapon = CONST_SLOT_LEFT
        local slotShield = CONST_SLOT_RIGHT
       
        local playerWeapon = creature:getSlotItem(slotWeapon)
        local playerShield = creature:getSlotItem(slotShield)
        if playerWeapon and table.contains(weapons, playerWeapon:getId()) then
        if playerShield and table.contains(shields, playerShield:getId()) then
            return combat:execute(creature, var)
        end
    end

    creature:sendTextMessage(MESSAGE_STATUS_SMALL, "You need a special weapon to cast this spell.")
    return false
end
Thank you very much, it work flawless
 
Back
Top