• 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
Joined
Jul 18, 2009
Messages
1,117
Solutions
2
Reaction score
68
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?

Nekiro

Legendary OT User
TFS Developer
Joined
Sep 7, 2015
Messages
2,417
Solutions
110
Reaction score
1,560
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
 
OP
Mjmackan

Mjmackan

Mapper ~ Writer
Joined
Jul 18, 2009
Messages
1,117
Solutions
2
Reaction score
68
Location
Sweden
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:[email protected]
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
 

Nekiro

Legendary OT User
TFS Developer
Joined
Sep 7, 2015
Messages
2,417
Solutions
110
Reaction score
1,560
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
OP
Mjmackan

Mjmackan

Mapper ~ Writer
Joined
Jul 18, 2009
Messages
1,117
Solutions
2
Reaction score
68
Location
Sweden
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)
 

Nekiro

Legendary OT User
TFS Developer
Joined
Sep 7, 2015
Messages
2,417
Solutions
110
Reaction score
1,560
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.
 
Top