How can i get the index of a dictionary?

Hey,

I am making an admin commands model called “True Admin”
and i made a “settings” module.

  1. What do you want to achieve?
    I want to get the index from this dictionary table

Module

--|RANKS|---
-- Manual ranks
-- YOU DO NOT HAVE TO PUT YOUR SELF ANYWHERE HERE!
setting.Ranks = {
	['Owner'] = {'Beez_up'}; --1
	['Moderator'] = {}; -- 2
	['Head Admin'] = {}; -- 3
	['Admin'] = {}; -- 4
	['VIP'] = {}; -- On himself only -- 5
	['NonAdmins'] = {} -- 6
}
  1. What is the issue?

Script

function getRanks(plr)
	local a,g
	for k,v in pairs(ranks) do
		if table.find(v,plr.Name) then
			a = k.index
			break
		end
	end
	for k,v in pairs(Group_Admins) do
		if table.find(v,plr:GetRankInGroup(groupID)) then
			g = k
			break
		end
	end
	return a,g
end

This function returns the rank of the player in the group
and the rank of that player in the module “Ranks” so i can know if the player can run the command
The issue is that in a = k.index return nil also i dont want it to return the key because
i cant use if 'Owner' >=4 then it will be simpler if it return a number.
Groups_Admins works well.

Thanks for reading :smiley:

I cant show the module and the script because its too long.

Dictionaries don’t have an “order”. You will have to define the permissions level differently.

Try something like this; where the index of the dictionary is the name, then the value is a dictionary with a “PermissionLevel” index, and then a “Users” list.

settings.Ranks = {
    Owner = {
        PermissionLevel = 1,
        Users = {
            "Beez_up"
        }
    },
    Moderator = {
        PermissionLevel = 2,
        Users = {
            
        }
    },
    --// and so on
}
1 Like

oh, I think I misunderstood your question.

The index of the table will be the first parameter in a pairs loop.

local dictionary = {
    hello = "abc",
    world = "ok",
    cheeseburger = "yum"
}

for index, value in pairs(dictionary) do
    print(index)
end

will output:
hello
world
cheeseburger

2 Likes

Thanks i will try that! :happy4: