Jump to content

Triggering doesn't pass the getBans() table for me.


Baseplate

Recommended Posts

 

Server side

function setBans()
    triggerClientEvent("setBans", resourceRoot, getBans())
    outputChatBox("Server side says we have "..#getBans())
end
addEvent("outputBans", true)
addEventHandler("outputBans", root, setBans)

#getBans() returns 1 in here.

Client side

While in client side, #bans returns 0.

	function setBans(bans)
    outputChatBox("Client says we have "..#bans)
    for k, v in ipairs(bans) do
        local row = guiGridListAddRow (stfgrd5)
        local serial = tostring(v.serial) or "N/A"
        local duration = tostring(v.time) or "N/A"
        local ip = tostring(getBanIP(v)) or "N/A"
        local nick = tostring(getBanNick(v)) or "N/A"
        local admin = tostring(getBanAdmin(v)) or "N/A"
        guiGridListSetItemText (stfgrd5, row, 1, serial, false, false)
        guiGridListSetItemText (stfgrd5, row, 2, duration, false, false)
        guiGridListSetItemText (stfgrd5, row, 3, ip, false, false)
        guiGridListSetItemText (stfgrd5, row, 4, name, true, false)
        guiGridListSetItemText (stfgrd5, row, 5, admin, true, false)
        outputChatBox("Client says we have "..#bans)
    end
end
addEvent("setBans", true)
addEventHandler("setBans", root, setBans)
	function outputBans()
    if (source == stfgrd5) then
        triggerServerEvent("outputBans", resourceRoot)
    end
end
addEventHandler("onClientGUIClick", root, outputBans)
Edited by Baseplate
Link to comment

Try this

-- Server side
function setBans()
    local bans =  getBans()
    triggerClientEvent(client,"setBans", client, bans)
end
addEvent("outputBans", true)
addEventHandler("outputBans", resourceRoot, setBans)

-- Client side
function setBans(bans)
    if bans then 
        for k, v in ipairs(bans) do
            local row = guiGridListAddRow (stfgrd5)
            local serial = tostring(v.serial) or "N/A"
            local duration = tostring(v.time) or "N/A"
            local ip = tostring(getBanIP(v)) or "N/A"
            local nick = tostring(getBanNick(v)) or "N/A"
            local admin = tostring(getBanAdmin(v)) or "N/A"
            guiGridListSetItemText (stfgrd5, row, 1, serial, false, false)
            guiGridListSetItemText (stfgrd5, row, 2, duration, false, false)
            guiGridListSetItemText (stfgrd5, row, 3, ip, false, false)
            guiGridListSetItemText (stfgrd5, row, 4, name, true, false)
            guiGridListSetItemText (stfgrd5, row, 5, admin, true, false)
        end 
    end
end
addEvent("setBans", true)
addEventHandler("setBans", root, setBans)


function outputBans()
    if (source == stfgrd5) then
        triggerServerEvent("outputBans", resourceRoot)
    end
end
addEventHandler("onClientGUIClick", root, outputBans)

 

Link to comment

getBanIP, getBanNick these are all server-side functions, you can't use them client-side. You will need to process the table which you get with getBans and trigger that "sorted table". By sorting, I mean, put everything from the getBanIP, getBanNick functions into a new table.

Link to comment

Sorry i can't edit my post, anyways you can use sth like this :

function getBansTable()
    local bans =  getBans()
    local bansTable = {}
    for i=1, #bans do
        local admin = getBanAdmin(bans[i]) or "N/A"
        local ip = getBanIP(bans[i]) or "N/A"
        local nick = getBanNick(bans[i]) or "N/A"
        local serial = getBanSerial (bans[i]) or "N/A"
        local banTime = getBanTime (bans[i]) or "N/A"
        local reason = getBanReason (bans[i]) or "N/A"
        table.insert(bansTable,{admin,ip,nick,serial,banTime,reason})
    end 
    return bansTable
end


function setBans()
    local bans =  getBansTable()
    if bans then 
        triggerClientEvent(client,"setBans", client, bans)
    end
end
addEvent("outputBans", true)
addEventHandler("outputBans", resourceRoot, setBans)

 

Link to comment
11 hours ago, pa3ck said:

getBanIP, getBanNick these are all server-side functions, you can't use them client-side. You will need to process the table which you get with getBans and trigger that "sorted table". By sorting, I mean, put everything from the getBanIP, getBanNick functions into a new table.

How the :O did I actually miss this?

 

I edited the script and made it pass the variables instead of the whole table, works perfectly now.

Thanks pa3ck and walid!

Link to comment
3 hours ago, Baseplate said:

I edited the script and made it pass the variables instead of the whole table, works perfectly now.

Nah i don't recommend you to pass variabls one by one, sending the whole table is slightly better (less events triggered) use my code ( getBansTable())

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