Whats wrong with my code?

I’m trying to get a sound to play when the round starts for both the murderer, and bystander, for the murder mod gamemode. Any idea why it isn’t working?

What I want it to do is basically on round start, if your GetMurderer() then play this sound. Otherwise if its another team then play a different sound. Been googling and trying my best to do it myself for a few hours now but I’m stumped…

resource.AddFile(“sound/startsound/horror.wav”)
resource.AddFile(“sound/startsound/horror2.wav”)

local function PlayMusic()
if LocalPlayer():GetMurderer() then
surface.PlaySound(“startsound/horror.wav”) else
surface.PlaySound(“startsound/horror2.wav”)
end
hook.Add(“OnStartRound”, “Music”, PlayMusic)

Probably because you try to use client-only function on server. ( LocalPlayer() )

[editline]11th December 2013[/editline]

Or the fact that there’s no such hook on client.

Sorry, I’m pretty new to this. I got this to broadcast the sound to all players on round start, how could I make that GetMurderer() class only?
I’ve tried goggling for hours now but my OP was my best guess…

resource.AddFile(“sound/startsound/horror.wav”)

local function PlayMusic()
BroadcastLua(‘surface.PlaySound(“startsound/horror.wav”)’)
end
hook.Add(“OnStartRound”, “Music”, PlayMusic)


hook.Add("OnStartRound", "Music", function()
    for id, ply in pairs( player.GetAll() ) do
        if ply:GetMurderer() then
            ply:SendLua('surface.PlaySound("startsound/horror.wav")')
        else
            ply:SendLua('surface.PlaySound("startsound/horror2.wav")')
        end
    end
end )

Assuming Player:GetMurderer() is a real function.

P.S.


 TAGS

Are you using some sort of custom framework or something? Because there is no such hook called “OnStartRound”? Even if you were using a fixed up fretta framework the hook is called “OnRoundStart”. Plus the hook is serverside.

It’s not clientside, it’s not fretta, it’s Murder gamemode.

Wow… Worked instantly. Thanks so much, I would have not figured that out…

I understand the script all but the “for id, ply in pairs( player.GetAll() ) do” part.

What dose ply in pairs mean?

It’s basically the key and value of the for loop.

It is a for loop, id is the key in table, ply is value of the key in the table, player.GetAll() is the table and pairs is the iterator function that just goes through all keys in the table.

It looks like you need to learn basic Lua syntax, so google some tutorials.