DarkRP Weapon drop restrictions

I don’t code lua, I know C# though, can you tell me what is wrong with this? What I’m trying to accomplish is… If the weapon is not a buyable weapon in the DarkRP gamemode then don’t drop it on death. This is to stop the physgun, gravity gun, camera, and tool gun from dropping on death, I found these to be ugly to drop, also, if an admin spawns a weapon and is killed, it doesn’t drop their weapon unless it is a weapon that can be bought ingame.

New conditional function I added, returns true if weapon is droppable and false if the weapon is not droppable --------------

[lua]
–Check if the weapon is buyable and is not an admin weapon, allow it to drop.
function GM:CanDropWeapon(ply, weapon)
if tobool(GetConVarNumber(“restrictdrop”)) then
for k,v in pairs(CustomShipments) do – WAIT! I think CustomShipments doesn’t exist, even though the game doesn’t consider it a nil thing? I don’t see a CustomShipments array in the lua file. Is there a way to get the CustomShipments for DarkRP?
if v.entity == weapon:GetClass() then
if weapon:GetClass() ~= “weapon_real_cs_admin_weapon” then
return true
else
return false
end
end
end
else
return true
end
end
[/lua]

Modified DarkRP function.

[lua]
function GM:DoPlayerDeath(ply, attacker, dmginfo, …)
if tobool(GetConVarNumber(“dropweapondeath”)) and ValidEntity(ply:GetActiveWeapon()) then
if GM:CanDropWeapon(ply, ply:GetActiveWeapon()) then – This is a new line.
ply:DropWeapon(ply:GetActiveWeapon())
end – and the closing block.
end
ply:CreateRagdoll()
ply:AddDeaths( 1 )
if ValidEntity(attacker) and attacker:IsPlayer() then
if attacker == ply then
attacker:AddFrags(-1)
else
attacker:AddFrags(1)
end
end
end

[/lua]
Any help is appreciated.

Hello good sir,

We have a questions sub-forum located at: http://www.facepunch.com/forums/337
Please post any Garrysmod Lua related questions in that subforum.
We also have a subforum for requests, if you would like to request this to be made.

Thank you.

Instead of

[lua]if GM:CanDropWeapon(ply, ply:GetActiveWeapon()) then[/lua]

Do

[lua]if gamemode.Call( “CanDropWeapon”, ply, ply:GetActiveWeapon()) then[/lua]

Thanks! This fixed my problem! :smiley: