Removing an ent

Hi, I recently made it so if a player pressed 1 for example it would switch to their primary, 2 for their secondary etc…

and now, with the tool gun in f2s stronghold, there is a translucent model of the object you selected, which shows you where you can place it, its fine, but say if the player switched to their primary/secondary, the translucent object would still be there floating so I was wondering what would be the best way to solve this.

some code I thought might be relevant:

function ENT:DrawTranslucent( bDontDrawModel )
	if ( bDontDrawModel ) then return end
	if (  LocalPlayer():GetEyeTrace().Entity == self.Entity and 
		  EyePos():Distance( self:GetPos() ) < 256 ) then
		self:DrawEntityOutline( 1.0 )


Call Holster clientside on the weapon before switching from it.

Thankyou, it seems I am getting there, but I am not really sure what to do next:

function SWEP:Holster( wep )
	if( pressed == true )then
	weapon = LocalPlayer():GetActiveWeapon():GetClass()


(pressed is defined above)

What the hell is that code?

Call SWEP:Holster( wep ) on client where SWEP is the old weapon and wep is the new weapon. Might need to use the net.library.

                                        if(ply:GetActiveWeapon():GetClass() == "weapon_sh_tool")then
                                            weapon_sh_tool:Holster( "tfa_acr" )

I get the error attempt to index global ‘weapon_sh_tool’ (a nil value) why is this?

Because weapon_sh_tool is not defined? Both weapons must be a WEAPON object, not a string or a random uninitialized variable.

I just made it print the players active weapon, and this is what was in my console:

Weapon [46][weapon_sh_tool]

So, should I use 46 or weapon_sh_tool?

You should use a weapon entity object, not a number or a string. - This is what you need.

What you printed out IS a weapon entity object.

[sp]If you still can’t piece it together, ply:GetActiveWeapon() returns a weapon object of the currently carried weapon. GetClass() returns a string that contains the class name of the weapon. “gmod_tool” for example, is a string that contains gmod_tool, a class name for sandbox Toolgun.[/sp]

this is the code I have so far:

if(ply:GetActiveWeapon():GetClass() == "weapon_sh_tool" )then
                                            weapon_sh_tool:Holster( tfa_acr ) --HERE I AM STILL GETTING ERROR

I am still getting the said error, im not sure why, as weapon_sh_tool is a valid weapon

weapon_sh_tool is a VARIABLE, it’s not a WEAPON.

You need a WEAPON, a VARIABLE that when printed will give the same output as ply:GetActiveWeapon(). If you print weapon_sh_tool you will not get “Weapon [46][weapon_sh_tool]”, you will get a “nil” or “no value”.

To give weapon_sh_tool a value of the weapon object, you gotta do variable = ply:GetActiveWeapon().

Stronghold breaks with every update because the gamemode uses a lot of older older functions

It sounds quite noobish of me, but I am really stuck now, so I was wondering whether you could write a quick bit of code to point me in the right direction

[editline]3rd September 2015[/editline]

with GetActiveWeapon() would the syntax be ply:GetActiveWeapon() == “weapon_sh_tool” or would it be ply:GetActiveWeapon(“weapon_sh_tool” or weapon_sh_tool)

See the wiki page:
As you can see it does not have any arguments.

You should really read/watch some Lua/programming tutorials before doing this.

I sure can write you the answer, but then you will just come back asking for more code. You gotta learn to find all the required information yourself.

Look, I am going to give you 50% of the answer.
ply:GetActiveWeapon():Holster( tfa_acr )

ply is your Player object. It is an Entity with a subclass “Player”
Player:GetActiveWeapon() is a function ( method ) that you can use on a Player object. It returns a Weapon objcet.
ply:GetActiveWeapon() is your Weapon object. It is an Entity with a subclass “Weapon”
Entity:GetClass() is a function ( method ) that you can use on any Entity object. it returns a string, a string is not an Entity.
weapon_sh_tool is a variable name, same as ply is a variable that contains the Player object, but the weapon_sh_tool variable doesn’t contain any data in it, not an entity or anything.

Hopefully this will help you.

ok, I have done lua before, but doing stuff like this is a bit different, I tried the following:

ply:GetActiveWeapon():GetClass():Holster( tfa_acr )
weapon_sh_tool:GetClass():ply:GetActiveWeapon():Holster( tfa_acr )

I am sorry for being annoyingly nooby, but this is a bit different to what im used to

[editline]3rd September 2015[/editline]

I am very desperate to get this done :slight_smile:

I have decided the best way to do it, is check if the weapon was switched (if key 1 was pressed etc) and then run


which is located in the lua files of each tool gun modes