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

TFS 1.X+ Check if item is equiped on player to cast spells

Allan Silva

New Member
Joined
May 30, 2018
Messages
33
Reaction score
4
Hi
I'm trying to put a function to check if the player is using an item, if it is positive, the player can use the ability, otherwise the player can't use the spell, since only players with the equipped item can release the spell.

Lua:
local weapons = {
        {itemId = 2321}, -- giant smithhammer
        }
      
function onStepIn(cid, item, position, fromPosition)
    if getPlayerItemCount(cid, weapons.itemId) >= count then
    addEvent(onCastSpell, 100, var)
    end
end


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)
    return combat:execute(creature, var)
end


Anyone know how to change the script and perform this check? I'm using TFS 1.3
Thanks!
 
Last edited:
Solution
Here you go. Tested.
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...

Snavy

Bakasta
Senator
Joined
Apr 1, 2012
Messages
1,244
Solutions
71
Reaction score
548
Location
Hell
Try:
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, -- giant smithhammer
    }

    local playerWeapon = getPlayerWeapon(cid)
    if playerWeapon and table.find(weapons, playerWeapon.itemid) ~= nil then
        return combat:execute(creature, var)
    end

    doPlayerSendCancel(cid, "You need a special weapon to execute this spell.")
    return false
end
 
OP
A

Allan Silva

New Member
Joined
May 30, 2018
Messages
33
Reaction score
4
Try:
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, -- giant smithhammer
    }

    local playerWeapon = getPlayerWeapon(cid)
    if playerWeapon and table.find(weapons, playerWeapon.itemid) ~= nil then
        return combat:execute(creature, var)
    end

    doPlayerSendCancel(cid, "You need a special weapon to execute this spell.")
    return false
end


Lua:
data/spells/scripts/custom/teste.lua:onCastSpell
data/spells/scripts/custom/teste.lua:22: attempt to call global 'getPlayerWeapon' (a nil value)
 

Snavy

Bakasta
Senator
Joined
Apr 1, 2012
Messages
1,244
Solutions
71
Reaction score
548
Location
Hell
Lua:
data/spells/scripts/custom/teste.lua:onCastSpell
data/spells/scripts/custom/teste.lua:22: attempt to call global 'getPlayerWeapon' (a nil value)
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, -- giant smithhammer
    }

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

    doPlayerSendCancel(cid, "You need a special weapon to execute this spell.")
    return false
end
 
OP
A

Allan Silva

New Member
Joined
May 30, 2018
Messages
33
Reaction score
4
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, -- giant smithhammer
    }

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

    doPlayerSendCancel(cid, "You need a special weapon to execute this spell.")
    return false
end

Without erros in console, spells dont work.. Do you believe it is possible to do this check to use spells? I haven't seen anything like it in forum posts. Thanks to try help me XD
 

Snavy

Bakasta
Senator
Joined
Apr 1, 2012
Messages
1,244
Solutions
71
Reaction score
548
Location
Hell
Here you go. Tested.
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,
    }

    for slot = CONST_SLOT_RIGHT, CONST_SLOT_LEFT do
        local playerWeapon = creature:getSlotItem(slot)
        if playerWeapon and table.contains(weapons, playerWeapon: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

Do you believe it is possible to do this check to use spells?
Do you mean this same check for all spells?
 
Last edited by a moderator:
Solution
OP
A

Allan Silva

New Member
Joined
May 30, 2018
Messages
33
Reaction score
4
Here you go. Tested.
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,
    }

    for slot = CONST_SLOT_RIGHT, CONST_SLOT_LEFT do
        local playerWeapon = creature:getSlotItem(slot)
        if playerWeapon and table.contains(weapons, playerWeapon: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


Do you mean this same check for all spells?

You really good, now the scripts working! thanks to help me XD
 
Top