• 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+ How tf getSlotItem with self?

Mjmackan

Mapper ~ Writer
Premium User
Joined
Jul 18, 2009
Messages
1,424
Solutions
15
Reaction score
176
Location
Sweden
WADUUP?!

using tfs 1.3
Tried to use this in events/creature.lua.

Lua:
local backpack = self:getSlotItem(CONST_SLOT_AMMO)
local skillBoostCharm = backpack:getItemsById(10313)

if #skillBoostCharm > 1 then
print("yello")
end

For some reason it returns nil value on 'local backpack', I guess It was cause I used 'self' instead of 'player' so I added 'player' instead and added:
local player = Player(self) but it throws same error.
 
Solution
The item you are receiving from getSlotItem is not guaranteed to be container, it might even be nil, if there is no item in this slot. Also getItemsById does not exist in tfs 1.3, so idk if you are using unknown method or its your custom made?
Your self is not guaranteed to be player, to get item from slot, you need to check if its player otherwise it might return nil value error:
If self:isPlayer() then
 
Your self is not guaranteed to be player, to get item from slot, you need to check if its player otherwise it might return nil value error:
If self:isPlayer() then
Still getting same error.
Code:
Lua Script Error: [Event Interface]
data/events/scripts/creature.lua:Creature@onTargetCombat
data/events/scripts/creature.lua:11: attempt to index local 'backpack' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/events/scripts/creature.lua:11: in function <data/events/scripts/creature.lua:9>

This is how the script looks now:
Lua:
if self:isPlayer() then
local backpack = self:getSlotItem(CONST_SLOT_AMMO)
local skillBoostCharm = backpack:getItemsById(10313)

 if #skillBoostCharm > 1 then
print("yello")
 end
end
 
The item you are receiving from getSlotItem is not guaranteed to be container, it might even be nil, if there is no item in this slot. Also getItemsById does not exist in tfs 1.3, so idk if you are using unknown method or its your custom made?
 
Solution
The item you are receiving from getSlotItem is not guaranteed to be container, it might even be nil, if there is no item in this slot. Also getItemsById does not exist in tfs 1.3, so idk if you are using unknown method or its your custom made?
Lol, I did see my fault now, I didn't want to check any container. X))
This is what i wanted: print(self:getSlotItem(CONST_SLOT_AMMO).itemid)
 
Lol, I did see my fault now, I didn't want to check any container. X))
This is what i wanted: print(self:getSlotItem(CONST_SLOT_AMMO).itemid)
Make sure you check if the item is not nil before doing that, cause it will result in nil value error.
 
Back
Top