Jump to content

Remove items from player's inventory


TungstenX

Recommended Posts

Good day,

I'm trying to "drop" all items in the player's inventory. The issue that I'm facing now is that the items are on the floor, the player's inventory shows empty but the attachment/equip dot is shown and you have to unequip the item before you can wear it. Also, the items are still shown on the player's model (as well as the floor).

 

This is the current iteration of my code:

    local container = player:getInventory()
    player:dropHandItems() -- works well
    local items = container:getItems()
    for i = 0, items:size() -1, 1
    do
      local item = items:get(i)
      currentSquare:AddWorldInventoryItem(item, 0, 0, 0) -- Put on floor
      
      if item:isEquipped() then
        -- unequip
        player:removeAttachedItem(item)
      else
        player:getInventory():DoRemoveItem(item) -- :clear() didn't work
      end      
    end

 

1. Is my approach correct? (I can't find a "drop" function)

2. How do I unequip (clothing, bags, etc) and remove item from the player's inventory

3. How do I remove non-wearing items such as water bottles, etc.

Edited by TungstenX
Adding a line of code for clarity
Link to comment
Share on other sites

  • 2 weeks later...
Posted (edited)

Here is how the function evolved so far: (There was a glitch and the stuff that was on the floor wasn't there when I started the game again - thus this must be verified carefully)

Currently I'm calling this method via a context menu to speed up the testing

 

function UndressAll(x, y, z)
  local player = getPlayer()
  local container = player:getInventory()
  local currentSquare = getSquare(x, y, z) 
  local items = container:getItems()
  
  player:dropHandItems()
  -- Worn items
  local wornItems = player:getWornItems()    
  local size = wornItems:size()
  for i = 0, size - 1, 1
  do
    local wItem = wornItems:get(0)
    if wItem ~= nil then
      local item = wItem:getItem()
      currentSquare:AddWorldInventoryItem(item, 0, 0, 0)
      player:removeWornItem(item)
      container:Remove(item)      
      wornItems:remove(item)
    end
  end
    
  items = container:getItems()
  size = items:size()  
  for i = 0, size - 1, 1
  do
    local item = items:get(0)
    if item ~= nil then
      local itemDisplayName = item:getDisplayName()
      currentSquare:AddWorldInventoryItem(item, 0, 0, 0)
      container:Remove(item)
    end
  end
end

 

Is this correct?

Is there a better way to do this?

Edited by TungstenX
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...