Ammo Control - a few weapon/ammo plugin ideas

1) The weapons NPCs drop when they die shouldn’t be able to be picked up by the player. When the player picks up a gun, he should collect a magazine’s worth of ammo from the weapon (pistol - 18, SMG - 45, shotgun - 6, AR2 - 30), but the weapon should not be picked up. You could even have the weapon deleted from the inventory, if that’s easier.

2) You shouldn’t be able to pick up any weapon without pressing E on it. Sometimes I build armories and people run in not knowing what it is and pick up every single thing and feel guilty. All weapons should have to be used before they can be picked up.

3) Players should drop their weapon when they die. If possible, it should only be picked up with the amount of ammo it had left in the magazine upon the player’s death.

I hope for all these plugins to be in the same script, but if it’s easier, three separate ones is okay.


function WeponAmmoThink()
	for k, player in pairs(player.GetAll()) do
		local forremove = {"weapon_smg1","weapon_ar2","weapon_frag","weapon_357","weapon_slam","weapon_pistol","weapon_crossbow","weapon_shotgun"}
		for k, wepname in pairs(forremove) do
			local wepon = player:GetWeapon(wepname)
			if wepon!=NULL then
				player:GiveAmmo(wepon:Clip1(),wepon:GetPrimaryAmmoType());
				player:GiveAmmo(wepon:Clip2(),wepon:GetSecondaryAmmoType());
				player:StripWeapon(wepname)
			end
		end
	end
end
hook.Add("Think", "WeponAmmoThink", WeponAmmoThink)

Goes in Autorun/server/whateveryouwantz.lua
thats so when you pickup a half life 2 weapon or as you said “Npc weapons” wich is usually hl2… makes you collect the mag, not the gun.


if ( CLIENT ) then return end

local function PlayerCanPickupWeapon( ply, weap )
	if ( CurTime() <= ( ply.UseWeaponSpawn or 0 ) ) then return end
	if ( !ply:KeyDown( IN_USE ) ) then return false end
	local trace = util.QuickTrace( ply:GetShootPos(), ply:GetAimVector() * 8192, ply )
	if ( !trace.Entity || !trace.Entity:IsValid() || trace.Entity != weap ) then
		return false
	end
end
hook.Add( "PlayerCanPickupWeapon", "UseWeapon", PlayerCanPickupWeapon )

local function PlayerSpawn( ply )
	ply.UseWeaponSpawn = CurTime()
end
hook.Add( "PlayerSpawn", "UseWeapon", PlayerSpawn )

goes in autorun i think, stops players picking up weps without pressing Use on them.

For the drop weapon on die then you could just code that into the gamemode, or swep itself. Have fun

Awesome Zoeh.3

Cheers ^^

Wow… wow! Very nice.

Thanks a lot!