I want to make a hitsound when player shoots an other player. I think it should be something like
[code]function GM:EntityTakeDamage( )
if ( ent:IsPlayer() ) then
self.Owner:EmitSound(hitsound)
end
end[/code]
But sure it's wrong and I don't know how to write it right.
Try this.
[code]function GM:EntityTakeDamage( )
if ( ent:IsPlayer() ) and dmginfo:IsBulletDamage() then
self.Owner:EmitSound("Path/To/Sound.whatever")
end
end[/code]
[QUOTE=.Tenshi;41207456]Try this.
[code]function GM:EntityTakeDamage( )
if ( ent:IsPlayer() ) and dmginfo:IsBulletDamage() then
self.Owner:EmitSound("Path/To/Sound.whatever")
end
end[/code][/QUOTE]
[code][ERROR] gamemodes/q3ffa/gamemode/init.lua:27: attempt to index field 'Owner' (a nil value)[/code]
[code]function GM:EntityTakeDamage( )
if ( ent:IsPlayer() ) and dmginfo:IsBulletDamage() then
ent:EmitSound("Path/To/Sound.whatever")
end
end[/code]
[QUOTE=.Tenshi;41207756][code]function GM:EntityTakeDamage( )
if ( ent:IsPlayer() ) and dmginfo:IsBulletDamage() then
ent:EmitSound("Path/To/Sound.whatever")
end
end[/code][/QUOTE]
You forgot to add the args to the first line
[code]function GM:EntityTakeDamage( ent, dmginfo )[/code]
[QUOTE=.Tenshi;41207756][code]function GM:EntityTakeDamage( )
if ( ent:IsPlayer() ) and dmginfo:IsBulletDamage() then
ent:EmitSound("Path/To/Sound.whatever")
end
end[/code][/QUOTE]
Now the sound is coming from the player gets damage, and I need to play the sound on the player shoots
What kind of hitsound is it? If you want a Quake-like hitsound that notifies a player every time they hit someone, only the attacker should be hearing it. Try this instead:
Serverside:
[lua]function GM:EntityTakeDamage(ent, dmginfo)
local attacker = dmginfo:GetAttacker()
if ent:IsPlayer() and attacker:IsPlayer() then
umsg.Start("PlayHitSound", attacker)
umsg.End()
end
end[/lua]
Clientside:
[lua]usermessage.Hook("PlayHitSound", function(msg)
LocalPlayer():EmitSound("path/to/sound.whatever")
end)[/lua]
This will not play a sound serverside, instead it will send a message to the attacking player which plays a sound clientside once it is received. No one else will be able to hear it.
[QUOTE=_Kilburn;41208175]What kind of hitsound is it? If you want a Quake-like hitsound that notifies a player every time they hit someone, only the attacker should be hearing it. Try this instead:
Serverside:
[lua]function GM:EntityTakeDamage(ent, dmginfo)
local attacker = dmginfo:GetAttacker()
if ent:IsPlayer() and attacker:IsPlayer() then
umsg.Start("PlayHitSound", attacker)
umsg.End()
end
end[/lua]
Clientside:
[lua]usermessage.Hook("PlayHitSound", function(msg)
LocalPlayer():EmitSound("path/to/sound.whatever")
end)[/lua]
This will not play a sound serverside, instead it will send a message to the attacking player which plays a sound clientside once it is received. No one else will be able to hear it.[/QUOTE]
Thank you!
Sorry, you need to Log In to post a reply to this thread.