JackZipper Posted June 25, 2009 Share Posted June 25, 2009 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
50p Posted June 25, 2009 Share Posted June 25, 2009 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
robhol Posted June 25, 2009 Share Posted June 25, 2009 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... 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
JackZipper Posted June 25, 2009 Author Share Posted June 25, 2009 i tried the version with the small "s" and it works. i don't know why the console has given me the wrong error but it did. thanks for the help guys. 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