How can you remove a server sided entity on a client?

I am trying to remove some entities within a certain radius of another entity when someone presses a button.

Basically this is how the code looks:

//removes items in area and spawns item crafted
					for l,o in pairs(craft_items*[9]) do
						local num = craft_items*[9][l]
							for kk, vv in pairs(entina) do
								local count = 0
								//if table.HasValue(craft_items*[8][l], v) then
								if vv:GetClass() == craft_items*[8][l] then
									if count == num then

I thought about adding a console command, that would take the arguments and remove it, but I was a idiot and removed the player. :v:

function item_remove( ent )
concommand.Add( "item_remove", item_remove )

You can’t. You can only hide it, make invisible.

Do you have any idea as to what I can do? I was thinking about igniting it because I have set up the entities to remove themselves when they hit 0 HP but this might light everything else on fire. Could I teleport them outside of the map or something. xD

I also tried changing the owner to see if I could remove it but that did not work.

Why are you giving players the authority to delete any entity?

You cannot affect an entity from client, except for changing it’s color or overall rendering.
Explain what you are trying to do.

and prevent it
Basically I am trying to make it where a entity will not spawn until there are certain entities in range. I want to remove those other entities before it spawns the new one.

The reason this is client side is because I have a ton of different entities that need to be created depending on the ones near it. The user presses a vgui button to determine which entity they would like to make.

I am thinking about trying to put it all into one big file and use if CLIENT and if SERVER stuff. I would not like to do that though, because I have organized it the way I like it and fusing shared, cl_init, and init together would get hard to read.

Bit hard to understand what you’re trying to say; But I think your problem is you don’t know how to call server side code from the client.

You had the right idea about using concommands to call it, except that’s not exactly how they work.

function funcName (ply, cmd, args)
print(ply:Nick) --prints the name of the player who ran the console command
print(args[1]) – prints the first argument that was passed
concommand.Add(“example”, funcName)

– if you were to type “example test” into console
– funcName would print out your name, followed by ‘test’ as test was the first argument passed

Knowing that might help you figure out a solution to your problem.
Hint: the index of an entity is the same on the client and the server, so you can pass the ID number of an entity as an argument, then use that number to get the entity in the server side code.

The client should not work out what entities need to be removed. Never trust the client.
Just send the name of the button that the client pressed. Let the server work out where the client is, where the entities are, if the client is looking in the right direction, if the client is allowed to modify those entities, if the entities are right for that button and where to put the new entity. Treat every request as suspicious and dodgy requests won’t fuck up your server.

To be honest The only way I know how to send data from the client to the server is by console command. I feel that still gives players control over the entities. Like what would stop them from typing that command in console?

I guess I could take all of the code out of the button and then simply make the client send the table where the entity is, but again I still feel that completely defeats the purpose of having a entity doing it for the players.

What do people normally do when they are trying to prevent exploits?

Not trusting the client is generally the best solution.

[editline]30th November 2013[/editline]

And you might want to learn some proper networking methods.

No it doesn’t - the entity can still do it all for the players but it has to do it all on the server. Why would the client need to send the table where the entity is? The server knows where the player is and should work everything else out.
If the player pressed a button on the entity, then the player must be looking at the entity. Is the player looking at the right type of entity? If yes - you now have the entity and thus it’s positions etc. If not, assume they’re trying to screw with you and pretend they never said anything.

(PS It’s generally a bad idea to take retaliatory action like kicking the player for unexpected commands that a player shouldn’t have been able to send - they might be out of sync)

Thanks that was just what I was looking for. I did not know this even existed.

If anyone knows if this can still be exploited though please tell me.

Yep. If the client has a scriptenforcer bypass (or the server has sv_allowcslua 1) then you can run net messages almost as easily as you can concommands.

Look, the net library is nice but it’s not the universal solution to everything. In this situation a console command is perfectly fine, the only problem here is the fact that most of the checking is done on client while it should be done on the server. It’s fine to let the client ask for an entity to be removed, but the server has to make sure the client is allowed to remove that entity.

This is actually a good solution. When a player presses that button, simply send a console command to the server which tells it to look for all the entities that are going to be crafted, remove them, and then spawn the craft result. It’s the right way to do it.

[editline]30th November 2013[/editline]

More of a general tip than anything specifically related to the issue presented in the OP really.

Thanks guys I changed it around to use console commands.

To prevent players from randomly calling the command I made it check for the other entity, that allowed the crafting, and if it was not in range it would return false.

You cant use ply:RunConsoleCommand you need ConCommand if you only wants 1 to use it at same time.