• Removing an ent
    14 replies, posted
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: [code] 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 ) end self:Draw() end [/code]
Call Holster clientside on the weapon before switching from it.
[QUOTE=Robotboy655;48606482]Call Holster clientside on the weapon before switching from it.[/QUOTE] Thankyou, it seems I am getting there, but I am not really sure what to do next: [code] function SWEP:Holster( wep ) if( pressed == true )then weapon = LocalPlayer():GetActiveWeapon():GetClass() end end [/code] (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.
[QUOTE=Robotboy655;48606670]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.[/QUOTE] [code] if(ply:GetActiveWeapon():GetClass() == "weapon_sh_tool")then weapon_sh_tool:Holster( "tfa_acr" ) end [/code] 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.
[QUOTE=Robotboy655;48606858]Because weapon_sh_tool is not defined? Both weapons must be a WEAPON object, not a string or a random uninitialized variable.[/QUOTE] 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. [url]http://wiki.garrysmod.com/page/string[/url] [url]http://wiki.garrysmod.com/page/number[/url] [url]http://wiki.garrysmod.com/page/Entity[/url] - 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]
[QUOTE=Robotboy655;48606979]You should use a weapon entity object, not a number or a string. [url]http://wiki.garrysmod.com/page/string[/url] [url]http://wiki.garrysmod.com/page/number[/url] [url]http://wiki.garrysmod.com/page/Entity[/url] - 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][/QUOTE] this is the code I have so far: [code] if(ply:GetActiveWeapon():GetClass() == "weapon_sh_tool" )then weapon_sh_tool:Holster( tfa_acr ) --HERE I AM STILL GETTING ERROR end [/code] 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().
[QUOTE=Robotboy655;48606670]What the hell is that code? [/QUOTE] Stronghold breaks with every update because the gamemode uses a lot of older older functions
[QUOTE=Robotboy655;48607182]... 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().[/QUOTE] 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] [QUOTE=Robotboy655;48607182]... 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().[/QUOTE] 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: [url]http://wiki.garrysmod.com/page/Player/GetActiveWeapon[/url] As you can see it does not have any arguments. You should really read/watch some Lua/programming tutorials before doing this. [url]http://facepunch.com/showthread.php?t=1250283[/url] 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.
[QUOTE=Robotboy655;48607756]See the wiki page: [url]http://wiki.garrysmod.com/page/Player/GetActiveWeapon[/url] As you can see it does not have any arguments. You should really read/watch some Lua/programming tutorials before doing this. [url]http://facepunch.com/showthread.php?t=1250283[/url] 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.[/QUOTE] ok, I have done lua before, but doing stuff like this is a bit different, I tried the following: [code] ply:GetActiveWeapon():GetClass():Holster( tfa_acr ) weapon_sh_tool:GetClass():ply:GetActiveWeapon():Holster( tfa_acr ) [/code] I am sorry for being annoyingly nooby, but this is a bit different to what im used to [editline]3rd September 2015[/editline] [QUOTE=Mattymoo14211;48608187]ok, I have done lua before, but doing stuff like this is a bit different, I tried the following: [code] ply:GetActiveWeapon():GetClass():Holster( tfa_acr ) weapon_sh_tool:GetClass():ply:GetActiveWeapon():Holster( tfa_acr ) [/code] I am sorry for being annoyingly nooby, but this is a bit different to what im used to[/QUOTE] I am very desperate to get this done :)
[QUOTE=Robotboy655;48607756]See the wiki page: [url]http://wiki.garrysmod.com/page/Player/GetActiveWeapon[/url] As you can see it does not have any arguments. You should really read/watch some Lua/programming tutorials before doing this. [url]http://facepunch.com/showthread.php?t=1250283[/url] 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.[/QUOTE] 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 [code] self.GhostEntity:Remove() [/code] which is located in the lua files of each tool gun modes
Sorry, you need to Log In to post a reply to this thread.