Baseplate Posted November 6, 2016 Share Posted November 6, 2016 (edited) 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 November 6, 2016 by Baseplate Link to comment
Walid Posted November 6, 2016 Share Posted November 6, 2016 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
Baseplate Posted November 6, 2016 Author Share Posted November 6, 2016 I tried that one too before I even posted this topic, doesn't work too. The getBans() table doesn't pass from the server to client side somehow. Link to comment
Walid Posted November 6, 2016 Share Posted November 6, 2016 15 minutes ago, Baseplate said: I tried that one too before I even posted this topic, doesn't work too. The getBans() table doesn't pass from the server to client side somehow. Working fine for me ?? Link to comment
pa3ck Posted November 6, 2016 Share Posted November 6, 2016 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
Walid Posted November 6, 2016 Share Posted November 6, 2016 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
Baseplate Posted November 7, 2016 Author Share Posted November 7, 2016 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
Walid Posted November 7, 2016 Share Posted November 7, 2016 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
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