expert975 Posted October 25, 2015 Share Posted October 25, 2015 (edited) How do I remove an entity?For instance, an item from a player's inventory. How do I kill it? Maybe just teleport it to somewhere far?Inventory:RemoveItem() seems to teleport it to 0,0,0, wich may happen to be on the middle of the land.What I really need to do is get an item from one player's inventory and copy it to the other(I guess I would need to create a new item entity with the same stats, like spoilage or uses left, but how to do that?), then delete it from my own inventory, leaving the original item should be intact. Thoughts:-What happens to a carrot when you eat it? Where does it go?-Birds fly up and disapear, looks like they are destroyed when they do this.-When a tool break, where does it go to? I wonder one could not teleport all broken axes to a hidden place. Any tips on messing with item entities and general entities? Thanks. Edited October 25, 2015 by expert975 Link to comment Share on other sites More sharing options...
fluffyNest Posted October 25, 2015 Share Posted October 25, 2015 (edited) inst:Remove()?But probably not. Edited October 25, 2015 by fluffyNest Link to comment Share on other sites More sharing options...
expert975 Posted October 25, 2015 Author Share Posted October 25, 2015 inst:Remove() seems to delete the entity propertly. Now how do I create a new entity with the same stats as an existing one? Example: Carrot, 50% spoilage. Link to comment Share on other sites More sharing options...
fluffyNest Posted October 25, 2015 Share Posted October 25, 2015 (edited) we do have inst.prefab, Just create new item before destroing the old. for usages there is finiteuses.SetUses and finiteuses.GetUses. Take a look at this component.Also there is probably some method to move item from one inventory to another. Edited October 25, 2015 by fluffyNest Link to comment Share on other sites More sharing options...
DarkXero Posted October 25, 2015 Share Posted October 25, 2015 (edited) -What happens to a carrot when you eat it? Where does it go?ACTIONS.EAT.fn = function(act) -- to act.doer.components.eater:Eat(obj)endfunction Eater:Eat(food) if food:IsValid() then --might get removed in OnEaten... if not self.eatwholestack and food.components.stackable ~= nil then food.components.stackable:Get():Remove() else food:Remove() end endendIt gets removed. -Birds fly up and disapear, looks like they are destroyed when they do this. State{ name = "flyaway", tags = {"flying", "busy"}, timeline = { TimeEvent(2, function(inst) inst:Remove() end) } },It gets removed up and away. -When a tool break, where does it go to? I wonder one could not teleport all broken axes to a hidden place. I assume by tool you mean a prefab that has the tool component and the finite uses component. When the finite uses component reaches 0 because of the tool component consuming it, the onfinished function gets executed.In the axe, this isinst.components.finiteuses:SetOnFinished(inst.Remove)Again, removed. If you don't save in variables the data you want, then when you spawn a new prefab, you can't put that data on it. Alternative methods:inst:Hide()inst:Show()makes stuff disappear and reappear. Also, there's a GIVETOPLAYER action.You can work with that. Edited October 25, 2015 by DarkXero Link to comment Share on other sites More sharing options...
fluffyNest Posted October 25, 2015 Share Posted October 25, 2015 (edited) inventory.lua its holds alot about transferring.there is Inventory:RemoveItem(item, wholestack) that is removeFromInventory and returns this item.there is Inventory:GiveItem(item) that taking item into inventory. About carrot... I have not idea what is this.It's probably 'perishable' try look into 'perishable.lua' there is a lot of functions.And call it as component of your item. Edited October 25, 2015 by fluffyNest Link to comment Share on other sites More sharing options...
expert975 Posted October 25, 2015 Author Share Posted October 25, 2015 (edited) Its something like this:For each item on the player's one inventory, make one item of the same type and the same stats on player's two inventory.It's meant to be just visual, I don't need to use the axe on a tree, I just need to see it there on the same slot that player one sees.Do I need to compare every visual component of every item? Item moisture, durability, spoilage... Edited October 25, 2015 by expert975 Link to comment Share on other sites More sharing options...
DarkXero Posted October 25, 2015 Share Posted October 25, 2015 So you want an admin to see the inventory of somebody else? Link to comment Share on other sites More sharing options...
fluffyNest Posted October 26, 2015 Share Posted October 26, 2015 (edited) expert975, quick look into the code don't gives any results for 'copy' function. So yes you need to compare(you mean copy?) every component unique parameters. Just a tip about syntax that may help. Inventory.lua contains 'Inventory:TransferInventory(receiver)'function Inventory:TransferInventory(receiver) if not receiver.components.inventory then return end local inv = receiver.components.inventory for k,v in pairs(self.itemslots) do inv:GiveItem(self:RemoveItemBySlot(k)) endendDarkXero, inspecting inventory? Interesting. I'm first thought about some "evil clone" of the player.That will stand in the shadows and saying such things as - "IwillKillyou", "Where is my leg?" or something else lol Edited October 26, 2015 by fluffyNest Link to comment Share on other sites More sharing options...
expert975 Posted October 28, 2015 Author Share Posted October 28, 2015 DarkXero, its an spectator function. Link to comment Share on other sites More sharing options...
Mobbstar Posted October 28, 2015 Share Posted October 28, 2015 Why don't you hax a bit and tell the item tile to diplay that item, rather than making a dummy item? I know for a fact that two inventory instances can refer to the same entity (don't ask how I managed that, no idea). Link to comment Share on other sites More sharing options...
expert975 Posted October 28, 2015 Author Share Posted October 28, 2015 That would be ideal. The problem is how... Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now