Jump to content

[Question] health


Stranger

Recommended Posts

Posted

hello,

i have a problem or maybe bug ? i don't know

that if i used:

setElementHealth (player, getElementHealth (player) - 30) 

it's work

but if his health and his health has reached 30, his health is filled automatically,

i don't know if this is a bug or something like that.

Posted
  
local msec = 1000 -- Type mili - seconds here how much you whant. 
local hpC = getElementHealth (player) -- get players health 
local upmSec = 5000 -- type mili - seconds here of how much time you want take it make it u;. 
local up = 35 -- the hp should be up must be here 
function nameIt(player) -- function 
if hpC  < 30 then -- checking players hp if 30 down then it will continue 
setTimer(setElementHealth,upmSec,3,player,up) -- it set its hp 
     end 
end 
setTimer(nameIt,msec,0) 
  

If you meant the script then here.

else--

If you meant the bug then you are talking about the health getting refiled automatically? Then post it at bugs section.

Posted

i meant, that i want his health go down not go up, like if i hit him , will take

from his health 30%

until he die

but i here is the problem

that make the health refilled

if his health reached 30

Posted (edited)
  
function playerHP(attacker) 
local hp =  getElementHealth (source) 
if hp < 30 then 
cancelEvent() 
end 
end 
addEventHandler("onClientPlayerDamage",getRootElement(),playerHP) 
  

Edited by Guest
Posted

1- you must make it -300 because full health is 1000

2- here is what you have to do

  
health = getElementHealth(player) 
if health =< 300 then 
killPed(player) 
else setElementHealth(player,health - 300) 
end 
  

Ingame Name: Arnold

If you need my help, contact me on Skype @bshr.ara

NOTE:DO NOT ASK ME FOR SCRIPTS, ASK ME FOR HELP

Posted
1- you must make it -300 because full health is 1000

2- here is what you have to do

  
health = getElementHealth(player) 
if health =< 300 then 
killPed(player) 
else setElementHealth(player,health - 300) 
end 
  

Lol? See at the wiki setElementHealth example. Why there is -20 not -200?

Posted

you didn't understand me, i mean every time i hit him he loss 30 until he die, and

i just wanna make it fast, i mean i want when i hit him

not loss 5 or whatever he use ,

i just wanna make it if i hit him

he loss 30 until he die

but i have this problem

that if the player close to die his health refilled,

i want it if he close to die , his health not refilled,

just keep going down,

i wish that you understand what i meant.

Posted

no there is not a code that refilling the health, i'm sure, and the code i know there is no problem with it:

addEventHandler ("onPlayerDamage", root, 
function (attacker, weapon, bodypart) 
if attacker then 
health = getElementHealth (source) 
setElementHealth (source, health - 30) 
end 
end) 

  • Moderators
Posted
you didn't understand me, i mean every time i hit him he loss 30 until he die, and

i just wanna make it fast, i mean i want when i hit him

not loss 5 or whatever he use ,

i just wanna make it if i hit him

he loss 30 until he die

but i have this problem

that if the player close to die his health refilled,

i want it if he close to die , his health not refilled,

just keep going down,

i wish that you understand what i meant.

This is how you solve that problem.

local healthLoss = 30 
addCommandHandler("kill", 
function() 
  
    local health = getElementHealth(localPlayer) 
    if healh =< healthLoss then 
        setElementHealth(localPlayer,0) 
    else 
        setElementHealth(localPlayer,healh-healthLoss) 
    end 
end) 
  
  
  

Health gets refilled because you can't have negative health for players.

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

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