#DaMiAnO Posted December 28, 2011 Share Posted December 28, 2011 Hi! I have this: function lowHealth() local playerHealth = getElementHealth ( getLocalPlayer() ) if playerHealth <= 10 then local sound = playSound("sounds/heart.mp3") else stopSound( "sounds/heart.mp3" ) end end addEventHandler ( "onPlayerDamage", getRootElement(), lowHealth ) But, when I have less of 10 HP (or equivalent), i can't hear sound. How to fix that? Link to comment
Evil-Cod3r Posted December 28, 2011 Share Posted December 28, 2011 Try this function lowHealth() local playerHealth = getElementHealth ( source ) if playerHealth <= 10 or 9 or 8 or 7 or 6 or 5 or 4 or 3 or 2 or 1 then local sound = playSound("sounds/heart.mp3") else stopSound( "sounds/heart.mp3" ) end end addEventHandler ( "onPlayerDamage", getRootElement(), lowHealth ) Link to comment
JR10 Posted December 28, 2011 Share Posted December 28, 2011 This is wrong. Client side: function lowHealth() if getElementHealth ( source ) <= 10 then playSound("sounds/heart.mp3",false) end end addEventHandler ( "onClientPlayerDamage", localPlayer, lowHealth ) Link to comment
#DaMiAnO Posted December 28, 2011 Author Share Posted December 28, 2011 Can be done even as so, That when I lose more of 10 HP, it will not sound to me play 2 times? Link to comment
arezu Posted December 28, 2011 Share Posted December 28, 2011 Can be done even as so, That when I lose more of 10 HP, it will not sound to me play 2 times? what? explain better Link to comment
Al3grab Posted December 28, 2011 Share Posted December 28, 2011 like this it wont play 2 times function lowHealth() if low == true then return end if getElementHealth ( source ) <= 10 then low = true else loa = false end if low == true then playSound("sounds/heart.mp3",false) end end addEventHandler ( "onClientPlayerDamage", localPlayer, lowHealth ) addEventHandler ( "onClientPlayerWasted", localPlayer, function() low = false end ) Link to comment
12p Posted December 28, 2011 Share Posted December 28, 2011 function lowHealth() if not low then if getElementHealth ( source ) <= 10 then playSound("sounds/heart.mp3",false) low = true else low = false end end end addEventHandler ( "onClientPlayerDamage", localPlayer, lowHealth ) addEventHandler ( "onClientPlayerWasted", localPlayer, function() low = false end ) You mispelled "low", and wrote "loa". Also I reduced a bit your lines Link to comment
#DaMiAnO Posted December 29, 2011 Author Share Posted December 29, 2011 function lowHealth() if not low then if getElementHealth ( source ) <= 10 then playSound("sounds/heart.mp3",false) low = true else low = false end end end addEventHandler ( "onClientPlayerDamage", localPlayer, lowHealth ) addEventHandler ( "onClientPlayerWasted", localPlayer, function() low = false end ) You mispelled "low", and wrote "loa". Also I reduced a bit your lines Oh thanks, but Can be done so, that the sound will be repeated, until death player? Link to comment
Al3grab Posted December 29, 2011 Share Posted December 29, 2011 function lowHealth() if not low then if getElementHealth ( source ) <= 10 then playSound("sounds/heart.mp3",false) low = true else low = false end end end addEventHandler ( "onClientPlayerDamage", localPlayer, lowHealth ) addEventHandler ( "onClientPlayerWasted", localPlayer, function() low = false end ) You mispelled "low", and wrote "loa". Also I reduced a bit your lines yeah thanks for correcting it that the sound will be repeated, until death player? it wont be repeated until the player dies it will play again if his damage less than 10 , and go on Link to comment
#DaMiAnO Posted December 29, 2011 Author Share Posted December 29, 2011 For example, I had 5 HP. When sound is gone, It isn't repeated. Link to comment
GanJaRuleZ Posted December 29, 2011 Share Posted December 29, 2011 function lowHealth() local health = getElementHealth ( source ) if health <= 10 then for i=1;1000 do playSound("sounds/heart.mp3",false) end addEventHandler ( "onClientPlayerWasted", localPlayer, function lowHealth() ) function deadPlayer( thePlayer) if ( isPedDead ( thePlayer ) ) then stopSound("sounds/heart.mp3",false) end Now wait for a experienced scripter to find my mistakes ( if there are , but i'm sure it isn't perfect ) Link to comment
Orange Posted December 29, 2011 Share Posted December 29, 2011 Oh noes, pr0 scripters are helping another pr0 scripters local heartbeat = playSound("sounds/heart.mp3", true) setSoundVolume(heartbeat, 0) function onRender() if getElementHealth(getLocalPlayer()) and getElementHealth(getLocalPlayer()) <= 10 then setSoundVolume(heartbeat, 1) else setSoundVolume(heartbeat, 0) end end addEventHandler ( "onClientRender", getRootElement(), onRender) Link to comment
12p Posted December 29, 2011 Share Posted December 29, 2011 Isn't that actually taking too much CPU? Link to comment
GanJaRuleZ Posted December 29, 2011 Share Posted December 29, 2011 Since , it would to laggy , because the sounds loops everytime , making a huge lag. Just make one to start when someone is just under 10 HP .. Link to comment
Al3grab Posted December 29, 2011 Share Posted December 29, 2011 For example, I had 5 HP. When sound is gone, It isn't repeated. so you want it repeated ? Link to comment
#DaMiAnO Posted December 29, 2011 Author Share Posted December 29, 2011 Ye, when I'll have 10 HP or less,I want stop the sound. Link to comment
GanJaRuleZ Posted December 29, 2011 Share Posted December 29, 2011 Ye, when I'll have 10 HP or less,I want stop the sound. You mean start? Link to comment
#DaMiAnO Posted December 29, 2011 Author Share Posted December 29, 2011 When I have 10 HP or less, I want start the sound (when sound is end, i want repeat this sound until i die), and when I die I want stop the sound. But I have 10 HP or less, sound is ending, and it isn't repeated. Link to comment
BinSlayer1 Posted December 29, 2011 Share Posted December 29, 2011 When I have 10 HP or less, I want start the sound (when sound is end, i want repeat this sound until i die), and when I die I want stop the sound.But I have 10 HP or less, sound is ending, and it isn't repeated. So? That's just your original script that you posted here.. But you've been given a bunch of scripts. Have you tested them out? If yes, well, do they behave like you want? Orange's script looks fine to me. If it doesn't work, then say what doesn't work.. Link to comment
GanJaRuleZ Posted December 29, 2011 Share Posted December 29, 2011 Just post your current script here... Link to comment
Orange Posted December 29, 2011 Share Posted December 29, 2011 Check out my code, it works. Link to comment
#DaMiAnO Posted December 29, 2011 Author Share Posted December 29, 2011 Topic can be closed. Thanks Orange! 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