I've tried making this killcounter, but it dosent work. Everything looks absolutely right?
[CODE]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
[/CODE]
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!
[QUOTE=jacobcooper18;50200341]I've tried making this killcounter, but it dosent work. Everything looks absolutely right?
[CODE]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
[/CODE]
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![/QUOTE]
[CODE]
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
[/CODE]
Thanks! Ill try it :D
[QUOTE=kjh0105;50201761][CODE]
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
[/CODE][/QUOTE]
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: [CODE]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[/CODE]
and its in directory: garrysmod\addons\DOTASOUNDFILES\lua\autorun\rampage.lua and the sound is in \garrysmod\addons\DOTASOUNDFILES\sounds\rampage.wav
[QUOTE=jacobcooper18;50203303]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: [CODE]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[/CODE]
and its in directory: garrysmod\addons\DOTASOUNDFILES\lua\autorun\rampage.lua and the sound is in \garrysmod\addons\DOTASOUNDFILES\sounds\rampage.wav[/QUOTE]
Sorry... i posting to mobile mistakes
[CODE]
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')
[/CODE]
[CODE]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
[/CODE]
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]
[QUOTE=kjh0105;50203936]Sorry... i posting to mobile mistakes
[CODE]
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')
[/CODE][/QUOTE]
Help.. plz
[editline]26th April 2016[/editline]
[QUOTE=jacobcooper18;50204179][CODE]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
[/CODE]
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[/QUOTE]
Failed to load sound "rampage.wav", file probably missing from disk/repository
èrror console
[QUOTE=jacobcooper18;50204179][CODE]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
[/CODE]
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[/QUOTE]
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:
[CODE]
GiveKills(ply, attacker) -- Run fucktion
[/CODE]
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 [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/BroadcastLua]BroadcastLua[/url] (just a tip)
[QUOTE=MPan1;50204206]I think it's because of this:
[CODE]
GiveKills(ply, attacker) -- Run fucktion
[/CODE]
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 [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/BroadcastLua]BroadcastLua[/url] (just a tip)[/QUOTE]
I tried this, but it seems not to load again?
[CODE]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[/CODE]
[QUOTE=jacobcooper18;50204244]I tried this, but it seems not to load again?[/QUOTE]
Well, I didn't expect it to actually load, but I meant to do something like this instead:
[CODE]
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
[/CODE]
It doesn't really make a difference but I think less code makes stuff simpler
[QUOTE=MPan1;50204250]Well, I didn't expect it to actually load, but I meant to do something like this instead:
[CODE]
local function SoundPlayAll(snd)
BroadcastLua("surface.PlaySound('"..snd.."')")
end
local 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
hook.Add("DoPlayerDeath", "KillStreak", GiveKills)
[/CODE]
It doesn't really make a difference but I think less code makes stuff simpler[/QUOTE]
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
[QUOTE=MPan1;50204270]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[/QUOTE]
Yeah I have, it works. But one problem, I don't have a server sound directory?
Sorry, you need to Log In to post a reply to this thread.