Jump to content

Random death sound when a player dies


danylopez123

Recommended Posts

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
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 by ShayF
  • Like 1
Link to comment
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
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
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

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 by ShayF
Link to comment

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
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
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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...