• 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!
  • If you're using Gesior 2012 or MyAAC, please review this thread for information about a serious security vulnerability and a fix.

Lua Problem with getSlotItem

MorganaSacani

Member
Joined
Sep 20, 2022
Messages
59
Reaction score
18
Lua:
local removeBagWeapon = MoveEvent()

function removeBagWeapon.onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if not player then
        return true
    end
    
    local weaponsId = {
        3270, 3291, 3293,
    }
    
    if player:getSlotItem(CONST_SLOT_LEFT).getId() == 3270 then
        Spdlog.info("1")
        return true
    end

    

    player:teleportTo(fromPosition)
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You need to equip a weapon before pass.")
    return true
end

removeBagWeapon:type("stepin")
removeBagWeapon:id(870)
removeBagWeapon:register()

[2022-27-09 11:30:58.842] [error] Lua script error:
scriptInterface: [Scripts Interface]
scriptId: [C:\Users\Anderson Sacani\Documents\Tibia Project 1291 - 740\Server\TibiaOtServerProject\data\scripts\movements\rookgaard\remove_bag_weapon.lua:callback]
timerEvent: []
callbackId:[]
function: []
error [...t\data\scripts\movements\rookgaard\remove_bag_weapon.lua:13: attempt to index a nil value
stack traceback:
[C]: in function '__index'
...t\data\scripts\movements\rookgaard\remove_bag_weapon.lua:13: in function <...t\data\scripts\movements\rookgaard\remove_bag_weapon.lua:3>]

Can someone help me?
 
Solution
I've tested, but i've the same problem :(
Lua:
local weaponsId = {
    3270, 3291, 3293,
}

local removeBagWeapon = MoveEvent()

function removeBagWeapon.onStepIn(creature, item, position, fromPosition)
    local player = Player(creature)
    if not player then
        return true
    end
  
    local weaponEquipped = true
  
    local slotItem = player:getSlotItem(CONST_SLOT_LEFT)
    if not slotItem then
        print("Player has no item equipped in that slot.")
        weaponEquipped = false
    end
  
    if slotItem and not table.contains(weaponsId, slotItem:getId()) then
        print("Player does not have any weapons listed in the table currently equipped in this slot.")
        weaponEquipped = false
    end
  
    if not...

dami1310

◄ Unidentified ►
Joined
Jan 27, 2013
Messages
697
Solutions
12
Reaction score
620
Location
Poland
Change to
Code:
if player:getSlotItem(CONST_SLOT_LEFT).id == 3270 then
or
Code:
if player:getSlotItem(CONST_SLOT_LEFT):getId() == 3270 then
 

dami1310

◄ Unidentified ►
Joined
Jan 27, 2013
Messages
697
Solutions
12
Reaction score
620
Location
Poland
Try this
Code:
local removeBagWeapon = MoveEvent()

function removeBagWeapon.onStepIn(creature, item, position, fromPosition)
    if not creature:isPlayer() then
        return true
    end
    
    local weaponsId = {
        3270, 3291, 3293,
    }
    
    if creature:getSlotItem(CONST_SLOT_LEFT):getId() == 3270 then
        Spdlog.info("1")
        return true
    end

    creature:teleportTo(fromPosition)
    creature:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You need to equip a weapon before pass.")
    return true
end

removeBagWeapon:type("stepin")
removeBagWeapon:id(870)
removeBagWeapon:register()
 
OP
OP
M

MorganaSacani

Member
Joined
Sep 20, 2022
Messages
59
Reaction score
18
Try this
Code:
local removeBagWeapon = MoveEvent()

function removeBagWeapon.onStepIn(creature, item, position, fromPosition)
    if not creature:isPlayer() then
        return true
    end
   
    local weaponsId = {
        3270, 3291, 3293,
    }
   
    if creature:getSlotItem(CONST_SLOT_LEFT):getId() == 3270 then
        Spdlog.info("1")
        return true
    end

    creature:teleportTo(fromPosition)
    creature:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You need to equip a weapon before pass.")
    return true
end

removeBagWeapon:type("stepin")
removeBagWeapon:id(870)
removeBagWeapon:register()

Now. If I equip the weapon on left hand then works without errors, but if I desequip then:
[2022-27-09 11:55:17.084] [error] Lua script error:
scriptInterface: [Scripts Interface]
scriptId: [C:\Users\Anderson Sacani\Documents\Tibia Project 1291 - 740\Server\TibiaOtServerProject\data\scripts\movements\rookgaard\remove_bag_weapon.lua:callback]
timerEvent: []
callbackId:[]
function: []
error [...t\data\scripts\movements\rookgaard\remove_bag_weapon.lua:12: attempt to index a nil value
stack traceback:
[C]: in function '__index'
...t\data\scripts\movements\rookgaard\remove_bag_weapon.lua:12: in function <...t\data\scripts\movements\rookgaard\remove_bag_weapon.lua:3>]
 

Xikini

I whore myself out for likes
Senator
Joined
Nov 17, 2010
Messages
6,245
Solutions
545
Reaction score
4,489
I've tested, but i've the same problem :(
Lua:
local weaponsId = {
    3270, 3291, 3293,
}

local removeBagWeapon = MoveEvent()

function removeBagWeapon.onStepIn(creature, item, position, fromPosition)
    local player = Player(creature)
    if not player then
        return true
    end
  
    local weaponEquipped = true
  
    local slotItem = player:getSlotItem(CONST_SLOT_LEFT)
    if not slotItem then
        print("Player has no item equipped in that slot.")
        weaponEquipped = false
    end
  
    if slotItem and not table.contains(weaponsId, slotItem:getId()) then
        print("Player does not have any weapons listed in the table currently equipped in this slot.")
        weaponEquipped = false
    end
  
    if not weaponEquipped then
        print("Player does not have a weapon equipped from the table, therefore is not allowed to pass.")
        player:teleportTo(fromPosition)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You need to equip a weapon before pass.")
        return true
    end
  
    print("Player has a weapon equipped from the table and is allowed to pass.")
    return true
end

removeBagWeapon:type("stepin")
removeBagWeapon:id(870)
removeBagWeapon:register()
 
Solution
OP
OP
M

MorganaSacani

Member
Joined
Sep 20, 2022
Messages
59
Reaction score
18
Lua:
local weaponsId = {
    3270, 3291, 3293,
}

local removeBagWeapon = MoveEvent()

function removeBagWeapon.onStepIn(creature, item, position, fromPosition)
    local player = Player(creature)
    if not player then
        return true
    end
 
    local weaponEquipped = true
 
    local slotItem = player:getSlotItem(CONST_SLOT_LEFT)
    if not slotItem then
        print("Player has no item equipped in that slot.")
        weaponEquipped = false
    end
 
    if slotItem and not table.contains(weaponsId, slotItem:getId()) then
        print("Player does not have any weapons listed in the table currently equipped in this slot.")
        weaponEquipped = false
    end
 
    if not weaponEquipped then
        print("Player does not have a weapon equipped from the table, therefore is not allowed to pass.")
        player:teleportTo(fromPosition)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You need to equip a weapon before pass.")
        return true
    end
 
    print("Player has a weapon equipped from the table and is allowed to pass.")
    return true
end

removeBagWeapon:type("stepin")
removeBagWeapon:id(870)
removeBagWeapon:register()
OMG, thx man!! Love u!!
 
Top