• Fixing weapon autopickup
    6 replies, posted
In garrys mod after a weapon has be spawned, if you walk close to it, you pick it up, or gain ammo if you're already holding the weapon. How would I work around this from happening? I want the player to have to press E to pick it up instead of walking over it.
I haven't tested this but you could try to use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/PlayerCanPickupWeapon]GM:PlayerCanPickupWeapon[/url] and [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Player/KeyPressed]Player:KeyPressed[/url]. If you don't have the use key down then just return false.
[QUOTE=bigdogmat;50572145]I haven't tested this but you could try to use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/PlayerCanPickupWeapon]GM:PlayerCanPickupWeapon[/url] and [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Player/KeyPressed]Player:KeyPressed[/url]. If you don't have the use key down then just return false.[/QUOTE] Ah duh, why didn't I think of this. Thank you. [editline]23rd June 2016[/editline] Tested this, it works in some sense, but when spawning in, it won't give the loadout weapons. I can't give myself weapons directly from the Q menu. Any alternatives?
Maybe check if the weapon has a physics object? I think weapons only have physics objects when they're spawned as a prop (such as they are when they're on the ground) - I might be wrong though
[QUOTE=MPan1;50572877]Maybe check if the weapon has a physics object? I think weapons only have physics objects when they're spawned as a prop (such as they are when they're on the ground) - I might be wrong though[/QUOTE] I'm sorry but how would you do that?
[CODE] if IsValid( someweapon:GetPhysicsObject() ) then [/CODE] [editline]23rd June 2016[/editline] So pretty much [CODE] hook.Add( 'PlayerCanPickupWeapon', 'test', function( ply, wep ) if IsValid( wep:GetPhysicsObject() ) and ( !ply:KeyPressed( IN_USE ) ) then return false end end ) [/CODE] [editline]23rd June 2016[/editline] Actually, I just tested that and some weapons in the spawnmenu have physics objects so this doesn't work :(
[QUOTE=MPan1;50572937][CODE] if IsValid( someweapon:GetPhysicsObject() ) then [/CODE] [editline]23rd June 2016[/editline] So pretty much [CODE] hook.Add( 'PlayerCanPickupWeapon', 'test', function( ply, wep ) if IsValid( wep:GetPhysicsObject() ) and ( !ply:KeyPressed( IN_USE ) ) then return false end end ) [/CODE] [editline]23rd June 2016[/editline] Actually, I just tested that and some weapons in the spawnmenu have physics objects so this doesn't work :([/QUOTE] For future reference, GetPhysicsObject will always return an entity or NULL PHYSICS OBJECT, so you can use the metamethod and not the global. [editline]23rd June 2016[/editline] [QUOTE=dannyf127;50572209]Ah duh, why didn't I think of this. Thank you. [editline]23rd June 2016[/editline] Tested this, it works in some sense, but when spawning in, it won't give the loadout weapons. I can't give myself weapons directly from the Q menu. Any alternatives?[/QUOTE] In OnEntityCreated, you could set a variable on a weapon that would allow them to pick it up one second after spawning, then in a timer, set the variable to false. That means weapons spawned from the spawn menu can be picked up since they are avaliable immidiately.
Sorry, you need to Log In to post a reply to this thread.