KillCount playsound error please help!

I’ve tried making this killcounter, but it dosent work. Everything looks absolutely right?


function GiveKills(ply, attacker)
     if ( ply != attacker and attacker:IsPlayer()) then
          attacker.Kills = attacker.Kills + 1
          if ( attacker.Kills == 2 ) then
			attacker:EmitSound( 'addons\DOTA SOUNDFILES\sounds\rampage.wav' )
          end
     end
     if( ply:IsPlayer() ) then
	   ply.Kills = 0 -- Resets the players killstreak if they die
     end
end


Please help! Oh and I have this in garrysmod\addons\DOTA SOUNDFILES\lua\autorun\init.lua
By the way, I wanted to make it so, when a player kills 3 people A RAMPAGE sound plays and everyone can hear… it. Thanks for helping me!



hook.Add("DoPlayerDeath", "KillStreak", function(ply, attacker, dmg)
GiveKills(ply, attacker) -- Run fucktion
end)

function GiveKills(ply, attacker)
     attacker.Kills = attacker.Kills or 0 -- Var initialize

     if (ply != attacker && attacker:IsPlayer()) then
          attacker.Kills = attacker.Kills + 1
          if ( attacker.Kills == 2 ) then
              SoundPlayAll("rampage.wav")
          end
     end

     if( ply:IsPlayer() ) then
	   ply.Kills = 0 -- Resets the players killstreak if they die
     end
end

function SoundPlayAll(snd)
    for k, v in ipairs(player.GetAll()) do
          v:SendLua("surface.PlaySound("..snd..")")
    end
end


Thanks! Ill try it :smiley:

I tried it, dosent work. It works but the SOUNDPLAYALL comes up with error in console [ERROR] LuaCmd:1: attempt to index global ‘rampage’ (a nil value)

  1. unknown - LuaCmd:1

[editline]26th April 2016[/editline]

This is what I have now:


hook.Add("DoPlayerDeath", "KillStreak", function(ply, attacker, dmg)
GiveKills(ply, attacker) -- Run fucktion
end)

function GiveKills(ply, attacker)
     attacker.Kills = attacker.Kills or 0 -- Var initialize

     if (ply != attacker && attacker:IsPlayer()) then
          attacker.Kills = attacker.Kills + 1
          if ( attacker.Kills == 2 ) then
              SoundPlayAll("Rampage.wav")
          end
     end

     if( ply:IsPlayer() ) then
	   ply.Kills = 0 -- Resets the players killstreak if they die
     end
end

function SoundPlayAll(snd)
    for k, v in ipairs(player.GetAll()) do
          v:SendLua("surface.PlaySound("..snd..")")
    end
end

and its in directory: garrysmod\addons\DOTASOUNDFILES\lua\autorun\rampage.lua and the sound is in \garrysmod\addons\DOTASOUNDFILES\sounds\rampage.wav

Sorry… i posting to mobile mistakes



v:SendLua("surface.PlaySound("..snd..")") -- Error 
-- Client comes code .. surface.PlaySound(rampage.wav) rampage var is nil value.
change to

v:SendLua("surface.PlaySound('"..snd.."')") -- Working...
-- Client comes code .. surface.PlaySound('rampage.wav') 



hook.Add("DoPlayerDeath", "KillStreak", function(ply, attacker, dmg)
GiveKills(ply, attacker) -- Run fucktion
end)

function GiveKills(ply, attacker)
     attacker.Kills = attacker.Kills or 0 -- Var initialize

     if (ply != attacker && attacker:IsPlayer()) then
          attacker.Kills = attacker.Kills + 1
          if ( attacker.Kills == 2 ) then
              SoundPlayAll("Rampage.wav")
          end
     end

     if( ply:IsPlayer() ) then
	   ply.Kills = 0 -- Resets the players killstreak if they die
     end
end

function SoundPlayAll(snd)
    for k, v in ipairs(player.GetAll()) do
          v:SendLua("surface.PlaySound('"..snd.."')")

    end
end


And the “sound” aint playing, ? No errors. The RAMPAGE.wav is in direct downloads ( downloaded perfectly ) but still dosent play after 3 kills?!?!
hmm…

[editline]26th April 2016[/editline]

Help… plz

[editline]26th April 2016[/editline]

Failed to load sound “rampage.wav”, file probably missing from disk/repository
èrror console

Are you put “sounds” folder?
surface.PlaySound should working directory “sound” folder

addons contents folder not working
then please put the “garrysmod/sound/” folder

I think it’s because of this:



GiveKills(ply, attacker) -- Run fucktion


Lua doesn’t like swearing

Actually, I have no idea what the problem is… but instead of looping through all the players in the SoundPlayAll function, you could use

BroadcastLua (just a tip)

I tried this, but it seems not to load again?


hook.Add("DoPlayerDeath", "KillStreak", function(ply, attacker, dmg)
GiveKills(ply, attacker) 
end)

function GiveKills(ply, attacker)
     attacker.Kills = attacker.Kills or 0 -- Var initialize

     if (ply != attacker && attacker:IsPlayer()) then
          attacker.Kills = attacker.Kills + 1
          if ( attacker.Kills == 2 ) then
              BroadcastLua(SoundPlayAll("Rampage.wav"))
          end
     end

     if( ply:IsPlayer() ) then
	   ply.Kills = 0 -- Resets the players killstreak if they die
     end
end

function SoundPlayAll(snd)
    for k, v in ipairs(player.GetAll()) do
          v:SendLua("surface.PlaySound('"..snd.."')")

    end
end

Well, I didn’t expect it to actually load, but I meant to do something like this instead:



local function SoundPlayAll(snd)
      BroadcastLua("surface.PlaySound('"..snd.."')")
end

local function GiveKills(ply, attacker, dmginfo)
     attacker.Kills = attacker.Kills or 0 -- Var initialize

     if (ply ~= attacker and attacker:IsPlayer()) then
          attacker.Kills = attacker.Kills + 1
          if ( attacker.Kills == 2 ) then
              SoundPlayAll("Rampage.wav")
          end
     end

     if( ply:IsPlayer() ) then
	   ply.Kills = 0 -- Resets the players killstreak if they die
     end
end

hook.Add("DoPlayerDeath", "KillStreak", GiveKills) -- you can just directly refer to the function since the args for it don't really change


It doesn’t really make a difference but I think less code makes stuff simpler

Alright, but do you know were the Directory for sounds in servers ( gmod ) is?
hmm…

Maybe your sound file isn’t formatted properly? Do you have audacity?

Hang on, have you actually tried to play the sound (in gmod) before doing all this? Maybe there’s something wrong with the sound rather than the code

Yeah I have, it works. But one problem, I don’t have a server sound directory?