SWEP Dropping

How can I make a SWEP not drop when its used and they die. Like the jihad. When it is used and they die how can I make it so that it doesn’t drop? But it does drop when you manually drop it.

Are you running DarkRP, that’s what I’m thinking from the description you posted. If so, you can look in one of the death hooks, search the files for ply:DropWeapon() and check if they’re holding the weapon you don’t want to drop.


I’m running TTT and it’s not that I don’t want them to drop it. I want it so when they use it and die, it doesn’t spawn. If you know what I mean. Like the jihad is supposed to have 1 use in it and it doesn’t spawn after it blows up.


I cba to go look through TTT’s code, but find where it’s dropping the weapon and check if the class is the jihad bomb then just don’t drop it.

But do you know the function to make it not drop? Because I tried making it not droppable but it still drops when the player dies. You see the jihad bomb explodes, killing the player and any one around them. And as you know weapons drop when you die, or atleast custom SWEP’s.

Look in weaponry.lua, edit the function WEPS.DropNotifiedWeapon to just return if the weapon is of a certain class.

replace the weapon dropping function with this
dontdropthis = { “jihad_bomb”, “weapon_physgun”, “weapon_physcannon”, “droopy_richard”, “trolololol” } //customize this to your liking

function GM:DoPlayerDeath(victim)
if victim:GetActiveWeapon():IsValid() and !table.HasValue( dontdropthis, victim:GetActiveWeapon():GetClass() ) then

There is absolutely no need for more than one line of code to solve this problem.
Open the code, and find the function where the explosion is created, and inside of that find the line that kills the player (which is self.Owner:kill()), and add self:Remove() right before that line.

Do not mark me “dumb”, because this solution actually works.

There is absolutely no need for less than 6 lines either.
Less isn’t always more.

TTT doesn’t work like that though, I went and looked at it. You could just add it into the actual weapon drop function which I pasted above.

[editline]10th March 2011[/editline]

function WEPS.DropNotifiedWeapon(ply, wep, death_drop)
if ValidEntity(ply) and ValidEntity(wep) then
if wep:GetClass() == “jihad_bomb” then return end
– Hack to tell the weapon it’s about to be dropped and should do what it
– must right now
if wep.PreDrop then

  -- PreDrop might destroy weapon
  if not IsValid(wep) then return end

  -- Tag this weapon as dropped, so that if it's a special weapon we do not
  -- auto-pickup when nearby.
  wep.IsDropped = true



  -- After dropping a weapon, always switch to holstered, so that traitors
  -- will never accidentally pull out a traitor weapon


This problem is already solved, no need to make it more complicated.
To v34: Dude, that simple line solves the problem completely. This is the exact code he was looking for, believe me.

Your way is stupid.

My way doesn’t require 19 lines of code to drop a gun.
Coding is better when it’s optimized. The less you code, the easier it’s to manipulate.

If he needed a complicated code to drop a weapon, your way would be better, but what he’s asking for is not 19 lines of code, he wants it as compact as possible.

I added one line of code to the TTT code that is already there. Your code removes the weapon before the player dies, he will drop another weapon that means.