Closed Flatlander57 closed 11 years ago
try(depending on what you need): getPlayerSlotItem(cid, slot).uid getPlayerSlotItem(cid, slot).itemid getPlayerSlotItem(cid, slot).actionid
and it's player:getSlotItem(slot) btw
using . instead of : will return nil, because it will try to search it as table entry instead of method registered in luascript.cpp
Faith2531, the function returns an Item userdata, so you cannot use those. You need to use the proper Item methods: https://github.com/EvanMC/forgottenserver/wiki/Metatable:-Item
:getId() = itemid :getActionId() = actionid :getUniqueId() = uniqueid
I've done testing with getSlotItem, it seems to be bugged. It's been crashing the server for me, no matter how I use it. So, I'd wait for Mark or Dalkon.
Can you post example scripts that cause crash/returns nil when it shouldn't?
It's working fine for me with these examples:
local player = Player(cid)
local item = player:getSlotItem(CONST_SLOT_ARMOR)
if item ~= nil then
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "Result: " .. item:getId())
else
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "Result: no armor")
end
and
local item = getPlayerSlotItem(cid, CONST_SLOT_ARMOR)
if item.uid ~= 0 then
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "Result: " .. item.itemid)
else
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "Result: no armor")
end
I actually have no idea why this happens, but the function Player.getSlotItem will always return nil.
I added errors that output to the console, and it looks like it cannot find "player".
Example: Player.getSlotItem(cid, 1), whether there is an item in that slot or not, it will return nil and will output my error "Cannot find player" to console That I added in the source.