Jump to content

change nick on nick change and dont get into infinite loop


dzek (varez)

Recommended Posts

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.

Link to comment

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.

Link to comment

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

Link to comment

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)

Link to comment
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 ".

Link to comment

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