Jump to content

[Help] Onlin Admin


Stranger

Recommended Posts

hello, i need a help in this code

that,

i can't make it add more than one admin on the list

i don't know the problem

i want it If the player is logged in and the player an admin then

he will be added to the list of online admin

it work but not showing more than one

and if he logged out

his name still in the list

so , help.

the code client side:

adm = false 
  
addEvent ("heAdmin", true) 
addEventHandler ("heAdmin", root, 
function () 
adm = true 
end) 
  
addEvent ("notAdmin", true) 
addEventHandler ("notAdmin", root, 
function () 
adm = false 
end) 
  
function as () 
guiSetVisible(staf,not guiGetVisible(staf)) 
showCursor(not isCursorShowing()) 
if (adm == false) then 
guiGridListClear (gstaf) 
setTimer (function () 
local row = guiGridListAddRow ( gstaf ) 
guiGridListSetItemText ( gstaf, row, co, "No admin online", false, false ) 
guiGridListSetItemColor(gstaf, row, co, 255, 0,0, 255) 
guiGridListSetItemText ( gstaf, row, co2, "Offline", false, false ) 
guiGridListSetItemColor(gstaf, row, co2, 255, 0,0, 255) 
end, 50,1) 
else 
local row = guiGridListAddRow ( gstaf ) 
if adm == true then 
for k,v in ipairs (getElementsByType ("player")) do 
guiGridListSetItemText ( gstaf, row, co, getPlayerName (v), false, false ) 
guiGridListSetItemColor(gstaf, row, co, 0, 100,255, 255) 
guiGridListSetItemText ( gstaf, row, co2, "Online", false, false ) 
guiGridListSetItemColor(gstaf, row, co2, 0, 255,0, 255) 
end 
end 
end 
end 
  
bindKey ( "F10" , "down" , function() 
guiGridListClear (gstaf) 
setTimer (function () 
as () 
end, 50,1) 
end 
) 

code server side:

function Admins() 
if hasObjectPermissionTo ( source, "command.mute", true ) then 
if eventName == "onPlayerLogin" then 
triggerClientEvent ("heAdmin", source) 
elseif eventName == "onPlayerLogout" then 
triggerClientEvent ("notAdmin", source) 
elseif eventName == "onPlayerQuit" then 
triggerClientEvent ("notAdmin", source) 
end 
end 
end 
addEventHandler( "onPlayerLogin", getRootElement(), Admins ) 
addEventHandler( "onPlayerLogout", getRootElement(), Admins ) 
addEventHandler( "onPlayerQuit", getRootElement(), Admins ) 
setTimer (Admins, 500, 0) 
Link to comment
  • Moderators

What about use a table?

  
local adminsOnline = {} 
  
local rankedFun = function  () 
    local players = getElementsByType("player") 
    local rankedPlayers = {} -- save here all players with ranks. 
    for i=1,#players do 
        local player = players[i] 
        if hasObjectPermissionTo ( player, "command.mute", true ) then 
            rankedPlayers[#rankedPlayers+1] = player 
        end 
    end 
    if #adminsOnline ~= #rankedPlayers then -- check if the amount has changed, if changed update the grid. 
        triggerClientEvent (root,"theyAreRanked",root,rankedPlayers) 
        adminsOnline = rankedPlayers 
    elseif #rankedPlayers > 0 then  
        for i=1,#rankedPlayers do 
            local newRanked = rankedPlayers[i] 
            for j=#adminsOnline,1,-1 do 
                if adminsOnline[j] == newRanked then 
                    table.remove(adminsOnline,j) 
                end 
            end 
        end 
        if #adminsOnline > 0 then 
            triggerClientEvent (root,"theyAreRanked",root,rankedPlayers) 
            adminsOnline = rankedPlayers 
        end 
    end 
end 
addEventHandler( "onPlayerLogin", root, rankedFun ) 
addEventHandler( "onPlayerLogout", root, rankedFun ) 
addEventHandler( "onResourceStart",resourceRoot,rankedFun) 
  

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...