Guest Posted July 13, 2018 Share Posted July 13, 2018 (edited) Hey guys i'm new in scripting, i used wiki to learn i have made this code just to test myself addEventHandler("onPlayerChangeNick", getRootElement(), wasNickChangedByUser) function changenick (onPlayerChangeNick) outPutChatBox ( " Your have been changed your nickname " ) end How can i fix it ?, ik it's cancer ====================================================================== after some time because no one answered I tried this code and it's worked addEventHandler('onClientPlayerChangeNick', root, function(oldNick, newNick) outputChatBox('You have been changed your nickname', 255, 100, 100) end) But what's is " root, " and why in some script there is function testmod (oldNick, newNick) And other script only function(oldNick, newNick) Edited July 13, 2018 by Guest Link to comment
Galactix Posted July 13, 2018 Share Posted July 13, 2018 The event handler has to be under the fuction if you don’t include the function directly to the handler like in the working script you shown. A computer reads code from up to bottom so you’re just calling a function that doesn’t exist for the computer, which is solved by putting the addeventhandler under the function Link to comment
Moderators IIYAMA Posted July 13, 2018 Moderators Share Posted July 13, 2018 (edited) Root is the top of the elements.(it is an element) https://wiki.multitheftauto.com/wiki/Element_tree Which represents the container of everything. If used in an addEventHandler, every element ingame is capable to trigger/activate it. More information about specifying the trigger range: Edited July 13, 2018 by IIYAMA Link to comment
Galactix Posted July 13, 2018 Share Posted July 13, 2018 Also make sure if your function is called changenick to use the same name in the handler and not something like wasNickChangedByUser Link to comment
kieran Posted July 13, 2018 Share Posted July 13, 2018 (edited) 3 hours ago, Galactix said: Also make sure if your function is called changenick to use the same name in the handler and not something like wasNickChangedByUser When nesting a function in an event handler like this, don't use the function name. Just do the following. addEventHandler("onPlayerChangeNick", getRootElement(),wasNickChangedByUser)--wasNickChangedByUser is the function name. function wasNickChangedByUser()--removed onPlayerChangeNick, within these brackets you only pass returns from event handlers, functions etc. outPutChatBox ( " Your have been changed your nickname " ) end oldNick and newNick are what this event handler returns, an event handler is just something that happens when a player does a certain action (or event) and it handles that event with the function. So when the function happens the event handler passes the players old name, and new name to the function. Make sure you check the returns part of wiki page. Hope that made it a bit clearer to you. Edited July 13, 2018 by kieran Link to comment
Galactix Posted July 13, 2018 Share Posted July 13, 2018 (edited) 18 minutes ago, kieran said: When nesting a function in an event handler like this, don't use the function name. Which is what I said in my first post. Edited July 13, 2018 by Galactix Link to comment
kieran Posted July 13, 2018 Share Posted July 13, 2018 @GalactixI read his script wrong, I thought the bracket was at the end of the function... Nesting is the second example he gave on original post, where you just put the word function under or beside the element that is triggering handler (separated by a comma of course), and then you add a closing bracket at the end of your function, below it or as most do (as it's proper way), you add it to the end of the last end in that function.... If that makes sense. I forgot to take that line out my post when I edited it. 1 Link to comment
Galactix Posted July 13, 2018 Share Posted July 13, 2018 Oh alright, I get what you meant now, but I wasn't talking of the nesting in my second post, which is why you were confused. 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