How to remove an entity when a Derma button is pressed?
11 replies, posted
Hey, Its me again. I know I am basically banished from these forums, but this, I really have a problem with.
So, Basically, I have a DButton that I want to remove all of the players ship entities.
That might be confusing so let me explain:
I have a menu that allows someone to spawn in a Star Wars ship, But you can't remove them with 'Z', so I have a button in that same derma frame, and I need it to remove all of that player (the player that pressed the button)'s spawnFighter entities, I have sat here for hours. Here is the segment of code that I'm talking about.
local spawnFighter = ents.Create ("tie_fighter")
spawnFighter:SetPos( ply:GetEyeTrace().HitPos )
spawnFighter:Spawn()
spawnFighter:CPPISetOwner(ply)
spawnFighter.Owner = ply
spawnFighter.OwnerID = ply:SteamID()
net.Receive("rs", function(ply)
SafeRemoveEntity(spawnFighter)
end)
Now obviously I have a net.Receive on this, its not just out there.
In this case, when any player presses the DButton, the last spawned 'spawnFighter' is removed. After that, you can't remove any others, But that's not the main issue, I just want it to remove the player that pressed the button's spawnFighter entity (As there is going to be a 1 spawnFighter limit)
Please be helpful, and don't bash me in. I know that I'm stupid.
Thank you to anyone that attempts to help me
Ent:Remove ?
Just don't do
local spawnFighter = ents.Create("tie_fighter")
instead do
ply.spawnFighter = ents.Create("tie_fighter")
and for removing
ply.spawnFighter:Remove()
Are you trying to see whether a player has spawned it before or not? Can't you just use ent:CPPIGetOwner()? So, you'd write the entity using net.WriteEntity( spawnFighter ) (unless it's already on the serverside) then do
if ply == ent:CPPIGetOwner() then ent:Remove() end
I'm going to assume you are running that server-side. It gives me an error when I try to spawn the ship:
[ERROR] addons/customentityspawner/lua/autorun/shared.lua:31: attempt to index global 'spawnFighter' (a nil value)
1. func - addons/customentityspawner/lua/autorun/shared.lua:31
2. unknown - lua/includes/extensions/net.lua:32
Erm, Not exactly, I just need the entity to be removed when the player presses a DButton.
Right, derma things run client side. You'll need to use the net library to send a message to the server when the player presses the button. Then use the Remove function on the server.
Okay, Might wanna update you: So when a player spawns a ship, and presses the button, the ship gets removed, However when the player presses the button again (Because there is a limit, another ship will not be spawned), The remove button ceases to function :< I think its because once another ship is spawned, it no longer sees it as a spawnFighter entity, rather as something different (maybe "tie_fighter" because that's the entity's true name)
Bugs man. Hate them.
Still not following you. Perhaps you need a table to keep track of a player's multiple entities?
Yeah, You would have to help me with that one, I never have and never will understand them. And I'm too lazy to go and learn them. If need be, I'll send a video showing you what's going on.
I'm sure there are plenty of people happy to help you understand tables, but if you're "too lazy" to learn them, then you shouldn't be asking people to do it for you. In my opinion, you cannot be considered a capable programmer of a modern language without an understanding of tables, so definitely read up on that or pay somebody to make what you want.
Well, the point is: I've gone out and watched and read all of the tutorials I could find, and I still don't understand them. Tables are the one thing I cannot learn.
Sorry, you need to Log In to post a reply to this thread.