Jump to content

Random Player Nick


proracer

Recommended Posts

Okay I'm trying to test when someone enters server with nick: "Player" it sets random nick from: "Player1 to "Player1000".

But it doesn't work with too many errors.

function randomPlayerNick() 
local joinedPlayerName = getPlayerName (source) 
local newPlayerName = math.random (Player1, Player1000) 
if getPlayerName == "Player" then 
do setPlayerName ( thePlayer, newPlayerName )  
elseif getPlayerName ~== "Player" then 
return  
end  
end  
  
addEventHandler ( "onPlayerJoin", getRootElement(), randomPlayerNick) 

Im using MTA Script Editor so it's easier to find errors.One error is that I need to end "do" statement and with "end" but I don't know how.Every time I put "end" somewhere it closes statement "if".Just too many errors, please any help will be appreciated. :P Still learning.

Link to comment
function renamePlayer () 
    if ( string.lower ( getPlayerName ( source ) ) == string.lower ( "Player" ) ) then 
        local name = "Player_" .. math.random ( 1, 99 ) 
            while getPlayerFromName ( name ) do 
                local name = "Player_" .. math.random ( 1, 99 ) 
            end 
        setPlayerName ( source, name ) 
    end 
end 
addEventHandler ( "onPlayerJoin", getRootElement(), renamePlayer ) 

Link to comment
Thx for this but can you please put comments because I don't just want script, I wanna learn.I wanna understand why is that :P.Thx for help :mrgreen:

here:

function renamePlayer() 
  -- first we check if player name is "Player" or "pLayEr", by lowering the case 
  -- using string.lower() and comparing the result with "player": 
  if string.lower(getPlayerName(source)) == "player" then  
    -- then we generate a string with new name like "Player_35" and put it in local variable: 
    local name = "Player_" .. math.random(1, 99)  
    -- this will generate a new name if a player with previously generated name already exists: 
    while getPlayerFromName(name) do 
      name = "Player_" .. math.random(1, 99) 
    end 
    -- setting a new player name from local name variable: 
    setPlayerName(source, name) 
  end 
end 
addEventHandler ( "onPlayerJoin", getRootElement(), renamePlayer) 

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