dzek (varez) Posted February 27, 2010 Posted February 27, 2010 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..
Callum Posted February 27, 2010 Posted February 27, 2010 Do a cancelEvent(), then do your name change, like the following: function chanceNick () cancelEvent() setPlayerName ( source, "Bob" ) end addEventHandler ( "onPlayerChangeNick", getRootElement(), changeNick )
dzek (varez) Posted February 27, 2010 Author Posted February 27, 2010 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
Callum Posted February 27, 2010 Posted February 27, 2010 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.
dzek (varez) Posted February 27, 2010 Author Posted February 27, 2010 (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 February 27, 2010 by Guest
Callum Posted February 27, 2010 Posted February 27, 2010 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.
dzek (varez) Posted February 27, 2010 Author Posted February 27, 2010 same thing.. look at my edit.. you cant cancelEvent if nick change was caused by script (look at wiki) https://wiki.multitheftauto.com/wiki/OnPlayerChangeNick going to sleep now, ill try again tommorow
robhol Posted February 28, 2010 Posted February 28, 2010 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.
lil Toady Posted February 28, 2010 Posted February 28, 2010 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
dzek (varez) Posted February 28, 2010 Author Posted February 28, 2010 oh, right lil Toady, thanks ;D that was so simple 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)
karlis Posted February 28, 2010 Posted February 28, 2010 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
dzek (varez) Posted February 28, 2010 Author Posted February 28, 2010 well, its ok now, as this was a bit bigger,than blocking the change and change it via script, and i do some "ifs" etc and its ok. thanks everyone
Callum Posted February 28, 2010 Posted February 28, 2010 thats so simpleif 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 ".
dzek (varez) Posted February 28, 2010 Author Posted February 28, 2010 ok,but not player trigger that change name, so it wont be blocked clientside
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