Jump to content

How does one modify an inventory item on the server?


multox

Recommended Posts

I'm having trouble writing a change to an item in a player's inventory on the server.  Although I've found the object and changed the property that I want changed nothing appears different.  I suspect that I'm missing a key step but not sure what.  Any hints?

 

function onMarkTrashPressedServer(enabledMaterials, selectedRarities)
if onClient() then return end

local itemsMarked = 0
local inv = Player(callingPlayer):getInventory():getItems()

    for index, slotItem in pairs(inv) do
        local iitem = slotItem.item
        if ((iitem == nil) or iitem.trash or iitem.favorite) then goto continue end

        local item = SellableInventoryItem(iitem, index, buyer)
	local name = Rarity(item.rarity.value).name .. " " .. Material(item:getMaterial()).name .. " " ..item:getName()
	local material = Material(item:getMaterial()).value
	local rarity = Rarity(item.rarity.value).value

	if (enabledMaterials[material]) then
		local selectedMaxRarity = selectedRarities[material]
		if (rarity <= selectedMaxRarity) then
			--print("Trashing " .. name)
			iitem.trash = 1
			inv[index] = iitem  ???? <---- What needs to be done here to save the trash change?
			itemsMarked = itemsMarked + 1
		end
	end

        ::continue::
    end

Player(callingPlayer):sendChatMessage("Server", 0, itemsMarked .. " items have been marked as trash.")
end

Link to comment
Share on other sites

you need to remove/add to the inventory object not the item object.

 


local inv = Player(callingPlayer):getInventory()

for index, slotItem in pairs(inv:getItems()) do
  local iitem = slotItem.item
  inv:remove(index)
  iitem.trash = 1
  slotItem.item = iitem
  inv:add(slotItem,index)
end

 

Untested, but this should help yopu get close to what ya want to achieve

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...