danylopez123 Posted October 21, 2017 Share Posted October 21, 2017 See i downloaded this mod: https://community.multitheftauto.com/index.php?p=resources&s=details&id=6331 But i want to know, what lines do i need to edit to make it plays a random death sound when you die, i got many death sounds So waqaarali i hope you dont mind that i edit your scrip. Link to comment
ShayF2 Posted October 22, 2017 Share Posted October 22, 2017 (edited) Post your current code, I will try to help you to the best of my ability. Edited October 22, 2017 by ShayF Link to comment
danylopez123 Posted October 23, 2017 Author Share Posted October 23, 2017 function wasted (thePlayer) local sound = playSound("The_Incredible_Coneman_Death.wav",false) setSoundVolume(sound, 1) end addEventHandler ( "onClientPlayerWasted", getLocalPlayer(), wasted ) This is my current edit for the mod downloaded, what i want is like, plays a random death sound, but with different file names Also, "InCase" if you can, how about something more "Complex": A death sound, but ONLY for a certain skin, like for example, on my server, i use a custom Kirby skin, when you are having the Kirby skin and then you die, it plays a death sound for that skin, or, i have also a Yoshi skin, if you die having the Yoshi skin, it plays another death sound If you dont want to do this complex thing i said, is ok Link to comment
Enargy, Posted October 23, 2017 Share Posted October 23, 2017 if getElementModel(whodied) == kirby then --playSound(...) - kirby's death sound elseif getElementModel(whodied) == cat then --playSound(...) - cat's death sound end Link to comment
ShayF2 Posted October 23, 2017 Share Posted October 23, 2017 (edited) local sounds = { --Format: {sound/url,volume(0-100)}, {'The_Incredible_Coneman_Death.wav',100}, {'sound2.wav',100}, {'sound3.wav',100}, {'sound4.wav',100}, {'sound5.wav',100}-- always leave the last one without a comma } -- this is our function to get random sound, and avoid getting the same on as the previous.. local previous function getRandom(t) local random = math.random(1,#t) if not random == previous then previous = random return random else getRandom(t) end end function wasted() local randomSound = getRandom(sounds)-- we use the function we just created and input the sounds table. -- it will return a table with 2 variables, 1st the sound url and 2nd the volume.. local sound = playSound(randomSound[1],false)-- so we use the first variable, the sound url to create the sound. setSoundVolume(sound,randomSound[2]/100)-- and the second variable to set the volume. -- divide the volume by 100 so that mta reads it as the regular decimal value end addEventHandler('onClientPlayerWasted',localPlayer,wasted) I hope this helped you. Later I will explain how to do specific sounds for specific skins. I'm a bit busy at the moment. Edited October 23, 2017 by ShayF 1 Link to comment
danylopez123 Posted October 23, 2017 Author Share Posted October 23, 2017 3 hours ago, Enargy, said: if getElementModel(whodied) == kirby then --playSound(...) - kirby's death sound elseif getElementModel(whodied) == cat then --playSound(...) - cat's death sound end But how about Skins ID? Because i think thats how it works 53 minutes ago, ShayF said: local sounds = { --Format: {sound/url,volume(0-100)}, {'The_Incredible_Coneman_Death.wav',100}, {'sound2.wav',100}, {'sound3.wav',100}, {'sound4.wav',100}, {'sound5.wav',100}-- always leave the last one without a comma } -- this is our function to get random sound, and avoid getting the same on as the previous.. local previous function getRandom(t) local random = math.random(1,#t) if not random == previous then previous = random return random else getRandom(t) end end function wasted() local randomSound = getRandom(sounds)-- we use the function we just created and input the sounds table. -- it will return a table with 2 variables, 1st the sound url and 2nd the volume.. local sound = playSound(randomSound[1],false)-- so we use the first variable, the sound url to create the sound. setSoundVolume(sound,randomSound[2]/100)-- and the second variable to set the volume. -- divide the volume by 100 so that mta reads it as the regular decimal value end addEventHandler('onClientPlayerWasted',localPlayer,wasted) I hope this helped you. Later I will explain how to do specific sounds for specific skins. I'm a bit busy at the moment. This didint worked, i keep killing myself and nothing is playing, i even edited the line for the sounds and nothing else Link to comment
ShayF2 Posted October 23, 2017 Share Posted October 23, 2017 local sounds = { --Format: {sound/url,volume(0-100)}, {'The_Incredible_Coneman_Death.wav',100}, {'sound2.wav',100}, {'sound3.wav',100}, {'sound4.wav',100}, {'sound5.wav',100}-- always leave the last one without a comma } -- this is our function to get random sound, and avoid getting the same on as the previous.. local previous function getRandom(t) local r = math.random(1,#t) if r ~= previous then previous = random return random else getRandom(t) end end function wasted() local randomSound = getRandom(sounds)-- we use the function we just created and input the sounds table. -- it will return a table with 2 variables, 1st the sound url and 2nd the volume.. local sound = playSound(randomSound[1],false)-- so we use the first variable, the sound url to create the sound. setSoundVolume(sound,randomSound[2]/100)-- and the second variable to set the volume. -- divide the volume by 100 so that mta reads it as the regular decimal value end addEventHandler('onClientPlayerWasted',localPlayer,wasted) Try this instead.. Link to comment
danylopez123 Posted October 23, 2017 Author Share Posted October 23, 2017 Nope, still not working Link to comment
Enargy, Posted October 23, 2017 Share Posted October 23, 2017 local deathSoundTable = { [5] = {"The_Incredible_Coneman_Death.wav", "sound2.wav", "..."}, -- Kirby's sounds. [9] = {"sound1.wav", "sound2.wav", "..."}, -- Yoshi's sounds. } addEventHandler('onClientPlayerWasted',localPlayer, function() local model = getElementModel(localPlayer) if deathSoundTable[model] then local r = math.random(1, #deathSoundTable[model]) local sound = playSound(deathSoundTable[model][r], false) setSoundVolume(sound, 1.0) -- 1.0 is the max value. end end ) Link to comment
ShayF2 Posted October 23, 2017 Share Posted October 23, 2017 (edited) I'm sorry I'm quite blind lol. I found a mistake in my code, I have fixed it here. It was a really simple fix and explains why it wasn't working. Please try this code. local sounds = { --Format: {sound/url,volume(0-100)}, {'The_Incredible_Coneman_Death.wav',100}, {'sound2.wav',100}, {'sound3.wav',100}, {'sound4.wav',100}, {'sound5.wav',100}-- always leave the last one without a comma } -- this is our function to get random sound, and avoid getting the same on as the previous.. local previous function getRandom(t) local r = math.random(1,#t) if r ~= previous then previous = random return random else getRandom(t) end end function wasted() local rs = getRandom(sounds)-- we use the function we just created and input the sounds table. -- it will return a valid index number different from the previous one.. local sound = playSound(sounds[rs][1],false)-- so we use the first variable, the sound url to create the sound. setSoundVolume(sound,sounds[rs][2]/100)-- and the second variable to set the volume. -- divide the volume by 100 so that mta reads it as the regular decimal value end addEventHandler('onClientPlayerWasted',localPlayer,wasted) After I get home I will work on an advanced way for skins and their own sounds. Edited October 23, 2017 by ShayF Link to comment
ShayF2 Posted October 23, 2017 Share Posted October 23, 2017 Alright I've finished making it for specific skins, here's the template, I hope this works for you. local sounds = {} souds['none'] = {-- this is for if the player does not have a skin that you manually inputted here. {'sound2.wav',100}, {'sound3.wav',100}, {'sound4.wav',100}, {'sound5.wav',100} } sounds[131] = {-- you can make more of these for each skin, just put the skin id within the [] {'The_Incredible_Coneman_Death1.wav',100}, {'The_Incredible_Coneman_Death2.wav',100}, {'The_Incredible_Coneman_Death3.wav',100} } local previous function getRandom(t) local r = math.random(1,#t) if r ~= previous then previous = r return r else getRandom(t) end end function wasted() local var = sounds[getElementModel(localPlayer)] or sounds['none'] local rs = math.random(1,#var) local sound = playSound(var[rs][1],false) setSoundVolume(sound,var[rs][2]/100) end addEventHandler('onClientPlayerWasted',localPlayer,wasted) Link to comment
danylopez123 Posted October 23, 2017 Author Share Posted October 23, 2017 4 minutes ago, ShayF said: Alright I've finished making it for specific skins, here's the template, I hope this works for you. local sounds = {} souds['none'] = {-- this is for if the player does not have a skin that you manually inputted here. {'sound2.wav',100}, {'sound3.wav',100}, {'sound4.wav',100}, {'sound5.wav',100} } sounds[131] = {-- you can make more of these for each skin, just put the skin id within the [] {'The_Incredible_Coneman_Death1.wav',100}, {'The_Incredible_Coneman_Death2.wav',100}, {'The_Incredible_Coneman_Death3.wav',100} } local previous function getRandom(t) local r = math.random(1,#t) if r ~= previous then previous = r return r else getRandom(t) end end function wasted() local var = sounds[getElementModel(localPlayer)] or sounds['none'] local rs = math.random(1,#var) local sound = playSound(var[rs][1],false) setSoundVolume(sound,var[rs][2]/100) end addEventHandler('onClientPlayerWasted',localPlayer,wasted) Wow! This time it really worked! Even for the skin IDs you choose! Thank you very much! Link to comment
ShayF2 Posted October 23, 2017 Share Posted October 23, 2017 1 minute ago, danylopez123 said: Wow! This time it really worked! Even for the skin IDs you choose! Thank you very much! No problem mate, I hope you enjoy. If you need any other help you can contact me by email or by Skype. Email: [email protected] Skype: cemour.burkoff Have a nice day, Shaio Fencski Link to comment
danylopez123 Posted October 23, 2017 Author Share Posted October 23, 2017 Sos, i do have Skype but i barely use it due im now on Discord, but ill try to add you there Link to comment
ShayF2 Posted October 23, 2017 Share Posted October 23, 2017 3 minutes ago, danylopez123 said: Sos, i do have Skype but i barely use it due im now on Discord, but ill try to add you there You may add my discord as well, ShayF#0259 And I forgot to change this but replace your wasted function with this. Sorry about that. function wasted() local var = sounds[getElementModel(localPlayer)] or sounds['none'] local rs = getRandom(var) local sound = playSound(var[rs][1],false) setSoundVolume(sound,var[rs][2]/100) end 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