I think the code is
gameevent.Listen( "player_hurt" )
hook.Add( "player_hurt", "player_hurt_example", function( data )
local health = data.health // Remaining health after injury
local priority = SERVER and data.Priority or 5 // Priority ??
local id = data.userid // Same as Player:UserID()
local attackerid = data.attacker // Same as Player:UserID() but it's the attacker id.
// Called when the player is injured or dies.
end )
I want it to play a sound file i selected when i damage an other player but im not sure how to do it.
Look at the EntityTakeDamage hook, rather than what you've got above which may be harder for you to read
[QUOTE=NiandraLades;49347200]Look at the EntityTakeDamage hook, rather than what you've got above which may be harder for you to read[/QUOTE]
I don't see how i could play a sound file with that?
You could do this a couple ways.
I would suggest using a combination of [URL="https://wiki.garrysmod.com/page/surface/PlaySound"]surface.PlaySound()[/URL] with [URL="https://wiki.garrysmod.com/page/Player/SendLua"]Player:SendLua()[/URL] like so.
[CODE]ply:SendLua("surface.PlaySound('ENTER WAV FILE HERE')") -- this will play a sound on the players client[/CODE]
You could also use [URL="https://wiki.garrysmod.com/page/Entity/EmitSound"]Entity:EmitSound()[/URL] if you want the sound to come from the player so others can hear it.
[QUOTE=boxvader;49347584]You could do this a couple ways.
I would suggest using a combination of [URL="https://wiki.garrysmod.com/page/surface/PlaySound"]surface.PlaySound()[/URL] with [URL="https://wiki.garrysmod.com/page/Player/SendLua"]Player:SendLua()[/URL] like so.
[CODE]ply:SendLua("surface.PlaySound('ENTER WAV FILE HERE')") -- this will play a sound on the players client[/CODE]
You could also use [URL="https://wiki.garrysmod.com/page/Entity/EmitSound"]Entity:EmitSound()[/URL] if you want the sound to come from the player so others can hear it.[/QUOTE]
[ERROR] external:9: attempt to index global 'ply' (a nil value)
Did you put this into a hook? ply is not an automatically defined value in gmod. How are you deciding what player to run this code on?
Have you done what box is saying?
[QUOTE=boxvader;49347872]Did you put this into a hook? ply is not an automatically defined value in gmod. How are you deciding what player to run this code on?[/QUOTE]
I have it playing sound when i load up the file, but i would also like there to be a .wav played when i damage an other player
So you will need to put this in a hook. [URL="https://wiki.garrysmod.com/page/GM/PlayerHurt"]PlayerHurt()[/URL] should work for you.
[CODE]
hook.Add("PlayerHurt","SoundOnDamage", function(ply)
-- Insert code above here
end
[/CODE]
--snip--
[QUOTE=Stalinalive;49347956]do something like this
[code]
if SERVER then
AddCSLuaFile()
util.AddNetworkString("DmgSound")
hook.Add("PlayerHurt", "DamageSound", function( victim, attacker )
if !IsValid(ply) then return end
net.Start("DmgSoundd")
net.Send(ply)
end)
net.Receive("DmgSoundd", function(len, ply)
surface.PlaySound("sound_path")
end)
end
[/code][/QUOTE]
That's completely unecessary plus you have stuff that makes no sense. If the file is running the server why are you trying to include a client side file? Second you are trying to receive data on the server which is client side only. You also don't even need to use the net library for this at all.
All you need is this it will work perfectly fine without all that useless code you are including.
[CODE]
hook.Add("PlayerHurt","SoundOnDamage", function(ply)
ply:SendLua("surface.PlaySound('ENTER WAV FILE HERE')")
end)
[/CODE]
Cheats are often a way people start learning to code. I have nothing against him writting a cheat projects are a great way to improve your coding skills. This is a developer discussion he did not ask to create a hack he simply asked how to play sounds on player damage what he does past that I could care less.
[QUOTE=boxvader;49347930]So you will need to put this in a hook. [URL="https://wiki.garrysmod.com/page/GM/PlayerHurt"]PlayerHurt()[/URL] should work for you.
[CODE]
hook.Add("PlayerHurt","SoundOnDamage", function(ply)
-- Insert code above here
end
[/CODE][/QUOTE]
surface.PlaySound( "hidden/rousheebot.mp3" ) --Play on start-up
hook.Add("PlayerHurt","SoundOnDamage", function(ply)
-- Insert code above here
end
not sure what to do here? also got this error - [ERROR] external:24: ')' expected (to close '(' at line 11) near 'local'
[QUOTE=Riley_;49348028]surface.PlaySound( "hidden/rousheebot.mp3" ) --Play on start-up
hook.Add("PlayerHurt","SoundOnDamage", function(ply)
-- Insert code above here
end
not sure what to do here? also got this error - [ERROR] external:24: ')' expected (to close '(' at line 11) near 'local'[/QUOTE]
[CODE]
hook.Add("PlayerHurt","SoundOnDamage", function(ply)
ply:SendLua("surface.PlaySound('hidden/rousheebot.mp3')")
end)
[/CODE]
There use that
[QUOTE=boxvader;49348037]
[code]
hook.Add("PlayerHurt","SoundOnDamage", function(ply)
-- Insert code above here
end
[/code]
not sure what to do here? also got this error - [ERROR] external:24: ')' expected (to close '(' at line 11) near 'local'[/QUOTE]
instead use what box said
[code]
hook.Add("PlayerHurt","SoundOnDamage", function(ply)
ply:SendLua("surface.PlaySound('hidden/rousheebot.mp3')")
end)
[/code]
[QUOTE=boxvader;49348037][CODE]
hook.Add("PlayerHurt","SoundOnDamage", function(ply)
ply:SendLua("surface.PlaySound('hidden/rousheebot.mp3')")
end)
[/CODE]
There use that[/QUOTE]
Its not playing the sound no error just no sound
hook.Add("PlayerHurt","SoundOnDamage", function(ply)
ply:SendLua("surface.PlaySound('hidden/hitsound.mp3')")
end)
That's probably because you added the sound wrong or you included the wrong sound path there isn't much we can do to help you with that.
[QUOTE=Riley_;49348074]Its not playing the sound no error just no sound
hook.Add("PlayerHurt","SoundOnDamage", function(ply)
ply:SendLua("surface.PlaySound('hidden/hitsound.mp3')")
end)[/QUOTE]
How are you loading your files?
[QUOTE=Kevlon;49348108]How are you loading your files?[/QUOTE]
Executing a lua file, surface.PlaySound( "hidden/rousheebot.mp3" ) --Play on start-up is working
The other one isn't
[QUOTE=Riley_;49348142]Executing a lua file, surface.PlaySound( "hidden/rousheebot.mp3" ) --Play on start-up is working
The other one isn't[/QUOTE]
Define executing
[QUOTE=Riley_;49348167]lua_openscript_cl sounds.lua[/QUOTE]
Are you sure?
[QUOTE=Kevlon;49348202]Are you sure?[/QUOTE]
Yes.
Why are you all using SendLUA?
function GM:PlayerHurt( victim, attacker )
if ( attacker:IsPlayer() ) then
victim:EmitSound("SoundPath/Here.wav")
end
end
or
hook.Add("PlayerHurt","EmitDmg",function(ply)
if ( attacker:IsPlayer() ) then
victim:EmitSound("SoundPath/Here.wav")
end
end
[url]https://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index8f77.html[/url]
[QUOTE=D3NNYM41C01M;49348519]Why are you all using SendLUA?
function GM:PlayerHurt( victim, attacker )
if ( attacker:IsPlayer() ) then
victim:EmitSound("SoundPath/Here.wav")
end
end
or
hook.Add("PlayerHurt","EmitDmg",function(ply)
if ( attacker:IsPlayer() ) then
victim:EmitSound("SoundPath/Here.wav")
end
end
[url]https://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index8f77.html[/url][/QUOTE]
[ERROR] external:20: ')' expected (to close '(' at line 11) near 'local'
Riley_ PM me your steam name if you want to work it out there because this thread's just confusing
[CODE]
gameevent.Listen("player_hurt")
hook.Add("player_hurt", "PlayHitSound", function(hitData)
if (hitData.attacker == LocalPlayer():UserID()) then
surface.PlaySound("coolsound")
end
end
[/CODE]
pretty sure this works
edit:
the op is using something on mpgh to load his scripts
[QUOTE=Im-Friendly;49351656][CODE]
gameevent.Listen("player_hurt")
hook.Add("player_hurt", "PlayHitSound", function(hitData)
if (hitData.attacker == LocalPlayer():UserID()) then
surface.PlaySound("coolsound")
end
end
[/CODE]
pretty sure this works
edit:
the op is using something on mpgh to load his scripts[/QUOTE]
External2 loads files relative to documents over the lua folder.
[editline]19th December 2015[/editline]
[QUOTE=Stalinalive;49351272]Riley_ PM me your steam name if you want to work it out there because this thread's just confusing[/QUOTE]
[url]http://steamcommunity.com/id/rousheebot[/url]
[editline]20th December 2015[/editline]
gameevent.Listen("player_hurt")
local function hitSound(data)
local ply = LocalPlayer()
if data.attacker == ply:UserID() then
surface.PlaySound("hitmarkers/mlghit.wav")
end
end
hook.Add("player_hurt", "", hitSound)
Got it working.
Sorry, you need to Log In to post a reply to this thread.