Jump to content

Remove Entity


Recommended Posts

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 by expert975
Link to comment
Share on other sites

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 by fluffyNest
Link to comment
Share on other sites

-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	endend

It 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 is

inst.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 by DarkXero
Link to comment
Share on other sites

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 by fluffyNest
Link to comment
Share on other sites

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 by expert975
Link to comment
Share on other sites

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))    endend

DarkXero, 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 by fluffyNest
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
 Share

×
  • Create New...