Jump to content

setElementHealth


Recommended Posts

Hi, i tried to do an damagesystem for my gamemode which gives different damagetypes for every bodypart.

but everytime i want to give damage to my player it doesn't work and the console says "bad argument".

This is the (shortform) of the code i use:

  
function dmg ( attacker, weapon, bodypart, loss) 
  
if ( bodypart == 9 ) then 
    SetElementHealth ( source, ( getElementHealth ( source) - loss * 2 ) ) 
end 
end 
addEventHandler ( "onPlayerDamage", getRootElement(), dmg ) 
  

Link to comment

Why it doesn't say "attempt to call global 'SetElementHealth' (a nil value)"?

Lua, as many other programming/scripting languages is case-sensitive. SetElementHealth is not same as setElementHealth. All MTA functions start with lower case characters.

Link to comment

Indent much? It's not a crisis this time, but if you ever post any larger pieces of code and don't indent it, people will run screaming from it... :P

The problem I see here doesn't really match the error message you game, but there's no function named SetElementHealth. It's setElementHealth. (Function names are case-sensitive.)

Apart from that, a little gotcha. In this example, you're tripling the damage, not doubling it, like I assume you intended. You can either modify the amount set in the script, or just cancel the event with cancelEvent.

Link to comment

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