..:D&G:.. Posted December 17, 2017 Share Posted December 17, 2017 Hi, so I'm trying to make a script where I store some group names, ids of players within that group and the RGB for the outputChatBox. Here's my table: local groups = { fondatori = { name = "Fondator|Dev |", ids = {1, 3, 54, 85}, -- ID Of Players RGB = {0, 153, 255} -- RGB }, fondatori2 = { name = "Fondator|Hosting", ids = {2}, RGB = {0, 153, 255} B }, hosteri = { name = "Hoster |", ids = {9}, RGB = {204, 0, 102} }, scripteri = { name = "Scripter |", ids = {46}, RGB = {204, 0, 102} }, admini = { name = "Admin |", ids = {}, RGB = {255, 0, 0} }, } So I want to loop through every group and if the player is in one of those groups have an outputChatBox like so: outputChatBox("Fondator|Dev | ..:D&G:.. says hello!",0, 153, 255) I know how to loop through a table, but not a table withing a table within a table... I tried and it's so confusing and my head hurts, maybe someone smarter than me can do this Link to comment
DNL291 Posted December 17, 2017 Share Posted December 17, 2017 (edited) local groups = { fondatori = { name = "Fondator|Dev |", ids = {1, 3, 54, 85}, RGB = {0, 153, 255} }, fondatori2 = { name = "Fondator|Hosting", ids = {2}, RGB = {0, 153, 255} } } for _,group in pairs(groups) do local r,g,b = unpack(group.RGB) outputChatBox( group.name ) outputChatBox( r..", "..g..", "..b ) end Edited December 17, 2017 by DNL291 Link to comment
..:D&G:.. Posted December 17, 2017 Author Share Posted December 17, 2017 (edited) 6 minutes ago, DNL291 said: local groups = { fondatori = { name = "Fondator|Dev |", ids = {1, 3, 54, 85}, RGB = {0, 153, 255} }, fondatori2 = { name = "Fondator|Hosting", ids = {2}, RGB = {0, 153, 255} } } for _,group in pairs(groups) do local r,g,b = unpack(group.RGB) outputChatBox( group.name ) outputChatBox( r..", "..g..", "..b ) end But how about the IDs of the players from ids = {}? I need to check if the player has his ID in any of the groups because if the player is not in one of the groups, the outputChatBox should be like this: for _,group in pairs(groups) do local r,g,b = unpack(group.RGB) if (playerID == (one of the ids from ids = {}) then outputChatBox( group.name.." ..:D%G:.. says: Hello World", r, g, b ) else outputChatBox("Civilian | ..:D%G:.. says: Hello World", 255, 255, 0 ) end end Thanks. Edited December 17, 2017 by ..:D&G:.. Link to comment
DNL291 Posted December 17, 2017 Share Posted December 17, 2017 Try this: for _,group in pairs(groups) do if isPlayerIDInGroup( playerID, group.ids ) then outputChatBox( group.name.." ..:D%G:.. says: Hello World", r, g, b ) else outputChatBox("Civilian | ..:D%G:.. says: Hello World", 255, 255, 0 ) end end function isPlayerIDInGroup( id, IDsTable ) for i=1, #IDsTable do if IDsTable[i] == tonumber(id) then return true end end return false end Link to comment
..:D&G:.. Posted December 18, 2017 Author Share Posted December 18, 2017 If the user's ID is in one of the groups, it shows the outputChatBox with the name of that group, but also Civilian... Life, I have 3 groups ("Founder", "Admin" and "Scripter") and if I put my ID in "Scripter" the chatbox is like this: Civilian| ..:D&G:.. says: Hello world! -- Founder Group Civilian| ..:D&G:.. says: Hello world! -- Admin Group Scripter| ..:D&G:.. says: Hello world! -- Scripter Group (My ID is in this group only) 1 Link to comment
Jayceon Posted December 18, 2017 Share Posted December 18, 2017 (edited) E: local groups = { fondatori = { name = "Fondator|Dev |", ids = {1, 3, 54, 85}, RGB = {0, 153, 255} }, fondatori2 = { name = "Fondator|Hosting", ids = {2}, RGB = {0, 153, 255} } } function isPlayerIDInGroup( id, IDsTable ) for i=1, #IDsTable do if IDsTable[i] == tonumber(id) then return true end end return false end local groupFound = false for _,group in pairs(groups) do if isPlayerIDInGroup( playerID, group.ids ) then groupFound = group break end end if groupFound then local r,g,b = unpack(groupFound.RGB) outputChatBox(groupFound.name.." ..:D%G:.. says: Hello World", r, g, b ) else outputChatBox("Civilian | ..:D%G:.. says: Hello World", 255, 255, 0 ) end Edited December 18, 2017 by Jayceon Link to comment
..:D&G:.. Posted December 18, 2017 Author Share Posted December 18, 2017 I managed to fix it anyway, thanks Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now