• 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+ Support TFS 1.x Spell

epaminombas

New Member
Joined
Apr 23, 2009
Messages
17
Reaction score
0
My script test work if player have equiped boots but if no have nothing equiped distro send error and i dont recive msg NO im new on tfs 1.x


function onCastSpell(creature, var)
if creature:getSlotItem(CONST_SLOT_FEET).itemid == 2195 then
creature:sendTextMessage(MESSAGE_STATUS_DEFAULT, "OK1")
creature:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
return true

elseif creature:getSlotItem(CONST_SLOT_FEET).itemid == 2643 then
creature:sendTextMessage(MESSAGE_STATUS_DEFAULT, "OK2")
creature:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
return true

else
creature:sendCancelMessage("NO")
return false
end
end
 

Attachments

  • ScreenShot030.jpg
    ScreenShot030.jpg
    166.5 KB · Views: 13 · VirusTotal
Solution
Lua:
function onCastSpell(creature, var)
    local player = Player(creature)
    if not player then
        return false
    end
    local item = player:getSlotItem(CONST_SLOT_FEET)
    if item then -- we need to make sure the item exists before we attempt to index for itemid
        if item.itemid == 2195 and player:getStorageValue(5000) then
            player:sendTextMessage(MESSAGE_STATUS_DEFAULT, "OK1")
            player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
        elseif item.itemid == 2643 and player:getStorageValue(5001) then
            player:sendTextMessage(MESSAGE_STATUS_DEFAULT, "OK2")
            player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
        else...
it's not a 1.x error, it's a general lua error
if player:getSlotItem(CONST_SLOT_FEET) returns a nil value (only happens if the player doesn't have an item in that slot) then indexing (using the dot) for itemid will throw "attempt to index a nil value"
so you need to check if the item exists before indexing it
Lua:
function onCastSpell(creature, var)
    local player = Player(creature)
    if not player then
        return false
    end
    local item = player:getSlotItem(CONST_SLOT_FEET)
    if item then -- we need to make sure the item exists before we attempt to index for itemid
        if item.itemid == 2195 then
            creature:sendTextMessage(MESSAGE_STATUS_DEFAULT, "OK1")
            creature:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
        elseif item.itemid == 2643 then
            creature:sendTextMessage(MESSAGE_STATUS_DEFAULT, "OK2")
            creature:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
        end
    else
        creature:sendCancelMessage("NO")
        return false
    end
    return true
end
 
it's not a 1.x error, it's a general lua error
if player:getSlotItem(CONST_SLOT_FEET) returns a nil value (only happens if the player doesn't have an item in that slot) then indexing (using the dot) for itemid will throw "attempt to index a nil value"
so you need to check if the item exists before indexing it
Lua:
function onCastSpell(creature, var)
    local player = Player(creature)
    if not player then
        return false
    end
    local item = player:getSlotItem(CONST_SLOT_FEET)
    if item then -- we need to make sure the item exists before we attempt to index for itemid
        if item.itemid == 2195 then
            creature:sendTextMessage(MESSAGE_STATUS_DEFAULT, "OK1")
            creature:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
        elseif item.itemid == 2643 then
            creature:sendTextMessage(MESSAGE_STATUS_DEFAULT, "OK2")
            creature:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
        end
    else
        creature:sendCancelMessage("NO")
        return false
    end
    return true
end
Works thx <3
 
Another question if a add storage requeriment how i can do it?

i can do it? if item.itemid == 2195 and getStorageValue(5000) == 1 then



function onCastSpell(creature, var)
local player = Player(creature)
if not player then
return false
end
local item = player:getSlotItem(CONST_SLOT_FEET)
if item then -- we need to make sure the item exists before we attempt to index for itemid
if item.itemid == 2195 and getStorageValue(5000) == 1 then
creature:sendTextMessage(MESSAGE_STATUS_DEFAULT, "OK1")
creature:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
elseif item.itemid == 2643 then
creature:sendTextMessage(MESSAGE_STATUS_DEFAULT, "OK2")
creature:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
end
else
creature:sendCancelMessage("NO")
return false
end
return true
end
 
If use any other boots spell cast and say NO and spent mana and storage requeriment dont work if i use 2195 spell casts ignore storage requeriment

Lua:
function onCastSpell(creature, var)
    local player = Player(creature)
    if not player then
        return false
    end
    local item = player:getSlotItem(CONST_SLOT_FEET)
    if item then -- we need to make sure the item exists before we attempt to index for itemid
        if item.itemid == 2195 and player:getStorageValue(5000) then
            creature:sendTextMessage(MESSAGE_STATUS_DEFAULT, "OK1")
            creature:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
        elseif item.itemid == 2643 and player:getStorageValue(5001) then
            creature:sendTextMessage(MESSAGE_STATUS_DEFAULT, "OK2")
            creature:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
        end
    else
        creature:sendCancelMessage("NO")
        return false
    end
    return true
end
 
Last edited:
you're not comparing the storage value to any number, that's why it doesn't work
player:getStorageValue(storage) == number

if item.itemid == 2195 and player:getStorageValue(storage) == 1 then

Work Storage check but if you dont have storage spell spent mana and say words and dont say NO
 
Lua:
function onCastSpell(creature, var)
    local player = Player(creature)
    if not player then
        return false
    end
    local item = player:getSlotItem(CONST_SLOT_FEET)
    if item then -- we need to make sure the item exists before we attempt to index for itemid
        if item.itemid == 2195 and player:getStorageValue(5000) then
            player:sendTextMessage(MESSAGE_STATUS_DEFAULT, "OK1")
            player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
        elseif item.itemid == 2643 and player:getStorageValue(5001) then
            player:sendTextMessage(MESSAGE_STATUS_DEFAULT, "OK2")
            player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
        else
            player:sendCancelMessage("NO")
            return false
        end
    else
        player:sendCancelMessage("NO")
        return false
    end
    return true
end
 
Solution
Lua:
function onCastSpell(creature, var)
    local player = Player(creature)
    if not player then
        return false
    end
    local item = player:getSlotItem(CONST_SLOT_FEET)
    if item then -- we need to make sure the item exists before we attempt to index for itemid
        if item.itemid == 2195 and player:getStorageValue(5000) then
            player:sendTextMessage(MESSAGE_STATUS_DEFAULT, "OK1")
            player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
        elseif item.itemid == 2643 and player:getStorageValue(5001) then
            player:sendTextMessage(MESSAGE_STATUS_DEFAULT, "OK2")
            player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
        else
            player:sendCancelMessage("NO")
            return false
        end
    else
        player:sendCancelMessage("NO")
        return false
    end
    return true
end
Works !!!!
Wow you save my day i spent all day on this hehe <3 thx thx thx
 
Back
Top