DarkRP disallow player to carry more than one assault rifle

Hey,

I’m testing new things out. I’m currently inside the entity “spawned_weapon”
Trying to create a easy thing so people first of can not pickup the weapon they already have.

[LUA]
if self:GetClass(“weapon_m4”) and activator:HasWeapon(“weapon_m4”) then
return false
end
[/LUA]

However this code makes it when the player has a m4 he can not pickup any other weapon at all. how do I make it so the player is still able to pickup other weapons BUT the “weapon_m4”
From there I will be able to do things myself.

Thank you very much!


if activator:HasWeapon( self.weaponclass ) then
  return false
end

Would make it so that a player can’t pick up weapons they already have.

If you want it just for the m4, you can do:


if self.weaponclass == "weapon_m4" and activator:HasWeapon( self.weaponclass ) then

Would block picking up multiple M4s.

Alright nice.
But now if I would have “weapon_galil”, “weapon_m4”, “weapon_ak47” in my server. I only want the player to be able to carry one of these. NOT multiple.

How would I need to make it so it does this?



local assaults = { "weapon_galil", "weapon_m4", "weapon_ak47", "etc" }

--In the function

if table.HasValue( assaults, self.weaponclass ) then
  for k, v in ipairs( assaults ) do
    if activator:HasWeapon( v ) then
      return
    end
  end
end

There’s probably a better way to do it, but that’s the simple way.

That’s amazing!

I like things to be simple so thank you very much!