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 )

				ply:Give("weapon_crowbar")
				ply:Give("weapon_physgun")
				ply:Give("weapon_smg1")
				ply:Give("weapon_pistol")
				ply:Give("weapon_rpg")
				ply:Give("weapon_physcannon")

end

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
	end
end
return false

end)[/lua]

Put that in autorun/server.

[editline]12:15PM[/editline]

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

Thank you very much :slight_smile:

[editline]02:11PM[/editline]

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

[lua]
hook.Add( “PlayerLoadout”, “gravAndShot”, function()
ply:Give(“weapon_crowbar”)
ply:Give(“weapon_physgun”)
ply:Give(“weapon_smg1”)
ply:Give(“weapon_pistol”)
ply:Give(“weapon_rpg”)
ply:Give(“weapon_physcannon”)
return true
end)

[/lua]

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

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.