Sign in to follow this  
botshara

load data in tab

Recommended Posts

I want load data from triggerServerEvent but I get boolean in client side. I have records in db and i tested server side loop, it works and dont return boolean.

Server side 

function ShowTopKillers()
	allData = {}
	local data = dbQuery(db, "SELECT * FROM top_killers ORDER BY kills DESC LIMIT 50")
	local result = dbPoll(data, -1)
	
	for ind, val in ipairs( result ) do
		local killer = {}
		
		killer.nick = val.nick
		killer.kills = val.kills
		killer.deaths = val.deaths
		--killer.kd = val.kd
		
		allData[killer.nick] = killer
	end
	
	return allData
	
end
addEvent("ShowTopKillers", true)
addEventHandler("ShowTopKillers", getRootElement(), ShowTopKillers)

 

Client side 

allKilers = triggerServerEvent("ShowTopKillers", localPlayer)
killerCounter = 1
for id, killer in pairs(allKilers) do
	local row = guiGridListAddRow ( killersScreenGridList)
	guiGridListSetItemText ( killersScreenGridList, row, 1, killerCounter, false, false )
	guiGridListSetItemText ( killersScreenGridList, row, 2, killer.nick, false, false )
	guiGridListSetItemText ( killersScreenGridList, row, 3, killer.kills, false, false )
	guiGridListSetItemText ( killersScreenGridList, row, 4, killer.deaths, false, false )
	guiGridListSetItemText ( killersScreenGridList, row, 5, 0.69, false, true )
	killerCounter = killerCounter +1
end

 

Edited by botshara

Share this post


Link to post

I may be wrong but I've never seen triggerServerEvent be used like this, assigned to a variable. 

Share this post


Link to post

TriggerServer side event has to be paired with triggerClientEvent to return results.

    function ShowTopKillers()
    	allData = {}
    	local data = dbQuery(db, "SELECT * FROM top_killers ORDER BY kills DESC LIMIT 50")
    	local result = dbPoll(data, -1)
    	
    	for ind, val in ipairs( result ) do
    		local killer = {}
    		
    		killer.nick = val.nick
    		killer.kills = val.kills
    		killer.deaths = val.deaths
    		--killer.kd = val.kd
    		
    		allData[killer.nick] = killer
    	end
    	
    	 triggerClientEvent ( client, "ShowTopKillersC", client, allData )
    	
    end
    addEvent("ShowTopKillers", true)
    addEventHandler("ShowTopKillers", getRootElement(), ShowTopKillers)

Client -

		triggerServerEvent("ShowTopKillers", localPlayer)
	function ShowTopKillers(allKilers)
    killerCounter = 1
    for id, killer in pairs(allKilers) do
    	local row = guiGridListAddRow ( killersScreenGridList)
    	guiGridListSetItemText ( killersScreenGridList, row, 1, killerCounter, false, false )
    	guiGridListSetItemText ( killersScreenGridList, row, 2, killer.nick, false, false )
    	guiGridListSetItemText ( killersScreenGridList, row, 3, killer.kills, false, false )
    	guiGridListSetItemText ( killersScreenGridList, row, 4, killer.deaths, false, false )
    	guiGridListSetItemText ( killersScreenGridList, row, 5, 0.69, false, true )
    	killerCounter = killerCounter +1
    end
	end
	
    addEvent("ShowTopKillersC", true)
    addEventHandler("ShowTopKillersC", localPlayer, ShowTopKillers)

- Not Tested.

 

If you want this to happen every time a certain function is called -

	function ShowTopKillers()
	triggerServerEvent("ShowTopKillers", localPlayer)
	end

 

Edited by CodyJ(L)
  • Thanks 1

Share this post


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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.