Hey all, I'm working on an admin mod for fun, and I'm working on a set rank command. It works fine and all, but I'm having a problem.
I have it grabbing all the rank names from the mySql database, and putting them in a table (POAM.LRanks) to search args on the command and compare. But I'm having trouble having it grab the args if there's a space in the rank name, and also an issue with ranks with mixed capitals (such as iPro, or something)
I have some ideas on how to fix this, but I have a feeling my code is very unoptimized, so I have come to you guys for some advice on how to do this. Here's my code right now:
[lua]
local COMMAND = {}
COMMAND.Name = "SetRank"
COMMAND.Flag = "O"
COMMAND.Desc = "Change a players Rank."
COMMAND.Args = "Player,Rank"
COMMAND.argz = ""
function COMMAND.Command(ply,args)
if ply:IsPlayer() then
COMMAND.ply = ply:Nick()
else
COMMAND.ply = "Console"
end
local plr = POAM.FindPlayer(ply,args[2])
COMMAND.argz = ""
for k,v in pairs(args) do
if k > 2 then
local stl2 = string.Trim(string.Left(string.upper(v),1))
local str2 = string.Right(string.lower(v),string.len(v) - 1)
COMMAND.argz = COMMAND.argz .. stl2..str2 .. " "
end
end
args[3] = string.Trim(COMMAND.argz)
if table.HasValue(POAM.LRanks,args[3]) then
if plr then
plr:SetNetworkedString( "rank", args[3])
//POAM.SetLimits(plr)
for k,v in ipairs(player.GetAll()) do
v:ChatPrint(COMMAND.ply.." has changed "..plr:Nick().."'s rank to "..args[3])
v:SendLua("chat.PlaySound()")
end
POAM.SavePlayer(plr)
end
else
if ply:IsPlayer() then
ply:ChatPrint("Sorry, but "..string.upper(args[3]).." is not a valid rank.")
else
print("Sorry, but "..args[3].." is not a valid rank.")
end
end
end
POAM.Register(COMMAND)[/lua]
[editline]04:09PM[/editline]
Oh also, it would need to be formated back into the right capitalization to be added to the database somehow.
So the problem is spaces in the command name? As far as I can tell this is going to be run as a console command, so you could put quotes around the rank name if it has a space in it. As for capitalization, I must be dumb because I don't understand the problem. If you're allowing A and a to be different ranks, they have to type it right.
Well, I'm doing it as chat commands too. But if there's no easy way to fix this, I'll just keep it as a concommand in a menu.
Yeah, if parameters are delimited by spaces then it's going to be kinda hard to determine whether two words were meant to be the same parameter or not, afaik.
Oh wells. Thanks for the help :)
Sorry, you need to Log In to post a reply to this thread.