• Remove entity without spawning it with code
    14 replies, posted
Hi, I recently decided to make a simple little test addon to get better at it. I decided to make a present addon where you have a present, and when you open it it spawns a random entity. The problem is that it spawns lots of items (because you hold the use button down), I realized I could solve it by having the present dissapear after opening, but i cant figure out how, I've looked for a while and haven't found one that I understood. (Keep in mind, I have no previous lua experience) Here's my opening function: function Open() local SpawnableEntities =  {  "item_ammo_357", "item_ammo_357_large", "item_ammo_ar2" } local pl = player.GetByID( 1 ) local PlyLookDir = pl:GetTable() local EntityToSpawn = SpawnableEntities[ math.random( #SpawnableEntities ) ] SpawnFunction( pl, PlyLookDir, EntityToSpawn ) --This is where i want to remove the entity-- return end Again i have no previous lua experience so apologies if my code is bad :P
Take a look at these 2 wiki pages: Entity/SetUseType Entity/Remove Next time please do at least try to search on the wiki before making a thread.
Well I've seen the ent/remove one but again, i have no previous lua experience, and there were no examples (that i understood) that explained how i would put it into my code
Does SpawnFunction return the spawned entity?
Yes
Call Remove on the return in your Open function.
How exactly?
SpawnFunction( pl, PlyLookDir, EntityToSpawn ):Remove()
That removed the spawned object
You cannot with how you setup your Open function - you aren't passing any other entity.
Okay, but how would I set it up so i can do it? I assume I have to give it some argument when I call it right?
Yes.
Are the paramaters in the ENT:Use function (Which is where i call it from) useful (activator and caller)?
If it's an ENT: function, you can access the entity being used with the "self" variable.
It works now, thank you very much
Sorry, you need to Log In to post a reply to this thread.