I'm trying to have a command that when I type it, my name is changed to a name of a random person on the server. I have two problems: 1. Immediately when the name is changed, it changes back to my old name. 2. It will select [I][i]my[/I][/i] name sometimes. I need someone to fix both of these problems or tell me what's wrong. Thank you.
[lua]randomname = false
local orig = LocalPlayer():Nick()
concommand.Add("GAT_RandomName", function()
local randname = (table.Random( player.GetAll() ):Nick() .. " ")
if randomname then
LocalPlayer():ChatPrint("Your Name Has Been Set Back To Your Original Name")
RunConsoleCommand("setinfo", "name", orig)
randomname = !randomname
return
end
if !randomname then
if randname == LocalPlayer():Nick() then
local randname = (table.Random( player.GetAll() ):Nick() .. " ")
else
RunConsoleCommand("setinfo", "name", randname)
LocalPlayer():ChatPrint("Your Name Has Been Set To A Random Person's Name In Your Server")
randomname = !randomname
end
return
end
end)[/lua]
Put it in a think hook because garry made it so it sets your name back server second or so
Thanks. Good info. Will try that now.
[editline]12:06PM[/editline]
Okay, I have this now. It works perfectly, but it keeps on changing to a random name, while I just want it to change the name once. When I disable it, it works fine and switches back to your regular name.
[lua]randomname = false
nameselected = 0
function RandomName()
if randomname == false then
randomname = false
elseif randomname then
if nameselected == 0 then
randname = (table.Random(player.GetAll()):Nick().." ")
nameselected = 1
elseif randname == LocalPlayer():Nick() then
nameselected = 0
elseif randname != LocalPlayer():Nick() and nameselected == 1 then
RunConsoleCommand("setinfo", "name", randname)
end
end
end
hook.Add("Think", "randomnamehook", RandomName)
concommand.Add("GAT_RandomName", function()
if randomname then
randomname = !randomname
LocalPlayer():ChatPrint("GAT Random Name Disabled")
else
randomname = !randomname
LocalPlayer():ChatPrint("GAT Random Name Enabled")
end
end)[/lua]
Separate your functions, make one get a random name, make the other one actually sit around and constantly change it.
Grr... Was hoping I didn't have to do that.
[editline]12:27PM[/editline]
I'll let you guys know how it turns out.
[editline]12:34PM[/editline]
I turned it into this, but it's still doing the same thing (I will be gone for about an hour/two, so I won't reply until then):
[lua]hasname = 0
function RandomNameGet()
if hasname == 0 then
randname = (table.Random(player.GetAll()):Nick().." ")
hasname = 1
else
end
end
function RandomName()
if randomname then
RunConsoleCommand("setinfo", "name", randname)
else end
end
hook.Add("Think", "randomnamehook", RandomName)
concommand.Add("GAT_RandomName", function()
if randomname then
randomname = !randomname
LocalPlayer():ChatPrint("GAT Random Name Disabled")
else
randomname = !randomname
LocalPlayer():ChatPrint("GAT Random Name Enabled")
hasname = 0
end
end)[/lua]
Try this.
[lua]local nick = {}
local function GenName()
local pl = table.Random(player.GetAll())
while pl == LocalPlayer() do
pl = table.Random(player.GetAll())
end
return pl:Nick().. " "
end
hook.Add("Think" , "SetName" , function()
nick.Name = nick.Name or GenName()
if nick.Enabled and nick.Name then
RunConsoleCommand("Setinfo" , "name" , nick.Name)
end
end )
local function ToggleName()
nick.Enabled = not(nick.Enabled)
nick.Name = GenName()
end
concommand.Add("GAT_RandomName" , ToggleName)[/lua]
And where do I put my ChatPrint Notifications?
[editline]02:48PM[/editline]
It works perfectly. All I need are the ChatPrint notifications, but I don't want to screw it up. Where should I put them?
[editline]02:52PM[/editline]
Nevermind. Just put checks in to see if it was enabled. Thank you for your help!
Sorry, you need to Log In to post a reply to this thread.