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

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

Posted

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

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

Retired

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

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

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.

Retired

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

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

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.

Retired

Posted

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

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

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.

Do NOT PM ME for help unless invited. - New MTA Script Editor

Scripting help "etiquette": understandable language, relevant code (ALL code if unsure), [Lua] tags, error messages with line numbers. Super simple stuff.

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

Do not PM me, im not going to read it anyway.

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)

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

Posted

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

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

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

Retired

Posted

ok,but not player trigger that change name, so it wont be blocked clientside

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

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