Take Damage Sound for DarkRP

Hey,

  • I’m looking for a simple code that creates a sound when a player takes damage.

If you can help me, Thank you very much!

Regards, Ryan Stealth

Should the sound only be heard by the player or to all players nearby?

Everyone nearby :slight_smile:

Sorry for not metioning!

[LUA]
hook.Add(“EntityTakeDamage”, “SoundOnDamage”, function(target, dmginfo)
if (target:IsPlayer()) then
sound.Play(“sound.wav”, target:GetPos())
end
end)
[/LUA]

Replace “sound.wav” with your chosen sound.

[editline]26th June 2013[/editline]

This is a serverside hook btw.

Thank you very much!

I maybe have a few more things that I also need help with.
But I don’t want to make multiple threads on the forums.

- How to make it so a player drops a weapon on death.
But only the weapons as in firearms, can be only one but also multiple. He should not drop stuff like toolgun or physgun.

This is what I have but does not do as I’d want it.
[LUA]hook.Add(“DoPlayerDeath”, “DropWeapon”, function(ply)
local wep = ply:GetActiveWeapon()
if (wep:IsValid()) then
ply:DropWeapon(wep)
end
end)
[/LUA]

- I have breathing in my view (See codes to understand “I’m sh*t at explaining”)
But I want it NOT to breath swinging when having physgun or toolgun out (so people can build)

These are my codes now.
[LUA]
function LowHealthSway(UCMD)

–if LocalPlayer():GetActiveWeapon() == “keys” then

if !LocalPlayer():Alive() then return end

UCMD:SetViewAngles((UCMD:GetViewAngles() + Angle(math.sin(RealTime()*1.3) * 0.009, math.sin(RealTime()*0.6) * 0.008, 0)))
end
hook.Add(“CreateMove”, “LowHealthSway”, LowHealthSway)
[/LUA]

  1. Assuming you are using DarkRP:

[LUA]
function GM:DoPlayerDeath(ply, attacker, dmginfo, …)
for _,weapon in pairs(ply:GetWeapons()) do
local canDrop = hook.Call(“CanDropWeapon”, self, ply, weapon)

	if GAMEMODE.Config.dropweapondeath and IsValid(weapon) and canDrop then
		ply:DropDRPWeapon(weapon)
	end
end
self.BaseClass:DoPlayerDeath(ply, attacker, dmginfo, ...)

end
[/LUA]

To enable, set GAMEMODE.Config.dropweapondeath to true.
To restrict weapons, check out GAMEMODE.Config.DisallowDrop.

[LUA]
function LowHealthSway(UCMD)
if !LocalPlayer():Alive() then return end

local class = LocalPlayer():GetActiveWeapon():GetClass()
if class == "weapon_physgun" or class == "gmod_tool" then return end

UCMD:SetViewAngles((UCMD:GetViewAngles() + Angle(math.sin(RealTime()*1.3) * 0.009, math.sin(RealTime()*0.6) * 0.008, 0)))

end
hook.Add(“CreateMove”, “LowHealthSway”, LowHealthSway)
[/LUA]

Hey Bo98.

Thank you for putting so much effort in helping me, I very much appreciate it!
**

  1. I do not have that config since I have a older version (I’m not updating YET since I coded very much inside my gamemode)
    But it also did not seem to do what I want. (I’d like it to drop all the weapon he may carry “If he has a mac10 equiped but also a mp5 but not equiped” I’d like him to drop both)**

2) Was perfect (Thank you!)

Which config? The DisallowDrop one?

Yes, The “GAMEMODE.Config.DisallowDrop”

[LUA]
function GM:DoPlayerDeath(ply, attacker, dmginfo, …)
local disallowDrop = {
[“weapon_physgun”] = true,
[“weapon_physcannon”] = true, --gravity gun
[“weapon_keypadchecker”] = true,
[“weaponchecker”] = true,
[“keys”] = true,
[“pocket”] = true,
[“gmod_tool”] = true,
[“gmod_camera”] = true,
[“arrest_stick”] = true,
[“unarrest_stick”] = true,
[“stunstick”] = true,
[“door_ram”] = true,
[“med_kit”] = true,
[“weapon_bugbait”] = true,
[“lockpick”] = true
}
for _,weapon in pairs(ply:GetWeapons()) do
if GAMEMODE.Config.dropweapondeath and IsValid(weapon) and disallowDrop[weapon:GetClass()] then
ply:DropDRPWeapon(weapon)
end
end
self.BaseClass:DoPlayerDeath(ply, attacker, dmginfo, …)
end
[/LUA]

Hey,

I found a lua error for the swinging view.
[LUA]
function LowHealthSway(UCMD)

if LocalPlayer():GetActiveWeapon():GetClass() == "weapon_physgun" then return end
if LocalPlayer():GetActiveWeapon():GetClass() == "gmod_tool" then return end

if !LocalPlayer():Alive() then return end

UCMD:SetViewAngles((UCMD:GetViewAngles() + Angle(math.sin(RealTime()*1.3) * 0.009, math.sin(RealTime()*0.6) * 0.008, 0)))

end
hook.Add(“CreateMove”, “LowHealthSway”, LowHealthSway)
[/LUA]

[ERROR] gamemodes/darkrp/gamemode/client/vision.lua:5: Tried to use a NULL entity!

  1. GetClass - [C]:-1
  2. fn - gamemodes/darkrp/gamemode/client/vision.lua:5
    3. unknown - addons/ulib/lua/ulib/shared/hook.lua:183

Line 5 =
[LUA]
if LocalPlayer():GetActiveWeapon():GetClass() == “weapon_physgun” then return end
[/LUA]

This should fix the error:

[LUA]
if IsValid (LocalPlayer():GetActiveWeapon()) and (LocalPlayer():GetActiveWeapon():GetClass() == “weapon_physgun” or LocalPlayer():GetActiveWeapon():GetClass() == “gmod_tool”) then return end
[/LUA]

Just add a IsValid check for LocalPlayer():GetActiveWeapon()

Hey Bo98.

Thank you very much once again that fixed it.

I seem to have some problems with the weapon drop addon.
[LUA]
function GM:DoPlayerDeath(ply, attacker, dmginfo, …)
local disallowDrop = {
“weapon_physgun” = true,
“weapon_physcannon” = true,
“gmod_camera” = true,
“gmod_tool” = true,
“stunstick” = true,
“keys” = true,
“lockpick” = true
}
for _,weapon in pairs(ply:GetWeapons()) do
if GAMEMODE.Config.dropweapondeath and IsValid(weapon) and disallowDrop[weapon:GetClass()] then
ply:DropDRPWeapon(weapon)
end
end
self.BaseClass:DoPlayerDeath(ply, attacker, dmginfo, …)
end
[/LUA]

[ERROR] gamemodes/darkrp/gamemode/server/player.lua:25: ‘}’ expected (to close ‘{’ at line 24) near ‘=’

  1. unknown - gamemodes/darkrp/gamemode/server/player.lua:0

Line 24 and 25 are
[LUA]
local disallowDrop = {
“weapon_physgun” = true,
[/LUA]

Whoops

[LUA]
local disallowDrop = {
[“weapon_physgun”] = true,
[“weapon_physcannon”] = true,
[“gmod_camera”] = true,
[“gmod_tool”] = true,
[“stunstick”] = true,
[“keys”] = true,
[“lockpick”] = true
}
[/LUA]

Thank you so much Bo98.

You helped me out so much <3