View Full Version : How to Use GetItemByPos ?

12-23-2013, 12:21 PM
local newItem = player:GetItemByPos(x, y)
local itembagcount = newItem:GetCount()
local itembagid = newItem:GetEntry()
local itembagname = newItem:GetName()
Tried this to get an Item in Bag of Player tried with x= -1;0;1;18;19;20;21;22 (Found multiple Variables for the Main Bag) and y= 0;1 (first slot in Bag) but the console says it gives a nil value... So how can i use the function to get an Item Entry from the Item on first slot of first bag for e.g. remove it from bag or add it to a vendor sell list?

thx for help again :D

12-23-2013, 01:09 PM
:GetItemByPos(bag, slot) - Returns item in given slot in a bag (bag: 19-22 slot : 0-35) or inventory (bag: -1 slot : 0-38)

bag = -1 for inventory and backpack, 19-22 other bags
slots 0-18 equipment
slots 19-22 bags
slots 23-38 backpack
slots 0-35 other bags

As per core description :)

12-23-2013, 01:21 PM
I Know, i said i tried that all and every time i get the same error: attempt to call method getitembypos a nil value
but i dont know whats wrong

12-23-2013, 01:27 PM
Link your script please, when you get that it's attempting to call a method and you get a nil value, it means that the method is not used on the correct object, or the method does not exist.

12-23-2013, 01:41 PM
function On_Select(event, player, unit, sender, intid, code)
local newItem = player:GetItemByPos(-1, 23)
local itembagcount = newItem:GetCount()
local itembagid = newItem:GetEntry()
local itembagname = newItem:GetName()

if (intid == 1) then
player:SendBroadcastMessage("This is your Item: "..itembagname.." ")
player:AddItem(itembagid, itembagcount)

RegisterGameObjectGossipEvent(950001, 2, On_Select)

Its not the full script but its the core essence of the script at this moment

12-23-2013, 01:54 PM
Just tested this on the both the mangos and the trinity branch, works as intended. Is your source old (before the latest large update?) http://prntscr.com/2ddfj5

12-23-2013, 02:23 PM
Use GetInventoryItem(slot) or GetBagItem(bag, slot) if you have old core.

slots are the same as described and the bag argument as well, except GetInventoryItem is used for -1 bagslot (inventory)

12-23-2013, 10:25 PM
thx alot, after an update all works fine... not perfect but fine, so thread can be closed