Replace HL2 guns with Custom guns (Lua)

Hi!
It would be awesome if there was a script that allowed you to replace valves standard HL2 weapons that yo get when you spawn with custom guns. Simply a script that allows you to set which sweps people get when they respawn instead of the normal HL2 weapons.
Thanks.

For Sandbox? That already exists.

garrysmod\garrysmod\gamemodes\sandbox\gamemode\init.lua

Find this: (it’s near the top of the script, you won’t have to scroll much)

[lua]/---------------------------------------------------------
Name: gamemode:PlayerLoadout()
---------------------------------------------------------
/
function GM:PlayerLoadout( pl )

// Remove any old ammo
pl:RemoveAllAmmo()

if ( server_settings.Bool( "sbox_weapons", true ) ) then

	pl:GiveAmmo( 256,	"Pistol", 		true )
	pl:GiveAmmo( 256,	"SMG1", 		true )
	pl:GiveAmmo( 5,		"grenade", 		true )
	pl:GiveAmmo( 64,	"Buckshot", 	true )
	pl:GiveAmmo( 32,	"357", 			true )
	pl:GiveAmmo( 32,	"XBowBolt", 	true )
	pl:GiveAmmo( 6,		"AR2AltFire", 	true )
	pl:GiveAmmo( 100,	"AR2", 			true )
	
	
	pl:Give( "weapon_crowbar" )
	pl:Give( "weapon_pistol" )
	pl:Give( "weapon_smg1" )
	pl:Give( "weapon_frag" )
	pl:Give( "weapon_physcannon" )
	pl:Give( "weapon_crossbow" )
	pl:Give( "weapon_shotgun" )
	pl:Give( "weapon_357" )
	pl:Give( "weapon_rpg" )
	pl:Give( "weapon_ar2" )
	
	// The only reason I'm leaving this out is because
	// I don't want to add too many weapons to the first
	// row because that's where the gravgun is.
	//pl:Give( "weapon_stunstick" )

end

pl:Give( "gmod_tool" )
pl:Give( "gmod_camera" )
pl:Give( "weapon_physgun" )

local cl_defaultweapon = pl:GetInfo( "cl_defaultweapon" )

if ( pl:HasWeapon( cl_defaultweapon )  ) then
	pl:SelectWeapon( cl_defaultweapon ) 
end

end[/lua]

Change the names of the weapons and boom, you’re done.

Amazing thank you very much. I appreciate yor help more than you think.
Outstanding didn’t see that the soltion was that close. :open_mouth: I am greatful for you Kung Fu Jew.

No problem.

Doesn’t work. I Noticed that the man sandbox gamemode’s files can’t be modified.

Modify this to your wishes then put it in lua/autorun/server/myweapons.lua.
Do not use this on any gamemode other than sandbox, or you will break it.
[lua]hook.Add(“PlayerLoadout”,“MyWeapons”,function(pl)
// Remove any old ammo
pl:RemoveAllAmmo()

if ( server_settings.Bool( "sbox_weapons", true ) ) then

	pl:GiveAmmo( 256,	"Pistol", 		true )
	pl:GiveAmmo( 256,	"SMG1", 		true )
	pl:GiveAmmo( 5,		"grenade", 		true )
	pl:GiveAmmo( 64,	"Buckshot", 	true )
	pl:GiveAmmo( 32,	"357", 			true )
	pl:GiveAmmo( 32,	"XBowBolt", 	true )
	pl:GiveAmmo( 6,		"AR2AltFire", 	true )
	pl:GiveAmmo( 100,	"AR2", 			true )
	
	
	pl:Give( "weapon_crowbar" )
	pl:Give( "weapon_pistol" )
	pl:Give( "weapon_smg1" )
	pl:Give( "weapon_frag" )
	pl:Give( "weapon_physcannon" )
	pl:Give( "weapon_crossbow" )
	pl:Give( "weapon_shotgun" )
	pl:Give( "weapon_357" )
	pl:Give( "weapon_rpg" )
	pl:Give( "weapon_ar2" )
	
	// The only reason I'm leaving this out is because
	// I don't want to add too many weapons to the first
	// row because that's where the gravgun is.
	//pl:Give( "weapon_stunstick" )

end

pl:Give( "gmod_tool" )
pl:Give( "gmod_camera" )
pl:Give( "weapon_physgun" )

local cl_defaultweapon = pl:GetInfo( "cl_defaultweapon" )

if ( pl:HasWeapon( cl_defaultweapon )  ) then
	pl:SelectWeapon( cl_defaultweapon ) 
end
return true

end)[/lua]

Thank you. I’ll try it out right away. I was wonderngif it was possible to rip a code and place it aloneto the autorun place.

[editline]08:36PM[/editline]

HAHA! THANK YOU LEXIC! This time it worked! Awesome!