Master_11

Loop through the account table and ACL Group.

Recommended Posts

Hi, I am facing a problem in making this small script, well my Idea is to show all the accounts added in an ACL group to a GUI grid list, for example

 group 'admin' and I want all the account Names present in that ACL group to show in the grid list even if the player is offline.

 

Client:

function GetAccList(accName)
if (not accName) then
	return false
end
		local acsrow = guiGridListAddRow(AccountList)
		guiGridListSetItemText(AccountList, acsrow, accNameCol, accName, false, false)
		guiGridListSetItemText(AccountList, acsrow, accNameCol, plrName, false, false)
end
addEvent("GetACSList", true)
addEventHandler("GetACSList", root, GetAccList)

 

Server:

function OutputaccList(client, accName, plrName)
local ACSList = {}
local accountTable = getAccounts()
	for theKey, theAccount in pairs (accountTable) do
		local thePlayer = getAccountPlayer(theAccount)
		 accountname = getAccountName(getPlayerAccount(thePlayer))
		if (not isObjectInACLGroup("user."..accountname, aclGetGroup("Admin"))) then
			return false
		end
    			local plrName = getPlayerName(thePlayer)
    			local accName = accountname
			ACSList[accName] = plrname
	end
triggerClientEvent(client, "GetACSList", source, ACSList)
end
addCommandHandler("adminpanel", OutputaccList)

 

To open the panel the command is same "adminpanel".

Share this post


Link to post

Why not just use

aclGroupListObjects(aclGetGroup ("Admin"))

This will return all objects in the ACL group, with the prefix I believe, so now all you need to do is filter out everything other than what starts with "user."

When it comes to the code you posted above, you cannot use return in a loop in the way you used it on line 8. This aborts the loop, so as soon as an account that isn't in the admin group is iterated, the loop completely ends. In such loops, I believe the only way is to have all the code conditional on the if, rather than a return statement on the if.

Edited by MrTasty

Share this post


Link to post

I tried it, MrTasty and thanks it worked fine but the problem I face now is triggerClientEvent. This gives me an error of [Expected string at argument 1, got nil]

Here is my script

Client: 

function OutputAdminList(list)
adminlist = list
guiGridListClear(AccountList)

	local acclist = {}
	for k in pairs(adminlist) do table.insert(acclist, k) end
	table.sort(acclist)

	for i, k in ipairs(acclist) do
	local name = accName
		local row = guiGridListAddRow(AccountList, accName)
	end
end
addEvent("GetAdminList", true)
addEventHandler("GetAdminList", resourceRoot, OutputAdminList)

 

Server:  

function OutputAdminList(player)
	local adminlist = {}
    local group = aclGetGroup("Admin")
    if (not group) then
		return false
	end
        for i, object in ipairs(aclGroupListObjects(group) or {}) do
            local objType = gettok(object, 1, string.byte('.'))
            if (objType == "user") then
                local name = gettok(object, 2, string.byte('.'))
                table.insert(adminlist, name)
            end
        end
		triggerClientEvent(client, "GetAdminList", source, adminlist)
end
addCommandHandler("adminpanel", OutputAdminList)

 

Share this post


Link to post

Server Side Script line 14 replace 1st argument of "triggerClientEvent" to player and 3rd to resourceRoot

Edited by DeadthStrock

Share this post


Link to post
36 minutes ago, DeadthStrock said:

Server Side Script line 14 replace 1st argument of "triggerClientEvent" to player and 3rd to resourceRoot

Thanks, pal, it worked.

For those who may use this as a reference, I replaced client with:

function OutputAdminList(list, name)
adminlist = list
guiGridListClear(AccountList)
	for i, name in ipairs(adminlist) do
		local row = guiGridListAddRow(AccountList, name)
	end
end
addEvent("GetAdminList", true)
addEventHandler("GetAdminList", resourceRoot, OutputAdminList)

 

Share this post


Link to post

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.