xXGhostXx Posted September 7, 2018 Share Posted September 7, 2018 (edited) Hi guys . please fix my script for on players join and after /login name changed to username . before login name : Guess,random number function GuessShodan() local adadshansi = math.random(9999,9999) setPlayerName(thePlayer, Guess#adadshansi ) end addEventHandler("onPlayerJoin",getRootElement(),GuessShodan) thanks. Edited September 7, 2018 by xXGhostXx Link to comment
Dimos7 Posted September 7, 2018 Share Posted September 7, 2018 function GuessShodan() local adadshansi = math.random(9999,9999) setPlayerName(source , Guess#adadshansi ) end addEventHandler("onPlayerJoin",root , GuessShodan) 1 Link to comment
Mr.Loki Posted September 7, 2018 Share Posted September 7, 2018 (edited) Not sure what you meant but here u go. local names = {} -- Create a tabe to save names when they join function GuessShodan( ) names[source] = getPlayerName( source ) -- Save the player's name in the table. giveRandomName( source ) -- Call our custom function to generate a random name and give it to the player. end addEventHandler( "onPlayerJoin", root, GuessShodan ) function giveRandomName( plr ) local newName -- Create a variable to store the name that is only visible within the function. repeat newName = math.random(1000,9999) -- Generate random number until not getPlayerFromName( "Guess_"..newName ) -- repeat the line above until no player with this name is found in the server setPlayerName( plr, "Guess_"..tostring(newName) ) -- Give the player the new name end function Restorenick( ) if names[source] then -- Check if the player is in the table setPlayerName( source, names[source] ) -- Set the player's name to the nick he had when joining names[source] = nil -- Remove the name from the table end end addEventHandler( "onPlayerLogin", root, Restorenick ) Edited September 7, 2018 by Mr.Loki Link to comment
xXGhostXx Posted September 8, 2018 Author Share Posted September 8, 2018 10 hours ago, Mr.Loki said: Not sure what you meant but here u go. local names = {} -- Create a tabe to save names when they join function GuessShodan( ) names[source] = getPlayerName( source ) -- Save the player's name in the table. giveRandomName( source ) -- Call our custom function to generate a random name and give it to the player. end addEventHandler( "onPlayerJoin", root, GuessShodan ) function giveRandomName( plr ) local newName -- Create a variable to store the name that is only visible within the function. repeat newName = math.random(1000,9999) -- Generate random number until not getPlayerFromName( "Guess_"..newName ) -- repeat the line above until no player with this name is found in the server setPlayerName( plr, "Guess_"..tostring(newName) ) -- Give the player the new name end function Restorenick( ) if names[source] then -- Check if the player is in the table setPlayerName( source, names[source] ) -- Set the player's name to the nick he had when joining names[source] = nil -- Remove the name from the table end end addEventHandler( "onPlayerLogin", root, Restorenick ) Worked . But players can change the name from MTA Setting ! I Want script for change the name to username /register . Link to comment
Mr.Loki Posted September 8, 2018 Share Posted September 8, 2018 4 hours ago, xXGhostXx said: Worked . But players can change the name from MTA Setting ! I Want script for change the name to username /register . You can cancel the event onPlayerChangeNick the first example on the page shows you how. Use this instead of the above code. function giveRandomName( ) local newName -- Create a variable to store the name that is only visible within the function. repeat newName = math.random(1000,9999) -- Generate random number. until not getPlayerFromName( "Guess_"..newName ) -- Repeat the line above until if player with this name is found. setPlayerName( source, "Guess_"..tostring(newName) ) -- Give the player the new name. end addEventHandler( "onPlayerJoin", root, giveRandomName ) function Restorenick( _, acc ) local accountName = getAccountname(acc) -- get the name of the account they logged in with setPlayerName( source, accountName ) -- Set the player's name to his account name. end addEventHandler( "onPlayerLogin", root, Restorenick ) Link to comment
xXGhostXx Posted September 8, 2018 Author Share Posted September 8, 2018 1 hour ago, Mr.Loki said: You can cancel the event onPlayerChangeNick the first example on the page shows you how. Use this instead of the above code. function giveRandomName( ) local newName -- Create a variable to store the name that is only visible within the function. repeat newName = math.random(1000,9999) -- Generate random number. until not getPlayerFromName( "Guess_"..newName ) -- Repeat the line above until if player with this name is found. setPlayerName( source, "Guess_"..tostring(newName) ) -- Give the player the new name. end addEventHandler( "onPlayerJoin", root, giveRandomName ) function Restorenick( _, acc ) local accountName = getAccountname(acc) -- get the name of the account they logged in with setPlayerName( source, accountName ) -- Set the player's name to his account name. end addEventHandler( "onPlayerLogin", root, Restorenick ) Worked but i player name changed to Guess Random Number ! i want after Login Guess and before login Set name to Username Link to comment
Mr.Loki Posted September 8, 2018 Share Posted September 8, 2018 16 hours ago, xXGhostXx said: on players join and after /login name changed to username . before login name : Guess,random number Link to comment
xXGhostXx Posted September 8, 2018 Author Share Posted September 8, 2018 2 minutes ago, Mr.Loki said: what ? 12 minutes ago, xXGhostXx said: Worked but i player name changed to Guess Random Number ! i want after Login Guess and before login Set name to Username addEventHandler("onPlayerChangeNick", getRootElement(), function() cancelEvent(); end ); this is code ? Link to comment
Mr.Loki Posted September 8, 2018 Share Posted September 8, 2018 addEventHandler("onPlayerChangeNick", getRootElement(), function(oldNick, newNick, changedByUser) if changedByUser then -- check if the nickname was changed by the user cancelEvent() end end ); Link to comment
xXGhostXx Posted September 8, 2018 Author Share Posted September 8, 2018 11 minutes ago, Mr.Loki said: addEventHandler("onPlayerChangeNick", getRootElement(), function(oldNick, newNick, changedByUser) if changedByUser then -- check if the nickname was changed by the user cancelEvent() end end ); Not Work Link to comment
xXGhostXx Posted September 10, 2018 Author Share Posted September 10, 2018 Please answer me Link to comment
Dimos7 Posted September 10, 2018 Share Posted September 10, 2018 function giveRandomName( ) local newName -- Create a variable to store the name that is only visible within the function. repeat newName = math.random(1000,9999) -- Generate random number. until not getPlayerFromName( "Guess_"..newName ) -- Repeat the line above until if player with this name is found. setPlayerName( source, "Guess_"..tostring(newName) ) -- Give the player the new name. end addEventHandler( "onPlayerJoin", root, giveRandomName ) function Restorenick(_, acc) local accountName = getAccountName(acc) -- get the name of the account they logged in with setPlayerName( source, accountName ) -- Set the player's name to his account name. end addEventHandler( "onPlayerLogin", root, Restorenick ) Link to comment
xXGhostXx Posted September 10, 2018 Author Share Posted September 10, 2018 7 hours ago, Dimos7 said: function giveRandomName( ) local newName -- Create a variable to store the name that is only visible within the function. repeat newName = math.random(1000,9999) -- Generate random number. until not getPlayerFromName( "Guess_"..newName ) -- Repeat the line above until if player with this name is found. setPlayerName( source, "Guess_"..tostring(newName) ) -- Give the player the new name. end addEventHandler( "onPlayerJoin", root, giveRandomName ) function Restorenick(_, acc) local accountName = getAccountName(acc) -- get the name of the account they logged in with setPlayerName( source, accountName ) -- Set the player's name to his account name. end addEventHandler( "onPlayerLogin", root, Restorenick ) Not Work ! Link to comment
Dimos7 Posted September 10, 2018 Share Posted September 10, 2018 any error or warning? 7 minutes ago, xXGhostXx said: Not Work ! Link to comment
xXGhostXx Posted September 10, 2018 Author Share Posted September 10, 2018 10 minutes ago, Dimos7 said: any error or warning? Debug error: ERROR: Loading script failed: guess/server.lua:9: unexpected symbol near ' Link to comment
#STARK Posted September 10, 2018 Share Posted September 10, 2018 addEventHandler("onPlayerJoin", root, function() local newName = "Guest#"..math.random(1000,9999) repeat newName = "Guest#"..math.random(1000,9999) until not getPlayerFromName(newName) setPlayerName(source, newName) end ) addEventHandler("onPlayerLogin", root, function(_,account) local accountName = getAccountName(account) setPlayerName(source, tostring(accountName)) end ) addEventHandler("onPlayerChangeNick", root, function() cancelEvent() end ) Link to comment
JeViCo Posted September 12, 2018 Share Posted September 12, 2018 #optimized guests = {} addEventHandler("onPlayerJoin", root, function() local newName = "Guest#"..math.random(9999) if not guests[newName] then setPlayerName(source, newName) guests[newName] = true end end ) addEventHandler("onPlayerLogin", root, function(_,account) guests[getPlayerName(source)] = nil local accountName = getAccountName(account) setPlayerName(source, tostring(accountName)) end ) addEventHandler("onPlayerChangeNick", root, function() cancelEvent() end ) @xXGhostXx Link to comment
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