Jump to content

change nick on nick change and dont get into infinite loop


dzek (varez)

Recommended Posts

Posted

well, im trying to set nickname if somebody change his nickname (i dont want to block nickchanging btw)

but when i add event handler to onPlayerChangeNick, and inside i chage his nick, im going into infinite loop :(

im trying for 60 mins and no good results..

Posted

Do a cancelEvent(), then do your name change, like the following:

function chanceNick ()
cancelEvent()
setPlayerName ( source, "Bob" )
end
addEventHandler ( "onPlayerChangeNick", getRootElement(), changeNick )

Posted

i know about that, but it cant help me ..

function onChangeNick(old,new)
cancelEvent()
setPlayerName(source,new)
end
 
addEventHandler("onPlayerChangeNick", getRootElement(), onChangeNick)

edit: wow, you edited ;p

Posted

It definately works (maybe the other way around (script then cancelEvent())), because I used that in my "HEX_Removal" script in community. See that for a working example. Otherwise, I don't see how it won't work, unless you're trying to do something more than you're telling us.

Posted (edited)

i just did what is above.. and it changes the nick indeed, but its get an infinite loop, then C Stack Overflow

well, your script stops infinite loop becouse of

if ( string.find ( name, "#%x%x%x%x%x%x" ) ) then

..

Edited by Guest
Posted

Try your name change then cancelEvent(), I've just figured you're cancelling the name change, then you're changing the name, which would trigger another onPlayerChangeNick, and that will cause an infinate loop.

Posted

Seems reasonably easy to "hack around" to me. When you change someone's nick, temporarily set a variable for the player; the value can be the new name you set for him. Then in the handler function, do something like

if newNick == storedNewNick then return; end

Maybe there should be a "bool scripted" argument to onPlayerChangeNick, though. Would avoid this whole mess.

Posted

remove the event handler when changing the nick

function onPlayerChangeNick ( old, new )
removeEventHandler ( "onPlayerChangeNick", getRootElement(), onPlayerChangeNick )
setPlayerName ( source, "something" )
addEventHandler ( "onPlayerChangeNick", getRootElement(), onPlayerChangeNick )
end
 
addEventHandler ( "onPlayerChangeNick", getRootElement(), onPlayerChangeNick )

yeah, looks a bit ugly but thats gonna work. Could as well hook that code into setPlayerName function so no call to it in the script triggers the event

Posted

oh, right lil Toady, thanks ;D that was so simple :P

edit NO NO NO! this seems not to work :/

function onPlayerChangeNick (old, new)

outputDebugString("1")

removeEventHandler("onPlayerChangeNick", getRootElement(), onPlayerChangeNick)

setPlayerName(source, "something")

addEventHandler("onPlayerChangeNick", getRootElement(), onPlayerChangeNick)

end

addEventHandler ("onPlayerChangeNick", getRootElement(), onPlayerChangeNick)

this change my nick once, and get into infinite loop, console is spammed with "1" message, and after some sec in the game *NETWORK TROUBLE* appears..

this infinite loop isnt broke by some kind of protection in mta like in

while (1~=2) do  outputDebugString("2") end

(something like that stops after about 1000 loops? not sure how much)

Posted
thats so simple

if newnick~=oldnick then changenick, it will be same if u change it once and then going in loop to change it again

I thought if the oldNick is the same as the newNick onPlayerChangeNick won't be triggered because the client just gets an error like "Your nick is already ".

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