• Limiting weapons on spawn
    21 replies, posted
Alright, lemme make myself a little bit clearer I want a lua script that will get rid of all weapons [b]when I spawn.[/b] Keep in mind, this is for singleplayer, so I can't just use an admin mod. It would be nice to make the script easy to edit, or better yet, and a derma panel in Utilities or Options that would make it editable in game. Would also be nice if it could get rid of ammo when I spawn as well, but I would just settle for weapons.
Two weeks - Anybody?
Bi weekly bump here. ;_;
[lua] local weapons = { "weapon_ak47", "weapon_ar2", "weapon_crowbar" } local ammo = { "Pistol" = 25, "AR2" = 1337, "SMG1" = 101 } hook.Add( "PlayerLoadout", "SetWeaponsOnSpawn", function( ply ) for k, v in pairs( weapons ) do ply:Give( v ) end for k, v in pairs( ammo ) do ply:GiveAmmo( v, k, true ) end return true end) [/lua] There is weapons list [url]http://wiki.garrysmod.com/?title=Player.Give[/url] and there ammo list [url]http://wiki.garrysmod.com/?title=Player.GiveAmmo[/url] Put it in [i]lua/autorun/server/[/i]
[url]http://wiki.garrysmod.com/?title=Player.StripWeapons[/url] [code]hook.Add("PlayerSpawn", "StripAll", function(ply) ply:StripWeapons() end )[/code]
[QUOTE=Skondra;15940977][url]http://wiki.garrysmod.com/?title=Player.StripWeapons[/url] [code]hook.Add("PlayerInitialSpawn", "StripAll", function(ply) ply:StripWeapons() end )[/code][/QUOTE] I'm sorry if I may have been a little unclear. I wanted it to strip CERTAIN weapons, not all, and then maybe give me new ones. But it doesn't matter, this has already been answered above you.
[QUOTE=DeathDoom;15943166]I'm sorry if I may have been a little unclear. I wanted it to strip CERTAIN weapons, not all, and then maybe give me new ones. But it doesn't matter, this has already been answered above you.[/QUOTE] [QUOTE=DeathDoom;15448393]Alright, lemme make myself a little bit clearer I want a lua script that will get rid of [b]all[/b] weapons [b]when I spawn.[/b] Keep in mind, this is for singleplayer, so I can't just use an admin mod. It would be nice to make the script easy to edit, or better yet, and a derma panel in Utilities or Options that would make it editable in game. Would also be nice if it could get rid of ammo when I spawn as well, but I would just settle for weapons.[/QUOTE] Just a little unclear, yes.
[QUOTE=Pecius;15940545][lua] local weapons = { "weapon_ak47", "weapon_ar2", "weapon_crowbar" } local ammo = { "Pistol" = 25, "AR2" = 1337, "SMG1" = 101 } hook.Add( "PlayerLoadout", "SetWeaponsOnSpawn", function( ply ) for k, v in pairs( weapons ) do ply:Give( v ) end for k, v in pairs( ammo ) do ply:GiveAmmo( v, k, true ) end return true end) [/lua] There is weapons list [url]http://wiki.garrysmod.com/?title=Player.Give[/url] and there ammo list [url]http://wiki.garrysmod.com/?title=Player.GiveAmmo[/url] Put it in [i]lua/autorun/server/[/i][/QUOTE] Doesn't work.
[lua]local weapons = { "weapon_physcannon", "weapon_physgun", "gmod_tool", "gmod_camera", } hook.Add("PlayerLoadout","RestrictWeapons",function(ply) for _,v in ipairs(weapons) do ply:Give(v) end return true end)[/lua]
[QUOTE=Jamie932;15961006][lua]local weapons = { "weapon_physcannon", "weapon_physgun", "gmod_tool", "gmod_camera", } hook.Add("PlayerLoadout","RestrictWeapons",function(ply) for _,v in ipairs(weapons) do ply:Give(v) end return true end)[/lua][/QUOTE] This man wins.
Incidentally if you want to just spawn with a physgun/toolgun/camera and nothing else in sandbox, you can do it in one line. [lua]CreateConVar("sbox_weapons",0,{ FCVAR_REPLICATED, FCVAR_ARCHIVE })[/lua] in any serverside autorun file.
[QUOTE=Lexic;16023661]Incidentally if you want to just spawn with a physgun/toolgun/camera and nothing else in sandbox, you can do it in one line. [lua]CreateConVar("sbox_weapons",0,{ FCVAR_REPLICATED, FCVAR_ARCHIVE })[/lua] in any serverside autorun file.[/QUOTE] Problem is, sbox_weapons does not do anything when I run it in console. I dunno if it will do it via lua, but hey. That, and I'd like to edit my spawn weapons, which sbox_weapons won't let me do.
[QUOTE=DeathDoom;16023766]Problem is, sbox_weapons does not do anything when I run it in console. I dunno if it will do it via lua, but hey.[/QUOTE] That's because Garry is an idiot. You have to create it first, with that code, then it works.
[QUOTE=DeathDoom;16023403]This man wins.[/QUOTE] Your welcome.
[QUOTE=Jamie932;15961006][lua]local weapons = { "weapon_physcannon", "weapon_physgun", "gmod_tool", "gmod_camera", } hook.Add("PlayerLoadout","RestrictWeapons",function(ply) for _,v in ipairs(weapons) do ply:Give(v) end return true end)[/lua][/QUOTE] hi bit of a noob here but was wondering where i put this my folders basicly go like this garrysmod/lua/autorun/client i then create a file called autorun.lua with this but i keep getting an error in gmod saying autorun/client/Autorun.lua:1: unexpected symbol near '1.'
Put it in lua/autorun/server/Autorun.lua
hi i did exactly what jamie said and im getting the exact same results i even reinstalled gmod but nope anyone know why? edit side not heres what the console says in full Lua initialized (Lua 5.1) autorun/client/Autorun.lua:1: unexpected symbol near '1.' Registering gamemode 'sandbox' derived from 'base' edit also just like to point out that i dont seem to have any problems when doing this at college seems to only go wrong when im at home dont see why tho has i stated ive reinstalled it at home, i even tryed the scripting written above to strip ALL weapons and that didnt work eithe, lua just doesnt seem to want to work on my home pc anyone got any suggestions?
Did you copy it directly from the lua tag and kept the hash signs? (#) These are not part of the script. If so next time click view plain first to get the actual code. Here's what you want to use : [code]local weapons = { "weapon_physcannon", "weapon_physgun", "gmod_tool", "gmod_camera", } hook.Add("PlayerLoadout","RestrictWeapons",function(ply) for _,v in ipairs(weapons) do ply:Give(v) end return true end)[/code]
[QUOTE=Crazy Quebec;18585265]Did you copy it directly from the lua tag and kept the hash signs? (#) These are not part of the script. If so next time click view plain first to get the actual code. Here's what you want to use : [code]local weapons = { "weapon_physcannon", "weapon_physgun", "gmod_tool", "gmod_camera", } hook.Add("PlayerLoadout","RestrictWeapons",function(ply) for _,v in ipairs(weapons) do ply:Give(v) end return true end)[/code][/QUOTE] BINGO absoulutely fantastic cheers mate
Yeah, before you copy and paste a code, at the top of the box, there should be a button called view plain. Click that and copy it.
[QUOTE=Jamie932;18586375]Yeah, before you copy and paste a code, at the top of the box, there should be a button called view plain. Click that and copy it.[/QUOTE] Sadly I can't use it because the Facepunch Ultimate Greasemonkey script breaks that for me. :frown: It's a bit annoying. :dance:
[QUOTE=Crazy Quebec;18586437]Sadly I can't use it because the Facepunch Ultimate Greasemonkey script breaks that for me. :frown: It's a bit annoying. :dance:[/QUOTE] Unfortunate. :3:
Sorry, you need to Log In to post a reply to this thread.