• 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.3 Check slot

lazarus321

Member
Joined
May 8, 2017
Messages
209
Reaction score
20
I'm trying to do a check while using a spell but I can not do it.
It is a check if it is axe or sword. anyone can help? is tfs 1.3.

function onCastSpell(creature, variant)
local player = Player(creature)

local leftHand = player:getSlotItem(CONST_SLOT_LEFT)
local item = leftHand:getWeaponType()

creature:say(''..item..'', TALKTYPE_MONSTER_SAY)

end
 
Last edited:
I'm trying to do a check while using a spell but I can not do it.
It is a check if it is axe or sword. anyone can help? is tfs 1.3.

function onCastSpell(creature, variant)
local player = Player(creature)

local leftHand = player:getSlotItem(CONST_SLOT_LEFT)
local item = rightHand:getWeaponType()

creature:say(''..item..'', TALKTYPE_MONSTER_SAY)

end
You don't have to convert creature to a player if a player is the one casting the spell because a player is a creature. Also if for any reason you do create a Player from creature you should check if the player exists before using any of its methods otherwise you end up with errors if the player doesn't exist.

Example is:
Lua:
function onCastSpell(creature, variant)
    local player = Player(creature)
    if player then
        -- code that the player will use
    end

Also if you are testing code use print to print the values to the console this way you can either copy & paste or take a screen shot of the console.
Example:
Lua:
function onCastSpell(creature, variant)
    local leftHand = creature:getSlotItem(CONST_SLOT_LEFT)
    if leftHand then
        local weapon = Item(leftHand:getUniqueId())
        if weapon then
            print("weapon id:", weapon:getId(), "weapon name:", weapon:getName())
        else
            print("The item could not be created.")
        end
    else
        print("The player is not holding a weapon.")
    end
    return true
end
The code above is a proper way to test the execution of a script.
Furthermore if you are testing code you should give as much information as possible other than it doesn't work or you tried.
 
Back
Top