micheal1230 Posted May 19, 2012 Share Posted May 19, 2012 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 Link to comment
Alpha Posted May 19, 2012 Share Posted May 19, 2012 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. Link to comment
micheal1230 Posted May 19, 2012 Author Share Posted May 19, 2012 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 Link to comment
Alpha Posted May 19, 2012 Share Posted May 19, 2012 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. Link to comment
micheal1230 Posted May 19, 2012 Author Share Posted May 19, 2012 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! Link to comment
Anderl Posted May 19, 2012 Share Posted May 19, 2012 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 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