Removing certain weapons on spawn?

I’m pretty new to Lua, and so I’m still confused about plenty of stuff. I’m a bit of a slow learner, but I’ve been making more of an effort to memorize and try things recently. I can do basic stuff, and I know how to use things such as hooks.

My problem is that I’m not sure how I can make it so that you don’t have certain weapons at first. So if you spawned you would not have, say, the crowbar and crossbow. I think it has something to do with in for loops and hooks, but I’m pretty confused as to how I could code it or what I need to use despite reading through the GMod wiki for anything that could help.

Thanks in advance if anyone can help me out here, and my apologies for sounding stupid. :confused:

Well, you could maybe strip all the weapons and then add some back using ply:Give(“weapon_rpg”) ?

Hm, didn’t think about it like that. I’ll see if I can make it work, but I’m not very hopeful.

Nope. Whatever I did, it didn’t work.

[lua]

local weaponstrip = function(ply)

ply:StripWeapons()
ply:Give(“weapon_shotgun”,“weapon_rpg”)
end

hook.Add(“PlayerSpawn”,“Weaponstrip”, weaponstrip)

[/lua]

I thought it would be something like that, but I’m probably making some huge and somewhat obvious mistake.
If anyone can tell me how to do this correctly, then I’ll appreciate it. :sigh:

I think it should be like this.
[lua]local weaponstrip = function(ply)

ply:StripWeapons()
ply:Give(“weapon_shotgun”)
ply:Give(“weapon_rpg”)
end

hook.Add(“PlayerSpawn”,“Weaponstrip”, weaponstrip)
[/lua]

[lua]
hook.Add(“PlayerLoadout”, “WeaponStrip”, function§
p:Give(“weapon_shotgun”);
p:Give(“weapon_rpg”);

return false;

end);
[/lua]

Thanks Seth, worked exactly how I wanted it to. Thanks guys! :buddy:

No problem, glad to help (:

Bit late but this should come in handy to clear the map.

[Lua]
AllowedWeps = {weapon_crowbar, weapon_rpg}

for k,v in pairs (ents.GetAll) do
for a,d in pairs (AllowedWeps) do
if (v != d) and v:IsWeapon() then
v:Remove()
end
end
end
[/Lua]

:wtc:

[lua]
local allowedweps = {“weapon_crowbar”, “weapon_rpg”};

for k, v in pairs(ents.GetAll()) do
if(!ValidEntity(v) || !table.HasValue(allowedweps, v:GetClass())) then
continue;
end

v:Remove();

end
[/lua]

Ah bitch.

I mean I was typing from my phone this morning so it is dodgy.
But yea, Im newbie at this shit.

Alright, I’ll have a look at that later. :smile:
Thanks!