Jump to content

setElementHealth


Recommended Posts

Posted

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 ) 
  

Posted

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.

Do NOT PM ME for help unless invited. - New MTA Script Editor

Scripting help "etiquette": understandable language, relevant code (ALL code if unsure), [Lua] tags, error messages with line numbers. Super simple stuff.

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