ElexTron Software Posted July 24, 2010 Share Posted July 24, 2010 Okay I have this script: function dieHandler() local aa = math.random(1,3) local ab = tonumber(aa) if ab == 1 then outputChatBox("Damn! Now we'll never get that Weed!", source, 255, 0, 0, true) elseif ab == 2 outputChatBox("...Knew I should've gotten Chris to do it!", source, 255, 0, 0, true) elseif ab == 3 outputChatBox("Next time we get the stuff, you ain't in!", source, 255, 0, 0, true) end setSoundVolume(snd, .35) local sound = playSound("sounds/wasted.mp3") end addEventHandler("onClientPlayerWasted", getResourceRootElement(getThisResource()), dieHandler) But it won't work. If I remove everything and just make it output a message it works (aka i remove the random stuff). Does anyone know why? Thanks in advance. Link to comment
MaddDogg Posted July 24, 2010 Share Posted July 24, 2010 I think you should learn a bit more about Lua syntax and event handlers.. 1. You attached the event to the resource root element, which makes no sense, because the source is the player, who died. https://wiki.multitheftauto.com/wiki/OnC ... ayerWasted 2. The thing with variable "ab" is unnecessary, math.random already returns a number, so a conversion from a number to number is pointless. 3. You're missing the "then" after your elseif conditions. 4. You set the sound volume from a sound element "snd" to something, although in the next line you play a sound and save it in the variable "sound". So the lines should be swapped and setSoundVolume should rather use an actual sound element. Link to comment
ElexTron Software Posted July 24, 2010 Author Share Posted July 24, 2010 Okay thanks for your help, it works now. And about the snd in playSound, it is a global sound from another part of the script. I didn't post the whole script, just the function that wasn't working. And I knew that math.random already returned a number, but after trying everything else (and forgetting the then after elseif ) I tried anything. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now