Jump to content

Help Roleplay names!


xScatta

Recommended Posts

Hey code here problem below:

names = {"James","John","Johnny","Cesar"} 
subnames = {"Rodriguez","Johnshon","Thomson","Black"} 
  
function nick() 
players = getElementsByType("player") 
setPlayerNametagText(players,math.random(names).."_"..math.random(subnames)) 
end 
  
addCommandHandler("rpnick",nick) 

i want to script random the names and subnames for every player but idk how to use ipairs :/

Link to comment
  
local names = {"James","John","Johnny","Cesar"} 
local subnames = {"Rodriguez","Johnshon","Thomson","Black"} 
  
function nick() 
    local players = getElementsByType("player") 
    local nbrNames = table.getn(names) 
    local nbrSubnames = table.getn(subnames) 
    for i, player in pairs(players) do 
        setPlayerNametagText(player, ""..names[math.random(nbrNames)].."_"..subnames[math.random(nbrSubnames)].."") 
    end 
end 
addCommandHandler("rpnick",nick) 
  

Tested, if you want allow the command only for admin :

  
local names = {"James","John","Johnny","Cesar"} 
local subnames = {"Rodriguez","Johnshon","Thomson","Black"} 
  
function nick(thePlayer) 
    local accountname = getAccountName(getPlayerAccount(thePlayer)) 
    if isObjectInACLGroup("user."..accountname, aclGetGroup("Admin")) then 
        local players = getElementsByType("player") 
        local nbrNames = table.getn(names) 
        local nbrSubnames = table.getn(subnames) 
        for i, player in pairs(players) do 
            setPlayerNametagText(player, ""..names[math.random(nbrNames)].."_"..subnames[math.random(nbrSubnames)].."") 
        end 
    end 
end 
addCommandHandler("rpnick",nick) 
  

Enjoy

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