• Pickup Weapon if user presses E on it
    7 replies, posted
Hello, I have recently downloaded the script gas grenades off of the steam workshop and extracted it using GMad extractor. I am currently editing the code. Currently, when I spawn the weapon and walk over it, it is automatically picked up by the player. I want to change this so that when the player presses E on the gas grenade, it will pick it up. Any ideas of how to go about doing this? I imagine I would have to implement Player:PickupObject() somewhere. The Player:PickupObject() command does not have a range capacity to it, is there any way I can add a range capacity? ie. So I can't pick up the item from the other side of the map. Any help is greatly appreciated, thank you for your time.
[url]http://wiki.garrysmod.com/page/GM/PlayerCanPickupWeapon[/url] You can override that to check if they used it by setting a variable on the player right after it's used, then resetting it after like half a second.
[QUOTE=code_gs;50128452][url]http://wiki.garrysmod.com/page/GM/PlayerCanPickupWeapon[/url] You can override that to check if they used it by setting a variable on the player right after it's used, then resetting it after like half a second.[/QUOTE] Hmm, but how would I stop the player from picking it up automatically? I understand that function, I will take it into effect!
[QUOTE=Cosmo51;50128496]Hmm, but how would I stop the player from picking it up automatically? I understand that function, I will take it into effect![/QUOTE] return false if the player doesn't have the use variable set.
[QUOTE=code_gs;50128545]return false if the player doesn't have the use variable set.[/QUOTE] Where would I find the use variable? I dont think I have it, how would I set it? Sorry man, I'm not very good at lua... I'm trying to get better though, very thankful for people like you willing to help :)
[QUOTE=Cosmo51;50128586]Where would I find the use variable? I dont think I have it, how would I set it? Sorry man, I'm not very good at lua... I'm trying to get better though, very thankful for people like you willing to help :)[/QUOTE] You could try something like this: [code]local elipson = 0.1 local lasttime = CurTime() hook.Add( "StartCommand", "CheckUse", function( ply, cmd ) if ( cmd:KeyDown( IN_USE )) then ply.Used = true ply.UsedEnt = ply:GetEyeTrace().Entity lasttime = CurTime() + 0.1 elseif ( lasttime <= CurTime() ) ply.Used = false end end )[/code] Now, all you have to do is check if ply.Used is true in the hook provided above and that the weapon matches ply.UsedEnt. If so, allow pickup.
[QUOTE=code_gs;50128906]You could try something like this: [code]local elipson = 0.1 local lasttime = CurTime() hook.Add( "StartCommand", "CheckUse", function( ply, cmd ) if ( cmd:KeyDown( IN_USE )) then ply.Used = true ply.UsedEnt = ply:GetEyeTrace().Entity lasttime = CurTime() + 0.1 elseif ( lasttime <= CurTime() ) ply.Used = false end end )[/code] Now, all you have to do is check if ply.Used is true in the hook provided above and that the weapon matches ply.UsedEnt. If so, allow pickup.[/QUOTE] well, it still would automaticly pick the gun up if you're close enough when returning true again, even if you don't aim at it.
[QUOTE=whitestar;50130207]well, it still would automaticly pick the gun up if you're close enough when returning true again, even if you don't aim at it.[/QUOTE] By like a 0.1 second margin, he can lower the elipson if he wants
Sorry, you need to Log In to post a reply to this thread.