Jump to content

[HELP] OBJECT HEALTH


Erknneto

Recommended Posts

Posted

Hey, guys. I'm creating a Craft System for my server, but I really need a Helth System for the Object, for example:

If a player damage the object with his arm or a weapon the object will lose his health, if the health reaches in 0, the object will be destroyed. I tryed to make it, but I can't, it never destroys the object. Can you guys help me? I really need that.

Look what I did:

function objDoesntBreak () --THIS FUNCTION WORKS, THE SECOND FUNCTION DOESN'T WORKS! 
    if getElementData(source,"craftedObject") == true then 
        cancelEvent() 
    end 
end 
addEventHandler("onClientObjectBreak", root, objDoesntBreak) 
  
function objDamageStart () 
currentHealth = getElementHealth(source) 
    if getElementData(source,"craftedObject") == true then 
        if currentHealth <= 0 then 
            destroyElement(source) 
        end 
    end 
    setElementHealth(source,getElementHealth(source)-20) 
end 
addEventHandler("onClientObjectDamage", root, objDamageStart) 

  • Moderators
Posted

I have never set health for an object. You should use an alternative, like tables or elementdata to make it perfect.

Posted

You can't set health of an object with setElementHealth. It only works with players, peds or vehicles. To do what you want use tables or(and) variables instead.

Posted

As was stated before, objects do not have any specified amount of health. You'll need to design your own health system to achieve this.

Personally I would use element data for this as you already have the functions and events necessary. :)

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