Jump to content

[HELP] Get online player and put them in a table


steadyfi

Recommended Posts

Hello , i've got a problem with a script.

I want to get all the online players and put them in a table onlinePlayers but it returns userdata: 00000068.

I'm using this script to see the serial of a player.

Ignore the part with the account manager , it's working.

Client-Side:

isVisible = false 
  
function createGui() 
    mainWnd = guiCreateWindow(650, 350, 283, 410, "Player Manager", false) 
    tabPanel = guiCreateTabPanel(0, 0.1, 1, 1, true, mainWnd) 
    guiSetVisible(mainWnd, true) 
    showCursor(true) 
    tabAcc = guiCreateTab("Accounts", tabPanel) 
        accountGrid = guiCreateGridList(9, 23, 249, 228, false, tabAcc) 
        guiGridListSetSelectionMode(accountGrid, 2) 
        refreshButton = guiCreateButton(9, 258, 80, 26, "Refresh", false, tabAcc) 
        deleteButton = guiCreateButton(110, 258, 80, 26, "Delete", false, tabAcc) 
        closeButton = guiCreateButton(228, 258, 26, 26, "X", false, tabAcc) 
        guiGridListAddColumn(accountGrid, "Account Name", 0.91) 
        triggerServerEvent("serverGetAccounts", localPlayer, localPlayer) 
    tabSerial = guiCreateTab("Serials", tabPanel) 
        playerGrid = guiCreateGridList(9, 23, 249, 228, false, tabSerial) 
        guiGridListSetSelectionMode(playerGrid, 2) 
        refreshButton = guiCreateButton(9, 258, 80, 26, "Refresh", false, tabSerial) 
        fetchButton = guiCreateButton(110, 258, 80, 26, "Fetch", false, tabSerial) 
        closeButton = guiCreateButton(228, 258, 26, 26, "X", false, tabSerial) 
        guiGridListAddColumn(playerGrid, "Name", 0.91) 
        editUser = guiCreateEdit(5, 300, 255, 30, "", false, tabSerial) 
        triggerServerEvent("serverGetPlayers", localPlayer, localPlayer) 
end 
  
function handleCommand() 
    --if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(source)), aclGetGroup("Admin")) then 
        if (isVisible == false) then 
            isVisible = true 
            createGui() 
        elseif (isVisible == true) then 
            guiSetVisible(mainWnd, false) 
            showCursor(false) 
            isVisible = false 
        end 
    --end 
end 
addCommandHandler("plr", handleCommand) 
  
  
--------------------------------- 
--          Account manager 
--------------------------------- 
function refreshGridlist(accountTable) 
    guiGridListClear(accountGrid) 
    for index, account in ipairs(accountTable) do 
        local row = guiGridListAddRow(accountGrid) 
        guiGridListSetItemText(accountGrid, row, 1, tostring(account), false, false) 
    end 
end 
addEvent("serverGivesAccounts", true) 
addEventHandler("serverGivesAccounts", getRootElement(), refreshGridlist) 
  
function buttonHandler() 
    if (source == refreshButton) then 
        triggerServerEvent("serverGetAccounts", localPlayer, localPlayer) 
    elseif (source == deleteButton) then 
        local row,col = guiGridListGetSelectedItem(accountGrid) 
        if row and col and row ~= -1 and col ~= -1 then 
            local targetAccount = guiGridListGetItemText(accountGrid, row, 1) 
            triggerServerEvent("requestAccountDelete", localPlayer, targetAccount) 
            triggerServerEvent("serverGetAccounts", localPlayer, localPlayer) 
        end 
    end 
    if (source == closeButton) then 
        guiSetVisible(mainWnd, false) 
        showCursor(false) 
    end 
end 
addEventHandler("onClientGUIClick", getResourceRootElement(getThisResource()), buttonHandler) 
  
  
--------------------------------- 
--          Serial Manager 
--------------------------------- 
function refreshGridlist2(onlinePlayers) 
    guiGridListClear(playerGrid) 
    for player in ipairs(onlinePlayers) do 
        local row = guiGridListAddRow(playerGrid) 
        guiGridListSetItemText(playerGrid, row, 1, tostring(player), false, false) 
    end 
end 
addEvent("serverGivesPlayers", true) 
addEventHandler("serverGivesPlayers", getRootElement(), refreshGridlist2) 
  
function buttonHandler2() 
    if (source == refreshButton) then 
        triggerServerEvent("serverGetPlayers", localPlayer, localPlayer) 
    end 
    if (source == fetchButton) then 
        local row,col = guiGridListGetSelectedItem(playerGrid) 
        if row and col and row ~= -1 and col ~= -1 then 
            local targetPlayer = guiGridListGetItemText(playerGrid, row, 1) 
            triggerServerEvent("requestGetSerial", localPlayer, targetPlayer) 
        end 
    end 
    if (source == closeButton) then 
        guiSetVisible(mainWnd, false) 
        showCursor(false) 
    end 
