fairyoggy Posted August 15, 2019 Share Posted August 15, 2019 (edited) 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 August 15, 2019 by slapz0r Link to comment
Lachuks Posted August 15, 2019 Share Posted August 15, 2019 You want to list them with dxDraw or in chat? I dont rly understand Link to comment
fairyoggy Posted August 15, 2019 Author Share Posted August 15, 2019 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
Lachuks Posted August 15, 2019 Share Posted August 15, 2019 (edited) 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 August 15, 2019 by Emix Link to comment
VenomOG Posted August 15, 2019 Share Posted August 15, 2019 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 Link to comment
Scripting Moderators ds1-e Posted August 15, 2019 Scripting Moderators Share Posted August 15, 2019 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 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. 2 Link to comment
Addlibs Posted August 15, 2019 Share Posted August 15, 2019 (edited) 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 August 15, 2019 by MrTasty 2 Link to comment
Lachuks Posted August 15, 2019 Share Posted August 15, 2019 1 minute ago, majqq said: Can you guys tell me how this is supposed to work? Using server-side functions at client-side. Woops my bad. I can rewrite it if ya want @slapz0r . ( PM me if needed ) 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