Jump to content


Recommended Posts

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 " )

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)

But what's is  " root, "

and why in some script there is

function testmod (oldNick, newNick)

And other script only

	function(oldNick, newNick)


Edited by Guest
Link to post

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 post
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 " )

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 by kieran
Link to post

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

  • Haha 1
Link to post

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