A Few Quick Questions

Thanks for your time in reading this.
I saw the picking up a weapon on use script in the gmod wiki:

But I am a little unsure where to put it.
I have tried lua/autorun and lua/aurtorun/server and in the individual code for a weapon but it doesn’t seem to make any difference.
I’d like to put this in a file which will make it apply to the whole server.

Secondly, I am wondering if it is possible to make a script which changes the weapons the player spawns with, eg if a convar is off then normal weapons, if it is on then a different set of weapons.
Thanks again for your time.

[lua]function playerRespawn( ply )



hook.Add( “PlayerSpawn”, “playerRespawnTest”, playerRespawn )[/lua]
In autorun/server

Thanks samwilki, does anyone have any idea how to do the first thing?

[lua]hook.Add( “PlayerSpawn”, “PickupTimeout”, function( ply )
ply.PickupTimeout = CurTime() + 0.5
end )

hook.Add(“PlayerCanPickupWeapon”, “Pickup”, function( ply, entity )
if ( ply.PickupTimeout or 0 ) > CurTime() then return true end
if ( ply.NextPickup or 0 ) > CurTime() then return false end

if ply:KeyDown( IN_USE ) then
	local tr = ply:GetEyeTrace()
	if ValidEntity( tr.Entity ) and tr.Entity:GetPos():Distance( ply:GetShootPos() ) < 92 and tr.Entity == entity then
		ply.NextPickup = CurTime() + 0.5
		return true
return false


Put that in autorun/server.


Bearing in mind that this will stop all other PlayerCanPickupWeapon hooks from running.

Thank you very much :slight_smile:


Hello again, I tried the code posted by samwilki, however it is not entireley working.
The function is getting called (I inserted a debug line to print to chat), however I recon that gMod is giving all of the weapons anyway, meaning that they all are there.
I have tried inserting ply:StripWeapons() in line 2 but that didn’t seem to make any difference.

Try this

hook.Add( “PlayerLoadout”, “gravAndShot”, function()
return true


The reason this would work is because he is returning a value, this will stop all other PlayerLoadout hooks from executing.

Unless I’m mistaken that actually wouldn’t work, because the anonymous function has no arguments, therefore ply is nil. It needs function(ply) rather than function().

Absolutely right.