Jump to content

Morphine Item Does'nt Do else Code if health is not 100


Recommended Posts

Posted

Well i have scripted a item so when you have 100 health when you inject the morphine you loose health but when you have any health thats not 100 it set's your health to 100

My Script

            elseif (itemID == 152) then -- Morphine 
            if getElementHealth(source, 100) then 
                setElementHealth(source, 50) 
                exports.global:sendLocalMeAction(source, "inject's some morphine into himself and start's to feel dizzy.") 
            else 
                exports.global:sendLocalMeAction(source, "inject's some morphine into himself.") 
                setElementHealth(source, 100) 
            end 

Posted
           elseif (itemID == 152) then -- Morphine 
            if getElementHealth(source) == 100 then 
                setElementHealth(source, 50) 
                exports.global:sendLocalMeAction(source, "inject's some morphine into himself and start's to feel dizzy.") 
            else 
                exports.global:sendLocalMeAction(source, "inject's some morphine into himself.") 
                setElementHealth(source, 100) 
            end 

getElementHealth will return the health, so you have to compare it (==) with 100.

Posted
           elseif (itemID == 152) then -- Morphine 
            if getElementHealth(source) == 100 then 
                setElementHealth(source, 50) 
                exports.global:sendLocalMeAction(source, "inject's some morphine into himself and start's to feel dizzy.") 
            else 
                exports.global:sendLocalMeAction(source, "inject's some morphine into himself.") 
                setElementHealth(source, 100) 
            end 

getElementHealth will return the health, so you have to compare it (==) with 100.

Mate now it does'nt work when i inject it at 100 Health it Just set my health to 100 Again it doesnt take away 50 Health

Posted

Try:

          elseif (itemID == 152) then -- Morphine 
            if getElementHealth(source) < 100 then 
                exports.global:sendLocalMeAction(source, "inject's some morphine into himself.") 
                setElementHealth(source, 100) 
            else 
                setElementHealth(source, 50) 
                exports.global:sendLocalMeAction(source, "inject's some morphine into himself and start's to feel dizzy.") 
            end 

Probably because it returns float, which may cause problems when comparing.

EDIT: You don't have to PM me.

Posted
Try:
          elseif (itemID == 152) then -- Morphine 
            if getElementHealth(source) < 100 then 
                exports.global:sendLocalMeAction(source, "inject's some morphine into himself.") 
                setElementHealth(source, 100) 
            else 
                setElementHealth(source, 50) 
                exports.global:sendLocalMeAction(source, "inject's some morphine into himself and start's to feel dizzy.") 
            end 

Probably because it returns float, which may cause problems when comparing.

EDIT: You don't have to PM me.

Same Thing!

Posted

You should check the wiki before asking those things:

    elseif ( itemID == 152 ) then 
        if ( getElementHealth ( source ) < 100 ) then -- is element 'source' defined? 
            -- send message 
            exports['global']:sendLocalMeAction ( source, 'Injects some morphine into himself.' ); 
            -- define 'source' element health to 100 
            setElementHealth ( source, 100 ); 
        -- if health is not smaller than 100 
        else 
            -- take 50% of 'source' element health 
            setElementHealth ( source, getElementHealth ( source ) - 50 ); 
            -- send message 
            exports['global']:sendLocalMeAction ( source, 'Injects some morphine into himself and starts to feel dizzy.' ); 
        end 
    end 

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