Jump to content

Heartbeat


#DaMiAnO

Recommended Posts

Posted

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?

Posted

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 ) 

Posted

This is wrong.

Client side:

function lowHealth() 
if getElementHealth ( source ) <= 10 then 
playSound("sounds/heart.mp3",false) 
end 
end 
addEventHandler ( "onClientPlayerDamage", localPlayer, lowHealth ) 

Posted

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 ) 
  

Posted
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 :P

Posted
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 :P

Oh thanks, but Can be done so, that the sound will be repeated, until death player?

Posted
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 :P

yeah thanks for correcting it :D

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

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

Posted

Oh noes, pr0 scripters are helping another pr0 scripters :o

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) 

Posted

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.

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

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