• Two Lua problems: TTT Sound Hook
    9 replies, posted
Here is a snippet of my code: (This snippet should be enough) [lua]hook.Add("TTTEndRound", "End Round Music", function( wintype ) if music:GetInt() != 1 then return end if wintype == WIN_INNOCENT then surface.PlaySound("fun/CEL.mp3") elseif wintype == WIN_TIMELIMIT then surface.PlaySound("fun/Yeahhh.mp3") elseif wintype == WIN_TRAITOR then surface.PlaySound("ttt/tators.wav") end end)[/lua]
What are the problems? Wintype and end-round is called on the server? That looks like it was ripped from other code. because it has net code in it, but no net?? Here's the one I give out: Place in garrysmod/lua/autorun [url]https://dl.dropboxusercontent.com/u/26074909/ttt_end_round.rar[/url]
It wasnt ripped, as I saidit is a snippet. Where do you see net code?
Sorry, I read GetInt( ) as ReadInt( ); not sure what part of the code that is from; Read would be net. Feel free to use my system, put in your own sounds.
[QUOTE=Acecool;41631590]What are the problems?[/QUOTE]
He's probably using a server-side hook; and getting an error on surface is nil. And also on music:GetInt( ) nil. That's my guess, but I wish we'd have the error. Otherwise just use my code, change the sounds, and it works?
I get no error. The music just doesnt play. None of the three options plays. I dont want to use your code as I am learning Lua and wish to know [I]why[/I] it doesnt work.
Sure. To start: TTTEndRound is a SERVERside only call. Meaning the CLIENT can not call it. My guess is that since you're getting no error, you put it in an area where the CLIENT calls it. The SERVER needs to utilize the hook, then you need to tell the client what to do. surface is a CLIENT library. If that were to be copied to the SERVER as it is, it would give you an error. There are many different ways to do many different thing in coding solutions to problems. I use net.Broadcast( ) to tell all clients which song they need to play at the end of the round. The CLIENT receives that data, and uses the surface library to play the sound. Others have used BroadcastLua to keep everything serverside. I prefer a net solution. Feel free to use my code to learn. Make sure you set up hooks in appropriate areas ( CLIENT/ shared ( both client and server ) / SERVER ). Make sure that libraries which are client-side only are only called on the client, otherwise you'll end up with a library is nil error. Hope this helps!
It did, and I used the information to fix the script! Thanks!
Excellent, feel free to mark this topic as solved next to the top-left reply button so others don't think it's unsolved :-)
Sorry, you need to Log In to post a reply to this thread.