JackZipper Posted June 25, 2009 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 )
50p Posted June 25, 2009 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. - MTA Script Editor - Ask your scripting questions properly, please. - 50p's public resources - Meta.xml - what is it for? How is it possible LOL
robhol Posted June 25, 2009 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. 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.
JackZipper Posted June 25, 2009 Author 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.
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