So, I've been working on a lua script that'll grab all users and their groups and if they're donator or up (admins, superadmins, coowner etc) then it'll add them to my database. So far everything is working other than giving the groups an ID.
How I define said groups to put in database:
[CODE]local GROUPS = { "serveradmin", "luminary", "architect", "superadmin", "admin", "donator" }[/CODE]
To loop through the users and their groups I use this (Made by CallMePyro):
[CODE]
for k, v in pairs(ULib.ucl.users) do //Loop through ULib user file
local row = ULib.ucl.users[k] //Define the row of the current selected user
if string.find(row['group'], "donator") then //Check if rank conatins donator
row['groups'] = "donator"; //If does then change their rank to donator
end
if table.HasValue(GROUPS, row['group']) then //If there group is in the table GROUPS
(Inserting n' shit)
end
end[/CODE]
So far when it inserts it puts in their group name. What I need is to add an ID to the different groups. What I was using was:
[CODE]local IDs = { ["serveradmin"] = 1, ["luminary"] = 2, ["architect"] = 3, ["superadmin"] = 4, ["admin"] = 5, ["donator"] = 6 }[/CODE]
I've tried a couple of ways but every way I've done has added everyone in said groups 6 times to the database.
And help would be appreciated, thanks.
Well by doing this line:
[code]local IDs = { ["serveradmin"] = 1, ["luminary"] = 2, ["architect"] = 3, ["superadmin"] = 4, ["admin"] = 5, ["donator"] = 6 }[/code]
that doesn't really make sense so you don't wanna have them inside the ' [ ] ', because that returns to an index, maybe you want to do:
[code]local IDs = { GROUPS[1] = 1, GROUPS[2] = 2, GROUPS[3] = 3, GROUPS[4] = 4, GROUPS[5] = 5, GROUPS[6] = 6 }[/code]
Al tho I'm not really sure if you are exactly trying to do that but this gets the idea across that you are not really returning to anything, or it returns nil, you need to understand how tables works just like this: TABLE[Index].OtherIndex[extraindex]..... thats if you have a lot of tables withing tables, but in your case you only have:
TABLE[index], now you dont really need 2 tables for this one, you can make one table and just do:
ID = { serveradmin= 1, luminary = 2, ......... etc }
if you print this,
[CODE]print(ID[superadmin])[/CODE]
you would get '1'
So you can use this to make indexes with strings instead of numbers which i find it more useful creating these type of table or arrays..
Hope you understood all this
-luamaster
If you're trying to assign numeric values to each ULX usergroup, I would suggest making a function to return said value.
[CODE]
function getRankID(ply)
if ply:GetNWString("usergroup") == "serveradmin" then
return 0
elseif ply:GetNWString("usergroup") == "luminary" then
return 1
//And so on for each rank
end
[/CODE]
You could then use that with a for loop to check each player's rank and do whatever you want with them.
Im not sure how efficient this method is and there probably is a better way to do it but this works for me.
I've gotten it working, luamaster pointed me in the right direction. When a table is made every value on the table is already given an index number so all I have to do is "for k, v in pairs(GROUPS) do". Although that was the first thing I tired I didn't realise that k would be an index number.
Thanks for the help guys!
Sorry, you need to Log In to post a reply to this thread.