Freezing weapons at their spawn location and disallowing picking up a weapon of same type (per slot)?

Hey FP. I’m kind of lost with this issue and I’m fairly new to Lua. I’m trying to mimic CS:S physics and gameplay for numerous Fretta gamemodes.

First issue: When a round starts, all the weapons on the map are affected by physics like gravity, and fall from their place midair. I don’t believe this is the issue with HL2 weapons though, but only custom ones. Supposingly, I’m missing the piece of code from the weapons that disables this behaviour and freezes the weapons at their spawn location. This is the intended behaviour I’d like to have, as it’s not pretty to have a ton of guns falling on ground instead of being organized nicely on the shelf. “phys_timescale 0” won’t do, I still need to have proper physics.

I ended up with something like this:

[LUA]for k,v in pairs(ents.GetAll()) do
if v:IsWeapon() then
local phys = v:GetPhysicsObject()
if phys and phys:IsValid() then

Only need to hook it somewhere (OnPreRoundStart). Tried it inside GM:OnPreRoundStart in one gamemode, but that didn’t seem to work.

Second issue: Let’s take an example. We have a primary weapon, an AWP. We can still pickup any other primary weapon (in same slot) like Scout or AK47, and carry multiple weapons. Okay, we can disallow people picking up multiple weapons of the same type with this:

[LUA]function GM:PlayerCanPickupWeapon(ply,wep)
return !ply:HasWeapon(wep:GetClass())

which may also cause some issues with ammunition, but seems better though. If we have an AWP, we cannot pickup another AWP this way. However, we can still pickup any other primary weapon like AK47 once, and carry both AK47 and AWP. I’d only like to carry one weapon at the time (plus the melee weapon + pistol).

Would a table with all primary weapon names (and another table with secondary weapons) work, or as “HasPrimaryWeapon = true” check somewhere work?

tl;dr: Freeze entities/weapons in mid air on spawn and disable picking up multiple weapons in same slot.

Any help is appreciated. Cheers!

For Issue 2, The easiest way would just be to copy the structure from Dark RP’s spawned_weapon. Have an entity that holds the classname of the gun to add. Set the model fo the spawned_weapon to the model of the classname. In the ENT:Use hook, just check if the player already has the weapon. If not, add it and add a bit of ammo, if so, simply return.

Thanks, but my issue #1 still seems without an clue. Obviously, they are constrained in the map, but Garry’s Mod doesn’t obey this unlike CS:S obviously (different code for weapons). Also, I’m not a fan of DarkRP.

I also looked how Deathrun and TTT do it, it gave me a bit of more idea on it, but I’d still appricate more help on this.

You could try grabbing the weapons .Slot var if its a SWEP, C++ Coded weapons (Half-Life 2) do not have .Slot vars, So you’ll have to check for that.

Possibly something like this when the player is trying to pick up a weapon?

function _R.Player:HasWeaponSlot(num)

local WeaponsFound = 0

for _,v in pairs (self:GetWeapons()) do

if v.Slot and v.Slot == num then

WeaponsFound = WeaponsFound + 1



return WeaponsFound > 0

- This would go into the PickUpWeapon hook, Or whatever its called these days.

if IsValid(WEP) and WEP.Slot and WEP.Slot and self:HasWeaponSlot(WEP.Slot) then
-- Hey, you already have a weapon taking up this slot!
return false end

I only just drafted this up, So my apologies if it doesnt work straight up.

Thanks, I’ll take a look later. Definetly need to create something to drop the gun first too, which should be relatively easier (I hope). Still looking to constrain the SWEPs in maps with Lua.

Update: Came up with a draft something like this for weapon slots. Still has bugs and lots to improve. Thanks to Flora!

I’m probably going to create a new weapon base anyway.

[LUA]-- Weapon tables
local CSSPrimaryWeapons = {

local CSSSecondaryWeapons = {

– Unused table
local CSSUndroppableWeapons = {

– Weapon slot check
function _R.Entity:IsPrimaryWeapon()
if table.HasValue(CSSPrimaryWeapons,self:GetClass()) then
return true
return false

function _R.Entity:IsSecondaryWeapon()
if table.HasValue(CSSSecondaryWeapons,self:GetClass()) then
return true
return false

function _R.Player:HasCSSPrimary()
local primarywp = 0

for i,v in pairs(self:GetWeapons()) do
	if table.HasValue(CSSPrimaryWeapons,v:GetClass()) then
		primarywp = primarywp + 1

return primarywp >= 1


function _R.Player:HasCSSSecondary()
local secondarywp = 0

for i,v in pairs(self:GetWeapons()) do
	if table.HasValue(CSSSecondaryWeapons,v:GetClass()) then
		secondarywp = secondarywp + 1

return secondarywp >= 1


function PickupStopper(ply, wep)
if IsValid(wep) then
if wep:IsPrimaryWeapon() and ply:HasCSSPrimary() then
return false
elseif wep:IsSecondaryWeapon() and ply:HasCSSSecondary() then
return false

– Drop weapon
function DropCurrentWeapon(ply)
local Currentweapon = ply:GetActiveWeapon()

local NewWeapon = ents.Create(Currentweapon:GetClass())

local currentweaponclip1 = Currentweapon:Clip1()
local currentweaponclip2 = Currentweapon:Clip2()


NewWeapon:SetPos(ply:GetShootPos() + (ply:GetAimVector() * 30))

ply.AllowWeaponPickupFix = 0





function PickupDelayFunc(ply)
ply.AllowWeaponPickupFix = 1

– Weapon drop commands
if SERVER then

function AutoBindOnSpawn(ply)
ply.AllowWeaponPickupFix = 1
–ply:ConCommand("bind g DropWeapon

function RePickupFix(ply,weapon)
if ply.AllowWeaponPickupFix == 0 then return false end

Now, only to constraint weapons which are not obeying the map flags… I believe Deathrun has the solution for me in this (although, it loops through all weapons and replaces them with one, HL2 smg (which obeys the flag anyway?)).