Can't get it to work so making request.

[lua]local hear_voices = {
“/voices/voice01.mp3”;
“/voices/voice02.mp3”;
“/voices/voice03.mp3”;
“/voices/voice04.mp3”;
“/voices/voice05.mp3”;
“/voices/voice06.mp3”;
“/voices/voice07.mp3”;
“/voices/voice08.mp3”;
“/voices/voice09.mp3”;
“/voices/voice10.mp3”;
“/voices/voice11.mp3”;
“/voices/voice12.mp3”;
“/voices/voice13.mp3”;
“/voices/voice14.mp3”;
“/voices/voice15.mp3”;
}
function ChoosePlayer( ply )
local rply = math.random(1, #player.GetAll())
local chosen = player.GetAll()[rply]
for i = 1, #player.GetAll() do
player.GetAll():SetTeam( TEAM_INFECTED );
player.GetAll()
:Spawn()
end
end
concommand.Add(“infectedteam”, ChoosePlayer)

function Playsound()
surface.PlaySound( hear_voices[math.random( 1, #hear_voices )] )
end
function Hearsound( ply )
if ply:Team() == TEAM_INFECTED then
timer.Create( “playsound”, 15, 0, Playsound )
else
timer.Destroy( “playsound” )
end
end
concommand.Add(“voices”, Hearsound)
function Start()
timer.Create( “CheckTeam”, 5, 0, Hearsound )
RunConsoleCommand(“voices”)
end
hook.Add(“PlayerSpawn”, “RepeatChecking”, Start)[/lua]

Thats all I have now, I’m about to start pulling my hair out at this frustration. I can’t really get it to work because timers do not like ply and always decide it’s a nil value. Line 32, local ply index as nil.

You’re never calling the function with a valid ply argument, so no wonders it doesn’t work. Just do,
[lua]
RunConsoleCommand( “voices”, ply );
[/lua]

You also forgot a ply variable in the start function, so replace function Start() with
[lua]
function Start( ply )
[/lua]

[editline]06:51PM[/editline]



Timer Error: autorun/infected.lua:32: attempt to index local 'ply' (a nil value)

Still :frowning:

Anyone have any idea, or anything as to why this really isn’t working?

Or would someone like to make it for me ;(

You’re not actually setting/specifying ply anywhere. Should be…

[lua]
function Start( pl )
timer.Create( “CheckTeam”, 5, 0, Hearsound, pl )
// RunConsoleCommand(“voices”) // use pl:ConCommand instead
end

hook.Add(“PlayerSpawn”, “RepeatChecking”, Start)

[/lua]

Thanks.

I’ll try that.

[editline]03:42PM[/editline]

Still doesn’t work:


autorun/infected.lua:31: attempt to index local 'ply' (a nil value)

With
[lua]local hear_voices = {
“/voices/voice01.mp3”;
“/voices/voice02.mp3”;
“/voices/voice03.mp3”;
“/voices/voice04.mp3”;
“/voices/voice05.mp3”;
“/voices/voice06.mp3”;
“/voices/voice07.mp3”;
“/voices/voice08.mp3”;
“/voices/voice09.mp3”;
“/voices/voice10.mp3”;
“/voices/voice11.mp3”;
“/voices/voice12.mp3”;
“/voices/voice13.mp3”;
“/voices/voice14.mp3”;
“/voices/voice15.mp3”;
}
function ChoosePlayer( pl )
local rpl = math.random(1, #player.GetAll())
local chosen = player.GetAll()[rpl]
for i = 1, #player.GetAll() do
player.GetAll():SetTeam( TEAM_INFECTED );
player.GetAll()
:Spawn()
end
end
concommand.Add(“infectedteam”, ChoosePlayer)
function Playsound()
surface.PlaySound( hear_voices[math.random( 1, #hear_voices )] )
end
function Hearsound( ply )
if ply:Team() == TEAM_INFECTED then
timer.Create( “playsound”, 15, 0, Playsound )
else
timer.Destroy( “playsound” )
end
end
function Start( pl )
timer.Create( “CheckTeam”, 5, 0, Hearsound, pl )
pl:SendLua(“Hearsound(pl)”)
end
hook.Add(“PlayerSpawn”, “RepeatChecking”, Start)[/lua]

EDIT: Well atleast it’s not a timer error this time.

It’s the sendlua line. Revert back to the console command. Like so…

[lua]
function Headsound( pl ) end
concommand.Add( “cc”, Hearsound );

pl:ConCommand( “Hearsound” );
[/lua]

The first arg will be the player.

No errors now, but sounds don’t play. I can probably fix that.

Edit: Nope.

Another dead end.