end 
addEventHandler("onClientGUIClick", getResourceRootElement(getThisResource()), buttonHandler2) 
  
function serialReceived(serial) 
    editUser = serial 
end 
addEvent("fillForm", true) 
addEventHandler("fillForm", getRootElement(), serialReceived) 

Server-Side:

--------------------------------- 
--          Account manager 
--------------------------------- 
function getTheAccounts(client) 
    accountTable = getAccounts() 
    local tempTable = {} 
    if(#accountTable == 0)then 
        outputDebugString("No accounts in database!") 
    else 
    for index, account in pairs(accountTable) do 
        table.insert(tempTable, getAccountName(account)) 
    end 
    triggerClientEvent(client, "serverGivesAccounts", client, tempTable) 
    end 
end 
addEvent("serverGetAccounts", true) 
addEventHandler("serverGetAccounts", getRootElement(), getTheAccounts) 
  
function deleteAccount(targetAccount) 
    if getAccount(targetAccount) then 
        removeAccount(getAccount(targetAccount)) 
        outputChatBox("The account "..targetAccount.." has been deleted.") 
    end 
end 
addEvent("requestAccountDelete", true) 
addEventHandler("requestAccountDelete", getRootElement(), deleteAccount) 
  
  
--------------------------------- 
--          Serial Manager 
--------------------------------- 
function getThePlayers(client) 
    local onlinePlayers = {} 
    for i,v in pairs(getElementsByType("player")) do 
        table.insert(onlinePlayers, v) 
    end 
    if(#onlinePlayers == 0)then 
        outputDebugString("No player on the server !") 
    else 
        triggerClientEvent(client, "serverGivesPlayers", client, onlinePlayers) 
    end 
end 
addEvent("serverGetPlayers", true) 
addEventHandler("serverGetPlayers", getRootElement(), getThePlayers) 
  
function getSerial(targetPlayer) 
    serial = getPlayerSerial(targetPlayer) 
    triggerClientEvent("fillForm", serial) 
end 
addEvent("requestGetSerial", true) 
addEventHandler("requestGetSerial", getRootElement(), getSerial) 

Error: (in case you need it)

[2014-11-16 23:38:36] WARNING: [race]\[mods]\gc_accmanager\server.lua:47: Bad argument @ 'getPlayerSerial' [Expected player at argument 1, got string 'userdata: 00000068'] 
[2014-11-16 23:38:36] WARNING: [race]\[mods]\gc_accmanager\server.lua:48: Bad argument @ 'triggerClientEvent' [Expected element at argument 2, got boolean] 
  

Thanks

Link to post

getElementsByType("player") already is a table, no need to overheat your code.

If you convert usedata to strings, you can't convert them back.

Try:

function findPlayerByUserDataString (targetPlayer) 
    local players = getElementsByType("player") 
    for i=1,#players do 
        local player = players[i] 
        if targetPlayer == tostring(player) then 
            return player 
        end 
    end 
    return false 
end 
  

local player = findPlayerByUserDataString (targetPlayer) 

But managing a table next to your gridlist is much better.

Link to post
getElementsByType("player") already is a table, no need to overheat your code.

If you convert usedata to strings, you can't convert them back.

Try:

function findPlayerByUserDataString (targetPlayer) 
    local players = getElementsByType("player") 
    for i=1,#players do 
        local player = players[i] 
        if targetPlayer == tostring(player) then 
            return player 
        end 
    end 
    return false 
end 
  

local player = findPlayerByUserDataString (targetPlayer) 

But managing a table next to your gridlist is much better.

Thanks , i'll try to modify the code to fit this.

Edited by Guest
Link to post
no, one side. clientside or serverside.

The first one is just a useful function.

The second one is how you can use the function.

I think i'm close ... but not really close. It returns false. What did I do wrong ? Sorry if i'm being silly or a noob ... or both.

Client Side:

isVisible = false 
  
function createGui() 
    mainWnd = guiCreateWindow(650, 350, 283, 410, "Player Manager", false) 
    tabPanel = guiCreateTabPanel(0, 0.1, 1, 1, true, mainWnd) 
    guiSetVisible(mainWnd, true) 
    showCursor(true) 
    tabAcc = guiCreateTab("Accounts", tabPanel) 
        accountGrid = guiCreateGridList(9, 23, 249, 228, false, tabAcc) 
        guiGridListSetSelectionMode(accountGrid, 2) 
        refreshButton = guiCreateButton(9, 258, 80, 26, "Refresh", false, tabAcc) 
        deleteButton = guiCreateButton(110, 258, 80, 26, "Delete", false, tabAcc) 
        closeButton = guiCreateButton(228, 258, 26, 26, "X", false, tabAcc) 
        guiGridListAddColumn(accountGrid, "Account Name", 0.91) 
        triggerServerEvent("serverGetAccounts", localPlayer, localPlayer) 
    tabSerial = guiCreateTab("Serials", tabPanel) 
        playerGrid = guiCreateGridList(9, 23, 249, 228, false, tabSerial) 
        guiGridListSetSelectionMode(playerGrid, 2) 
        refreshButton = guiCreateButton(9, 258, 80, 26, "Refresh", false, tabSerial) 
        fetchButton = guiCreateButton(110, 258, 80, 26, "Fetch", false, tabSerial) 
        closeButton = guiCreateButton(228, 258, 26, 26, "X", false, tabSerial) 
        guiGridListAddColumn(playerGrid, "Nickname", 0.91) 
        editUser = guiCreateEdit(5, 300, 255, 30, "", false, tabSerial) 
        triggerServerEvent("serverGetPlayers", localPlayer, localPlayer) 
end 
  
function handleCommand() 
        if (isVisible == false) then 
            isVisible = true 
            createGui() 
        elseif (isVisible == true) then 
            guiSetVisible(mainWnd, false) 
            showCursor(false) 
            isVisible = false 
        end 
end 
addCommandHandler("plr", handleCommand) 
  
  
--------------------------------- 
--          Account manager 
--------------------------------- 
function refreshGridlist(accountTable) 
    guiGridListClear(accountGrid) 
    for index, account in ipairs(accountTable) do 
        local row = guiGridListAddRow(accountGrid) 
        guiGridListSetItemText(accountGrid, row, 1, tostring(account), false, false) 
    end 
end 
addEvent("serverGivesAccounts", true) 
addEventHandler("serverGivesAccounts", getRootElement(), refreshGridlist) 
  
function buttonHandler() 
    if (source == refreshButton) then 
        triggerServerEvent("serverGetAccounts", localPlayer, localPlayer) 
    elseif (source == deleteButton) then 
        local row,col = guiGridListGetSelectedItem(accountGrid) 
        if row and col and row ~= -1 and col ~= -1 then 
            local targetAccount = guiGridListGetItemText(accountGrid, row, 1) 
            triggerServerEvent("requestAccountDelete", localPlayer, targetAccount) 
            triggerServerEvent("serverGetAccounts", localPlayer, localPlayer) 
        end 
    end 
    if (source == closeButton) then 
        guiSetVisible(mainWnd, false) 
        showCursor(false) 
    end 
end 
addEventHandler("onClientGUIClick", getResourceRootElement(getThisResource()), buttonHandler) 
  
  
--------------------------------- 
--          Serial Manager 
--------------------------------- 
function refreshGridlist2(onlinePlayers) 
    guiGridListClear(playerGrid) 
    for player in ipairs(onlinePlayers) do 
        local playerName = findPlayerByUserDataString(targetPlayer) 
        local row = guiGridListAddRow(playerGrid) 
        guiGridListSetItemText(playerGrid, row, 1, tostring(playerName), false, false) 
    end 
end 
addEvent("serverGivesPlayers", true) 
addEventHandler("serverGivesPlayers", getRootElement(), refreshGridlist2) 
  
function findPlayerByUserDataString(targetPlayer) 
    local players = getElementsByType("player") 
    for i=1,#players do 
        local player = players[i] 
        if targetPlayer == tostring(player) then 
            return player 
        end 
    end 
    return false 
end 
  
function buttonHandler2() 
    if (source == refreshButton) then 
        triggerServerEvent("serverGetPlayers", localPlayer, localPlayer) 
    end 
    if (source == fetchButton) then 
        local row,col = guiGridListGetSelectedItem(playerGrid) 
        if row and col and row ~= -1 and col ~= -1 then 
            local targetPlayer = guiGridListGetItemText(playerGrid, row, 1) 
            triggerServerEvent("requestGetSerial", localPlayer, targetPlayer) 
        end 
    end 
    if (source == closeButton) then 
        guiSetVisible(mainWnd, false) 
        showCursor(false) 
    end 
end 
addEventHandler("onClientGUIClick", getResourceRootElement(getThisResource()), buttonHandler2) 
  
function serialReceived(serial) 
    editUser = serial 
end 
addEvent("fillForm", true) 
addEventHandler("fillForm", getRootElement(), serialReceived) 

Server Side:

--------------------------------- 
--          Account manager 
--------------------------------- 
function getTheAccounts(client) 
    accountTable = getAccounts() 
    local tempTable = {} 
    if(#accountTable == 0)then 
        outputDebugString("No accounts in database!") 
    else 
    for index, account in pairs(accountTable) do 
        table.insert(tempTable, getAccountName(account)) 
    end 
    triggerClientEvent(client, "serverGivesAccounts", client, tempTable) 
    end 
end 
addEvent("serverGetAccounts", true) 
addEventHandler("serverGetAccounts", getRootElement(), getTheAccounts) 
  
function deleteAccount(targetAccount) 
    if getAccount(targetAccount) then 
        removeAccount(getAccount(targetAccount)) 
        outputChatBox("The account "..targetAccount.." has been deleted.") 
    end 
end 
addEvent("requestAccountDelete", true) 
addEventHandler("requestAccountDelete", getRootElement(), deleteAccount) 
  
  
--------------------------------- 
--          Serial Manager 
--------------------------------- 
function getThePlayers(client) 
    local onlinePlayers = {} 
    for i,v in pairs(getElementsByType("player")) do 
        table.insert(onlinePlayers, v) 
    end 
    if(#onlinePlayers == 0)then 
        outputDebugString("No player on the server !") 
    else 
        triggerClientEvent(client, "serverGivesPlayers", client, onlinePlayers) 
    end 
end 
addEvent("serverGetPlayers", true) 
addEventHandler("serverGetPlayers", getRootElement(), getThePlayers) 
  
function getSerial(targetPlayer) 
    serial = getPlayerSerial(targetPlayer) 
    triggerClientEvent("fillForm", serial) 
end 
addEvent("requestGetSerial", true) 
addEventHandler("requestGetSerial", getRootElement(), getSerial) 

Screenshot:

VG1Cmbo.png?1

Link to post

Of course it returns false, there is no variable called: targetPlayer there.

And it DOEN'T RETURN THE PLAYER NAME, IT RETURNS A PLAYER.

When you put a userdata in to a grid list, it becomes a string.

This is what it does:

local targetPlayer = tostring(localPlayer) -- convert the userdata to a string 
local player = findPlayerByUserDataString (targetPlayer) -- find the player who is matching this userdata string. 

Use it between line 104 and 105. (clientside)

It looks like you don't know which types of data there are out there.

Use the function type(variable) to figure that out, it returns the type.

This link might help you: https://wiki.multitheftauto.com/wiki/De ... strategies

Link to post
Of course it returns false, there is no variable called: targetPlayer there.

And it DOEN'T RETURN THE PLAYER NAME, IT RETURNS A PLAYER.

When you put a userdata in to a grid list, it becomes a string.

This is what it does:

local targetPlayer = tostring(localPlayer) -- convert the userdata to a string 
local player = findPlayerByUserDataString (targetPlayer) -- find the player who is matching this userdata string. 

Use it between line 104 and 105. (clientside)

It looks like you don't know which types of data there are out there.

Use the function type(variable) to figure that out, it returns the type.

This link might help you: https://wiki.multitheftauto.com/wiki/De ... strategies

I'm officially retarted and I should quit. I'm staying here... for 2 hours or more.... trying to figure out how to make it work...

It returnes nil and gives me an error when trying to fetch serial in the server side script.

I didn't think I will ever ask for this but... could you please make it for me ? I'm never gonna make it work.

If you don't wanna help me with that it's alright, you aren't obligated to help me by doing my work.

Client Side:

isVisible = false 
  
function createGui() 
    mainWnd = guiCreateWindow(650, 350, 283, 410, "Player Manager", false) 
    tabPanel = guiCreateTabPanel(0, 0.1, 1, 1, true, mainWnd) 
    guiSetVisible(mainWnd, true) 
    guiWindowSetSizable(mainWnd, false) 
    showCursor(true) 
    tabAcc = guiCreateTab("Accounts", tabPanel) 
        accountGrid = guiCreateGridList(9, 23, 249, 260, false, tabAcc) 
        guiGridListSetSelectionMode(accountGrid, 2) 
        refreshButton = guiCreateButton(9, 300, 80, 26, "Refresh", false, tabAcc) 
        deleteButton = guiCreateButton(178, 300, 80, 26, "Delete", false, tabAcc) 
        guiGridListAddColumn(accountGrid, "Account Name", 0.91) 
        triggerServerEvent("serverGetAccounts", localPlayer, localPlayer) 
    tabSerial = guiCreateTab("Serials", tabPanel) 
        playerGrid = guiCreateGridList(9, 23, 249, 228, false, tabSerial) 
        guiGridListSetSelectionMode(playerGrid, 2) 
        refreshButton = guiCreateButton(9, 258, 80, 26, "Refresh", false, tabSerial) 
        fetchButton = guiCreateButton(178, 258, 80, 26, "Fetch", false, tabSerial) 
        guiGridListAddColumn(playerGrid, "Nickname", 0.91) 
        editUser = guiCreateEdit(5, 300, 255, 30, "", false, tabSerial) 
        guiEditSetReadOnly(editUser, true) 
        triggerServerEvent("serverGetPlayers", localPlayer, localPlayer) 
end 
  
function handleCommand() 
        if (isVisible == false) then 
            isVisible = true 
            createGui() 
        elseif (isVisible == true) then 
            guiSetVisible(mainWnd, false) 
            showCursor(false) 
            isVisible = false 
        end 
end 
addCommandHandler("plr", handleCommand) 
  
  
--------------------------------- 
--          Account manager 
--------------------------------- 
function refreshGridlist(accountTable) 
    guiGridListClear(accountGrid) 
    for index, account in ipairs(accountTable) do 
        local row = guiGridListAddRow(accountGrid) 
        guiGridListSetItemText(accountGrid, row, 1, tostring(account), false, false) 
    end 
end 
addEvent("serverGivesAccounts", true) 
addEventHandler("serverGivesAccounts", getRootElement(), refreshGridlist) 
  
function buttonHandler() 
    if (source == refreshButton) then 
        triggerServerEvent("serverGetAccounts", localPlayer, localPlayer) 
    elseif (source == deleteButton) then 
        local row,col = guiGridListGetSelectedItem(accountGrid) 
        if row and col and row ~= -1 and col ~= -1 then 
            local targetAccount = guiGridListGetItemText(accountGrid, row, 1) 
            triggerServerEvent("requestAccountDelete", localPlayer, targetAccount) 
            triggerServerEvent("serverGetAccounts", localPlayer, localPlayer) 
        end 
    end 
end 
addEventHandler("onClientGUIClick", getResourceRootElement(getThisResource()), buttonHandler) 
  
  
--------------------------------- 
--          Serial Manager 
--------------------------------- 
function refreshGridlist2(onlinePlayers) 
    guiGridListClear(playerGrid) 
    for players in ipairs(onlinePlayers) do 
        local row = guiGridListAddRow(playerGrid) 
        guiGridListSetItemText(playerGrid, row, 1, tostring(player), false, false) 
    end 
end 
addEvent("serverGivesPlayers", true) 
addEventHandler("serverGivesPlayers", getRootElement(), refreshGridlist2) 
  
function findPlayerByUserDataString(targetPlayer) 
    local players = getElementsByType("player") 
    for i=1,#players do 
        local player = players[i] 
        if targetPlayer == tostring(player) then 
            return player 
        end 
    end 
    return false 
end 
  
function buttonHandler2(targetPlayer) 
    if (source == refreshButton) then 
        triggerServerEvent("serverGetPlayers", localPlayer, localPlayer) 
    end 
    if (source == fetchButton) then 
        local row,col = guiGridListGetSelectedItem(playerGrid) 
        if row and col and row ~= -1 and col ~= -1 then 
            local targetPlayer = guiGridListGetItemText(playerGrid, row, 1) 
            local player = findPlayerByUserDataString(targetPlayer) 
            triggerServerEvent("requestGetSerial", localPlayer, targetPlayer) 
        end 
    end 
end 
addEventHandler("onClientGUIClick", getResourceRootElement(getThisResource()), buttonHandler2) 
  
function fillSerial(serial) 
    guiSetText(editUser, serial) 
end 
addEvent("fillForm", true) 
addEventHandler("fillForm", getRootElement(), fillSerial) 

Server Side:

--------------------------------- 
--          Account manager 
--------------------------------- 
function getTheAccounts(client) 
    accountTable = getAccounts() 
    local tempTable = {} 
    if(#accountTable == 0)then 
        outputDebugString("No accounts in database!") 
    else 
    for index, account in pairs(accountTable) do 
        table.insert(tempTable, getAccountName(account)) 
    end 
    triggerClientEvent(client, "serverGivesAccounts", client, tempTable) 
    end 
end 
addEvent("serverGetAccounts", true) 
addEventHandler("serverGetAccounts", getRootElement(), getTheAccounts) 
  
function deleteAccount(targetAccount) 
    if getAccount(targetAccount) then 
        removeAccount(getAccount(targetAccount)) 
        outputChatBox("The account "..targetAccount.." has been deleted.") 
    end 
end 
addEvent("requestAccountDelete", true) 
addEventHandler("requestAccountDelete", getRootElement(), deleteAccount) 
  
  
--------------------------------- 
--          Serial Manager 
--------------------------------- 
function getThePlayers(client) 
    local onlinePlayers = {} 
    for i,v in pairs(getElementsByType("player")) do 
        table.insert(onlinePlayers, v) 
    end 
    if(#onlinePlayers == 0)then 
        outputDebugString("No player on the server !") 
    else 
        triggerClientEvent(client, "serverGivesPlayers", client, onlinePlayers) 
    end 
end 
addEvent("serverGetPlayers", true) 
addEventHandler("serverGetPlayers", getRootElement(), getThePlayers) 
  
function getSerial(targetPlayer) 
    serial = getPlayerSerial(targetPlayer) 
    triggerClientEvent("fillForm", serial) 
end 
addEvent("requestGetSerial", true) 
addEventHandler("requestGetSerial", getRootElement(), getSerial) 

Screenshot: (error + nil)

Js8wsvi.png?1

Thanks for all your help, I really appreciate it ! I'm just a noob when it comes to tables and inserting tables into grids...

Link to post

Next time try to fix it by yourself . Never give up

Anyway :

-- Client side:

local getPlayerRow = {} 
  
isVisible = false 
  
function createGui() 
    local screenWidth, screenHeight = guiGetScreenSize() 
    local windowWidth, windowHeight = 283, 410 
    local windowX, windowY = (screenWidth / 2) - (windowWidth / 2), (screenHeight / 2) - (windowHeight / 2) 
    mainWnd = guiCreateWindow(windowX, windowY, windowWidth, windowHeight,  "Player Manager", false) 
    tabPanel = guiCreateTabPanel(0, 0.1, 1, 1, true, mainWnd) 
    guiSetVisible(mainWnd, true) 
    showCursor(true) 
    tabAcc = guiCreateTab("Accounts", tabPanel) 
        accountGrid = guiCreateGridList(9, 23, 249, 228, false, tabAcc) 
        guiGridListSetSelectionMode(accountGrid, 0) 
        refreshButton = guiCreateButton(9, 258, 80, 26, "Refresh", false, tabAcc) 
        deleteButton = guiCreateButton(110, 258, 80, 26, "Delete", false, tabAcc) 
        closeButton = guiCreateButton(228, 258, 26, 26, "X", false, tabAcc) 
        guiGridListAddColumn(accountGrid, "Account Name", 0.91) 
        triggerServerEvent("serverGetAccounts", localPlayer, localPlayer) 
         
         
        tabSerial = guiCreateTab("Serials", tabPanel) 
        playerGrid = guiCreateGridList(9, 23, 249, 228, false, tabSerial) 
        guiGridListAddColumn(playerGrid, "Name", 0.91) 
        guiGridListSetSelectionMode(playerGrid, 0) 
        refreshButton = guiCreateButton(9, 258, 80, 26, "Refresh", false, tabSerial) 
        fetchButton = guiCreateButton(110, 258, 80, 26, "Fetch", false, tabSerial) 
        closeButton = guiCreateButton(228, 258, 26, 26, "X", false, tabSerial) 
        editUser = guiCreateEdit(5, 300, 255, 30, "", false, tabSerial) 
        triggerServerEvent("serverGetPlayers", localPlayer, localPlayer) 
end 
  
function handleCommand() 
        if (isVisible == false) then 
            isVisible = true 
            createGui() 
        elseif (isVisible == true) then 
            guiSetVisible(mainWnd, false) 
            showCursor(false) 
            isVisible = false 
        end 
end 
addCommandHandler("plr", handleCommand) 
  
  
--------------------------------- 
--          Account manager 
--------------------------------- 
function refreshGridlist(accountTable) 
    guiGridListClear(accountGrid) 
    for index, account in ipairs(accountTable) do 
        local row = guiGridListAddRow(accountGrid) 
        guiGridListSetItemText(accountGrid, row, 1, tostring(account), false, false) 
    end 
end 
addEvent("serverGivesAccounts", true) 
addEventHandler("serverGivesAccounts", getRootElement(), refreshGridlist) 
  
function buttonHandler() 
    if (source == refreshButton) then 
        triggerServerEvent("serverGetAccounts", localPlayer, localPlayer) 
    elseif (source == deleteButton) then 
        local row,col = guiGridListGetSelectedItem(accountGrid) 
        if row and col and row ~= -1 and col ~= -1 then 
            local targetAccount = guiGridListGetItemText(accountGrid, row, 1) 
            triggerServerEvent("requestAccountDelete", localPlayer, targetAccount) 
            triggerServerEvent("serverGetAccounts", localPlayer, localPlayer) 
        end 
    end 
    if (source == closeButton) then 
        guiSetVisible(mainWnd, false) 
        showCursor(false) 
    end 
end 
addEventHandler("onClientGUIClick", getResourceRootElement(getThisResource()), buttonHandler) 
  
  
--------------------------------- 
--          Serial Manager 
--------------------------------- 
  
-- Add players to grid list: 
function addPlayersToGridlist() 
   guiGridListClear(playerGrid) 
    for index, players in pairs(getElementsByType("player")) do  
        local row = guiGridListAddRow(playerGrid) 
        local name = getPlayerName(players) 
        guiGridListSetItemText(playerGrid, row, 1, name, false, false) 
        getPlayerRow[players] = row 
    end 
 end 
addEvent("serverGivesPlayers",true) 
addEventHandler("serverGivesPlayers",root,addPlayersToGridlist) 
  
function buttonHandler2() 
-- Fetch button 
    if (source == fetchButton) then 
        local row,col = guiGridListGetSelectedItem(playerGrid) 
        if row and col and row ~= -1 and col ~= -1 then 
            local targetPlayer = guiGridListGetItemText(playerGrid, row, 1) 
            local serial = getPlayerSerial (targetPlayer ) 
            guiSetText(editUser,serial) 
        end 
    end 
-- Refresh button 
if (source == refreshButton) then 
    guiGridListClear(playerGrid) 
    for k,v in ipairs (getElementsByType("player")) do 
        local name = string.lower(getPlayerName(v)) 
        if (name) then 
            local row = guiGridListAddRow(playerGrid) 
            guiGridListSetItemText(playerGrid,row,1,getPlayerName(v),false,false) 
            getPlayerRow[v] = row 
        end 
    end 
end  
-- Close button 
    if (source == closeButton) then 
        guiSetVisible(mainWnd, false) 
        showCursor(false) 
    end 
end 
addEventHandler("onClientGUIClick", getResourceRootElement(getThisResource()), buttonHandler2) 

-- server side:

--------------------------------- 
--          Account manager 
--------------------------------- 
function getTheAccounts(client) 
    accountTable = getAccounts() 
    local tempTable = {} 
    if(#accountTable == 0)then 
        outputDebugString("No accounts in database!") 
    else 
    for index, account in pairs(accountTable) do 
        table.insert(tempTable, getAccountName(account)) 
    end 
    triggerClientEvent(client, "serverGivesAccounts", client, tempTable) 
    end 
end 
addEvent("serverGetAccounts", true) 
addEventHandler("serverGetAccounts", getRootElement(), getTheAccounts) 
  
function deleteAccount(targetAccount) 
    if getAccount(targetAccount) then 
        removeAccount(getAccount(targetAccount)) 
        outputChatBox("The account "..targetAccount.." has been deleted.") 
    end 
end 
addEvent("requestAccountDelete", true) 
addEventHandler("requestAccountDelete", getRootElement(), deleteAccount) 
  
function getThePlayers(client) 
triggerClientEvent(client, "serverGivesPlayers", client) 
end 
addEvent("serverGetPlayers", true) 
addEventHandler("serverGetPlayers", getRootElement(), getThePlayers) 
  

Link to post
Next time try to fix it by yourself . Never give up

Anyway :

-- Client side:

local getPlayerRow = {} 
  
isVisible = false 
  
function createGui() 
    local screenWidth, screenHeight = guiGetScreenSize() 
    local windowWidth, windowHeight = 283, 410 
    local windowX, windowY = (screenWidth / 2) - (windowWidth / 2), (screenHeight / 2) - (windowHeight / 2) 
    mainWnd = guiCreateWindow(windowX, windowY, windowWidth, windowHeight,  "Player Manager", false) 
    tabPanel = guiCreateTabPanel(0, 0.1, 1, 1, true, mainWnd) 
    guiSetVisible(mainWnd, true) 
    showCursor(true) 
    tabAcc = guiCreateTab("Accounts", tabPanel) 
        accountGrid = guiCreateGridList(9, 23, 249, 228, false, tabAcc) 
        guiGridListSetSelectionMode(accountGrid, 0) 
        refreshButton = guiCreateButton(9, 258, 80, 26, "Refresh", false, tabAcc) 
        deleteButton = guiCreateButton(110, 258, 80, 26, "Delete", false, tabAcc) 
        closeButton = guiCreateButton(228, 258, 26, 26, "X", false, tabAcc) 
        guiGridListAddColumn(accountGrid, "Account Name", 0.91) 
        triggerServerEvent("serverGetAccounts", localPlayer, localPlayer) 
         
         
        tabSerial = guiCreateTab("Serials", tabPanel) 
        playerGrid = guiCreateGridList(9, 23, 249, 228, false, tabSerial) 
        guiGridListAddColumn(playerGrid, "Name", 0.91) 
        guiGridListSetSelectionMode(playerGrid, 0) 
        refreshButton = guiCreateButton(9, 258, 80, 26, "Refresh", false, tabSerial) 
        fetchButton = guiCreateButton(110, 258, 80, 26, "Fetch", false, tabSerial) 
        closeButton = guiCreateButton(228, 258, 26, 26, "X", false, tabSerial) 
        editUser = guiCreateEdit(5, 300, 255, 30, "", false, tabSerial) 
        triggerServerEvent("serverGetPlayers", localPlayer, localPlayer) 
end 
  
function handleCommand() 
        if (isVisible == false) then 
            isVisible = true 
            createGui() 
        elseif (isVisible == true) then 
            guiSetVisible(mainWnd, false) 
            showCursor(false) 
            isVisible = false 
        end 
end 
addCommandHandler("plr", handleCommand) 
  
  
--------------------------------- 
--          Account manager 
--------------------------------- 
function refreshGridlist(accountTable) 
    guiGridListClear(accountGrid) 
    for index, account in ipairs(accountTable) do 
        local row = guiGridListAddRow(accountGrid) 
        guiGridListSetItemText(accountGrid, row, 1, tostring(account), false, false) 
    end 
end 
addEvent("serverGivesAccounts", true) 
addEventHandler("serverGivesAccounts", getRootElement(), refreshGridlist) 
  
function buttonHandler() 
    if (source == refreshButton) then 
        triggerServerEvent("serverGetAccounts", localPlayer, localPlayer) 
    elseif (source == deleteButton) then 
        local row,col = guiGridListGetSelectedItem(accountGrid) 
        if row and col and row ~= -1 and col ~= -1 then 
            local targetAccount = guiGridListGetItemText(accountGrid, row, 1) 
            triggerServerEvent("requestAccountDelete", localPlayer, targetAccount) 
            triggerServerEvent("serverGetAccounts", localPlayer, localPlayer) 
        end 
    end 
    if (source == closeButton) then 
        guiSetVisible(mainWnd, false) 
        showCursor(false) 
    end 
end 
addEventHandler("onClientGUIClick", getResourceRootElement(getThisResource()), buttonHandler) 
  
  
--------------------------------- 
--          Serial Manager 
--------------------------------- 
  
-- Add players to grid list: 
function addPlayersToGridlist() 
   guiGridListClear(playerGrid) 
    for index, players in pairs(getElementsByType("player")) do  
        local row = guiGridListAddRow(playerGrid) 
        local name = getPlayerName(players) 
        guiGridListSetItemText(playerGrid, row, 1, name, false, false) 
        getPlayerRow[players] = row 
    end 
 end 
addEvent("serverGivesPlayers",true) 
addEventHandler("serverGivesPlayers",root,addPlayersToGridlist) 
  
function buttonHandler2() 
-- Fetch button 
    if (source == fetchButton) then 
        local row,col = guiGridListGetSelectedItem(playerGrid) 
        if row and col and row ~= -1 and col ~= -1 then 
            local targetPlayer = guiGridListGetItemText(playerGrid, row, 1) 
            local serial = getPlayerSerial (targetPlayer ) 
            guiSetText(editUser,serial) 
        end 
    end 
-- Refresh button 
if (source == refreshButton) then 
    guiGridListClear(playerGrid) 
    for k,v in ipairs (getElementsByType("player")) do 
        local name = string.lower(getPlayerName(v)) 
        if (name) then 
            local row = guiGridListAddRow(playerGrid) 
            guiGridListSetItemText(playerGrid,row,1,getPlayerName(v),false,false) 
            getPlayerRow[v] = row 
        end 
    end 
end  
-- Close button 
    if (source == closeButton) then 
        guiSetVisible(mainWnd, false) 
        showCursor(false) 
    end 
end 
addEventHandler("onClientGUIClick", getResourceRootElement(getThisResource()), buttonHandler2) 

-- server side:

--------------------------------- 
--          Account manager 
--------------------------------- 
function getTheAccounts(client) 
    accountTable = getAccounts() 
    local tempTable = {} 
    if(#accountTable == 0)then 
        outputDebugString("No accounts in database!") 
    else 
    for index, account in pairs(accountTable) do 
        table.insert(tempTable, getAccountName(account)) 
    end 
    triggerClientEvent(client, "serverGivesAccounts", client, tempTable) 
    end 
end 
addEvent("serverGetAccounts", true) 
addEventHandler("serverGetAccounts", getRootElement(), getTheAccounts) 
  
function deleteAccount(targetAccount) 
    if getAccount(targetAccount) then 
        removeAccount(getAccount(targetAccount)) 
        outputChatBox("The account "..targetAccount.." has been deleted.") 
    end 
end 
addEvent("requestAccountDelete", true) 
addEventHandler("requestAccountDelete", getRootElement(), deleteAccount) 
  
function getThePlayers(client) 
triggerClientEvent(client, "serverGivesPlayers", client) 
end 
addEvent("serverGetPlayers", true) 
addEventHandler("serverGetPlayers", getRootElement(), getThePlayers) 
  

Thank you very very much ! I really appreciate it. Next time I will try to solve it by my self. Thanks again

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.

×
×
  • Create New...