I have searched and do not know of any lua plugin that does what I need to study it. I have a loop through players inventory looking for item name with x stack, when found, I would like to remove it from their inventory. This is where I am stuck, I find the item stack but can't remove it. Any help or guidance in the right direction is much appreciated. Thanks.
LUA: Remove item from inventory
Discussion in 'Rust Development' started by insane8472, Aug 23, 2015.
-
You should be able to call the method Remove on the item.
Code:public void Remove(float fTime) { if (this.removeTime <= 0f) { foreach (ItemMod mod in this.info.itemMods) { mod.OnRemove(this); } this.onCycle = null; this.removeTime = Time.time + fTime; this.OnDirty = null; this.position = -1; if (this.isServer) { ItemManager.RemoveItem(this, fTime); } } }
Code:... foundItem:Remove(0) ...
-
There was a second arg but i forgot it. It worked totally fine for me. -
Thanks for the replies. Laser's reply is the closest I have gotten to getting it working. Still not quite there yet. Do you still have the lua script you had working?
-
Below example will remove one stack of Wood from your inventory when you run /test.
Code:PLUGIN.Title = "Lua Tests" PLUGIN.Version = V(9, 9, 9) PLUGIN.Description = "Lua test plugin" PLUGIN.Author = "Mughisi"function PLUGIN:Init() command.AddChatCommand("test", self.Plugin, "cmdTest") endfunction PLUGIN:cmdTest( player, cmd, args ) local item = player.inventory:FindItemID(3655341) item:Remove(0) end
-
Thanks, I see what I did wrong. Trying to get the item id from the name instead of the id itself. The "0" in Remove, does this indicate the slot? Trying to remove a specific stack of x instead of a random stack. Thanks again.
Last edited by a moderator: Aug 23, 2015 -
I can recommend using a tool like .NET Reflector or Telerik JustDecompile to browse the Assembly-CSharp.dll to get to know the available fields, structs, methods, ... -
Thanks for all the help. I will check out the decompiled dll information.
-
[DOUBLEPOST=1440348826][/DOUBLEPOST] -
-
-
I just said it takes a List and not a single item ^^
-
-
Ok, I loop the inventory, find the stack with x amount of wood that I want to remove, but I cannot figure out even with the dll decompiled how to remove that stack. It still removes a random stack. Since they all have the same itemid, trying to compare the name returned "Item.woodx##..." is always the same. I know im probably missing someting simple.
-
-
I tried take but keep getting invalid arguments to method. I have the list, id and amount unless the list is wrong in some way.
-
-
Well, thats that. Thanks for the help.
[DOUBLEPOST=1440440837,1440412116][/DOUBLEPOST]How would I go about removing a blueprint? I can get the flags of items to determine if it is a blueprint but they have the same name and id as the item they provide.
[DOUBLEPOST=1440587793][/DOUBLEPOST]I have tried all I know or what could possibly work. I can get the position of a BP, but how do I remove it? Is it possible to remove a specific slot? I know X amount can be removed and items once found with an itemid, but they have the same ids.