Jump to content

Admins online in gridlist


fairyoggy

Recommended Posts

How do I list online administrators in a grid list?

For each administrator a new row.

I have such a code through a chat command, but how to make a glidlist

function refreshListAdmin()
	count = 0
	online = ""
	for i, v in ipairs(getElementsByType("player")) do
		if hasObjectPermissionTo(v,"function.setPlayerMuted",true) then
			online = getPlayerName(v).." "..online
			count = count+1
		end
	end
	return online, count	
end
addEvent("refreshListAdmin", true)
addEventHandler("refreshListAdmin", root, refreshListAdmin)

addCommandHandler("admins",
function(playerSource)
	admins, count = refreshListAdmin()
	outputChatBox("#1e90ffAdmins : #FFFFFF"..admins.."",playerSource,255,85,0,true)
end
)

 

Edited by slapz0r
Link to comment
2 minutes ago, Emix said:

You want to list them with dxDraw or in chat? I dont rly understand

in my code that this displays in the chat of administrators online but I need a list of administrators online in gridlist

For each administrator a separate row.

Example: There are 3 administrators on the server

in a gridlist will create 3 rows with their names.

 

Link to comment

Im not master but I guess this should be ok

local sW, sH = guiGetScreenSize()
function drawStaff()
	for i, v, in ipairs(getElementsByType("player")) do
		if hasObjectPermissionTo(v,"function.setPlayerMuted",true) then
			dxDrawRectangle(0,(sH/2)*i,sW*0.15,sH*0.05,tocolor(0,0,0,150))
			dxDrawText(getPlayerName(v),0,(sH/2)*i,sW*0.15,((sH/2)*i)+(sH*0.05),tocolor(255,255,255,255 ), 1, "default-bold","left","center",true, false,false,true)
		end
	end
end
addEventHandler("onClientRender", root, drawStaff)
Edited by Emix
Link to comment
local playerList = guiCreateGridList(0.80, 0.40, 0.15, 0.35, true)
guiGridListAddColumn(playerList, "Player", 0.85)

for _, player in ipairs(getElementsByType("player")  ) do
local accName = getAccountName ( getPlayerAccount ( player ) )
  if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Admin" ) do
	guiGridListAddRow(playerList, getPlayerName(player))
      end
end

Haven't coded in a while check this :D

Link to comment
  • Scripting Moderators
12 minutes ago, Knuck said:

local playerList = guiCreateGridList(0.80, 0.40, 0.15, 0.35, true)
guiGridListAddColumn(playerList, "Player", 0.85)

for _, player in ipairs(getElementsByType("player")  ) do
local accName = getAccountName ( getPlayerAccount ( player ) )
  if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Admin" ) do
	guiGridListAddRow(playerList, getPlayerName(player))
      end
end

Haven't coded in a while check this :D

 

13 minutes ago, Emix said:

Im not master but I guess this should be ok


local sW, sH = guiGetScreenSize()
function drawStaff()
	for i, v, in ipairs(getElementsByType("player")) do
		if hasObjectPermissionTo(v,"function.setPlayerMuted",true) then
			dxDrawRectangle(0,(sH/2)*i,sW*0.15,sH*0.05,tocolor(0,0,0,150))
			dxDrawText(getPlayerName(v),0,(sH/2)*i,sW*0.15,((sH/2)*i)+(sH*0.05),tocolor(255,255,255,255 ), 1, "default-bold","left","center",true, false,false,true)
		end
	end
end
addEventHandler("onClientRender", root, drawStaff)

Can you guys tell me how this is supposed to work? Using server-side functions at client-side.

What you should do is collect them in table, and send with trigger to client. 

  • Haha 2
Link to comment

Both posts above mix server-only functions with client-only functions. Smh.

--server
function refreshListAdmin()
  local onlineAdmins = {}
  for i, v in ipairs(getElementsByType("player")) do
    if hasObjectPermissionTo(v, "function.setPlayerMuted", true) then
      table.insert(onlineAdmins, getPlayerName(v))
    end
  end
  triggerClientEvent(client, "receiveListAdmin", client, onlineAdmins)
end
addEvent("refreshListAdmin", true)
addEventHandler("refreshListAdmin", root, refreshListAdmin)

--client
WINDOW_WITH_GRIDLIST = guiCreateWindow(...)
GRIDLIST = guiCreateGridList(...)
guiGridListAddColumn(GRIDLIST, "Admin Name", 0.85)

function showListAdmin()
  if guiGetVisible(WINDOW_WITH_GRIDLIST) then
    guiSetVisible(WINDOW_WITH_GRIDLIST, false) -- hide the window if it's already visible
    return
  end
  guiGridListClear(GRIDLIST)
  guiGridListAddRow(GRIDLIST, "Loading...") -- add a row that says "Loading..." while waiting for server to return the admins list
  guiSetVisible(WINDOW_WITH_GRIDLIST, true)
  triggerServerEvent("refreshListAdmin", localPlayer)
end
addCommandHandler("admins", showListAdmin)

function loadListAdmin(admins)
  if not guiGetVisible(WINDOW_WITH_GRIDLIST) then
    return -- don't continue if the user already closed the window
  end
  guiGridListClear(GRIDLIST) -- clear out the "Loading..." row
  if #admins > 0 then
    for k, v in pairs(admins) do
      guiGridListAddRow(GRIDLIST, v)
    end
  else
    guiGridListAddRow(GRIDLIST, "No admins online.")
  end
end
addEvent("receiveListAdmin", true)
addEventHandler("receiveListAdmin", root, loadListAdmin)

You'll need to incorporate this code into your existing code. Specifically, plug in the proper variables for your GUI window and gridlist.

Edited by MrTasty
  • Like 2
Link to comment

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.
×
×
  • Create New...