Jump to content

Can I export table in triggerClientEvent?


acp___(PL)

Recommended Posts

Optional Arguments

(...)

* arguments...: A list of arguments to trigger with the event. You can pass any lua data type (except functions). You can also pass elements.

table to??

executeSQLQuery( "SELECT player_nick, player_points FROM stats_mm WHERE player_points > 0" )

1. wants all the rows in which the players have some points

2. I am interested in the column: player_nick, player_points

3. table called: stats_mm

server side

line 13 - triggerClientEvent ( "onPlayerReSortMeTableRankMM", g_Root, countPlayersInMM, tablePlayersInMM )

function pointsMM_endRace (rank_mm)
	local allPlayersPointsMM = executeSQLQuery( "SELECT player_nick, player_points FROM stats_mm WHERE player_points > 0" )
	local countPlayersInMM = 0
	local tablePlayersInMM = {}
	for i, playerdata in ipairs(allPlayersPointsMM) do
		tablePlayersInMM[i] = {}
		tablePlayersInMM[i][1] = playerdata[player_nick]
		tablePlayersInMM[i][2] = playerdata[player_points]
		countPlayersInMM = countPlayersInMM + 1
	end
	setElementData ( source, "Points MM", playerPointsMMresult )
	triggerClientEvent ( source, "onPlayerShowIlePunktowZaWyscigInMM", g_Root, playerPointsInMM, placesInMM )
	triggerClientEvent ( "onPlayerReSortMeTableRankMM", g_Root, countPlayersInMM, tablePlayersInMM )
	triggerClientEvent ( source, "onPlayerShowMeTableRankMM", g_Root, 30 )
	outputDebugString("IV MM: " ..namePlayerMM.. " has finisched " ..placesInMM.. "/" ..playerPointsInMM.. "/" ..playerPointsMMresult, 3, 0, 0, 255)
else
end
end

client side

both the value in line 20 do not exist

line 20 - while countBombelkowanie > 0 and sortBombelkowanieEnd > 0 do

function algorytmSortowania (the_numberActivPlayersInMM, the_the_table)
local countPlayersInMM = 0
for i, k in ipairs(listaTop10points) do
	listaTop10points[i] = nil
end
local playerValue = the_numberActivPlayersInMM
while playerValue > 0 do
	countPlayersInMM = countPlayersInMM + 1
	listaTop10name[countPlayersInMM] = the_the_table[playerValue][1]
	listaTop10points[countPlayersInMM] = the_the_table[playerValue][2]
	playerValue = playerValue - 1
end
local countBombelkowanie = countPlayersInMM - 1
local sortBombelkowanieEnd = countBombelkowanie - 1
local iterowanieBombelkowania = 0
while countBombelkowanie > 0 and sortBombelkowanieEnd > 0 do
	iterowanieBombelkowania = iterowanieBombelkowania + 1
	outputConsole("algorytmSortowania while countBombelkowanie > 0 and sortBombelkowanieEnd > 0 do - c=" ..countBombelkowanie.. "/s=" ..sortBombelkowanieEnd.. "/i=" ..iterowanieBombelkowania )
	countBombelkowanie = countBombelkowanie - 1
	if listaTop10points[iterowanieBombelkowania] < listaTop10points[iterowanieBombelkowania + 1] then
		local tempNick = listaTop10name[iterowanieBombelkowania]
		local tempPoints = listaTop10points[iterowanieBombelkowania]
		listaTop10name[iterowanieBombelkowania] = listaTop10name[iterowanieBombelkowania + 1]
		listaTop10points[iterowanieBombelkowania] = listaTop10points[iterowanieBombelkowania + 1]
		listaTop10name[iterowanieBombelkowania + 1] = tempNick
		listaTop10points[iterowanieBombelkowania + 1] = tempPoints
	end
	if countBombelkowanie == 0 then
		countBombelkowanie = sortBombelkowanieEnd
		sortBombelkowanieEnd = sortBombelkowanieEnd - 1
		iterowanieBombelkowania = 0
	end
end
end
 
function playerReSortMeTableRankMM (theCountPlayersInMM, the_table)
algorytmSortowania(theCountPlayersInMM, the_table)
end
addEvent( "onPlayerReSortMeTableRankMM", true )
addEventHandler( "onPlayerReSortMeTableRankMM", g_Root, playerReSortMeTableRankMM )

Link to comment

is it the correct way to export table??

script still not working, but did not notify me of errors ...

server side:

function pointsMM_endRace (rank_mm)
	local allPlayersPointsMM = executeSQLQuery( "SELECT player_nick, player_points FROM stats_mm WHERE player_points > 0" )
	local countPlayersInMM = 0
	local tablePlayersInMMnick = {}
	local tablePlayersInMMpoints = {}
	for i, playerdata in ipairs(allPlayersPointsMM) do
		tablePlayersInMMnick[i] = playerdata[player_nick]
		tablePlayersInMMpoints[i] = playerdata[player_points]
		countPlayersInMM = countPlayersInMM + 1
	end
	setElementData ( source, "Points MM", playerPointsMMresult )
	triggerClientEvent ( source, "onPlayerShowIlePunktowZaWyscigInMM", g_Root, playerPointsInMM, placesInMM )
	triggerClientEvent ( "onPlayerReSortMeTableRankMM", g_Root, countPlayersInMM, unpack(tablePlayersInMMnick), unpack(tablePlayersInMMpoints))
	triggerClientEvent ( source, "onPlayerShowMeTableRankMM", g_Root, 30 )
	outputDebugString("IV MM: " ..namePlayerMM.. " has finisched " ..placesInMM.. "/" ..playerPointsInMM.. "/" ..playerPointsMMresult, 3, 0, 0, 255)
end
end

client side:

function playerReSortMeTableRankMM (theCountPlayersInMM, ...)
for i, k in ipairs(listaTop10points) do
	listaTop10points[i] = nil
end
local arg = {...}
local j = 1
for i,v in ipairs(arg) do
	if i <= theCountPlayersInMM then
		listaTop10name[i] = arg[i]
	else
		listaTop10points[j] = arg[i]
		j = j + 1 
	end
end
algorytmSortowania(theCountPlayersInMM)
end
addEvent( "onPlayerReSortMeTableRankMM", true )
addEventHandler( "onPlayerReSortMeTableRankMM", g_Root, playerReSortMeTableRankMM )

Link to comment
triggerClientEvent ( "onPlayerReSortMeTableRankMM", g_Root, countPlayersInMM, unpack(tablePlayersInMMnick), unpack(tablePlayersInMMpoints))

In this example, you are call two unpack functions together, the syntax Lua is unacceptable, you first have to pack everything into one table, and then unpack it.

Link to comment

my table:

tablets.jpg

how it will look like Table: allPlayersPointsMM

local allPlayersPointsMM = executeSQLQuery( "SELECT player_nick, player_points FROM stats_mm WHERE player_points > 0" )

to do so as described above post does I need to use this:

local allPlayersPointsMMpoints = executeSQLQuery( "SELECT player_nick FROM stats_mm WHERE player_points > 0" )
local allPlayersPointsMMnick = executeSQLQuery( "SELECT player_points FROM stats_mm WHERE player_points > 0" )

:?::?::?::?::?::?::?::?::?::?::?::?:

Link to comment

1) it must work: :?::?:

local allPlayersPointsMM = executeSQLQuery( "SELECT player_nick, player_points FROM stats_mm WHERE player_points > 0" )
triggerClientEvent ( "onPlayerReSortMeTableRankMM", g_Root, allPlayersPointsMM)

2) client-side: :?::?:

local tablePlayersInMM = {}
	for i, playerdata in ipairs(allPlayersPointsMM) do
		tablePlayersInMM[i] = {}
		tablePlayersInMM[i][1] = playerdata[player_nick]
		tablePlayersInMM[i][2] = playerdata[player_points]
		outputDebugString("function pointsMM_endRace (rank_mm) - nick: " ..playerdata[player_nick].. "/points: " ..playerdata[player_points], 3, 255, 0, 255)
	end

Link to comment

Your table is very simple. One column should be the key. Two other easier to keep as 2 columns.

Else you can try to store data in dbase table using lua user-data directly. But I am sure that this will not work due different data types (but you can try to use BLOB type).

The best solution for this, in my opinion, to use serialization(convert table to string, store, and then parse)

Link to comment

you were write that the table can be sent in triggerClientEvent and server-side I do not have the error

but the client side does not work :?::?::?:

what I'm doing wrong, how to draw nick and points from this table :?::?:

the entire table client-side is empty?

or bad draw from the table information?

server side:

function pointsMM_endRace (rank_mm)
	local allPlayersPointsMM = executeSQLQuery( "SELECT player_nick, player_points FROM stats_mm WHERE player_points > 0" )
	triggerClientEvent ( "onPlayerReSortMeTableRankMM", g_Root, allPlayersPointsMM)
end
addEvent('onPlayerFinish')
addEventHandler('onPlayerFinish', g_Root , pointsMM_endRace)

addEvent('onPlayerFinish')

addEventHandler('onPlayerFinish', g_Root , pointsMM_endRace)

client side:

local listaTop10name = {}
local listaTop10points = {}
function playerReSortMeTableRankMM(the_allPlayersPointsMM)
for i, k in ipairs(listaTop10points) do
	listaTop10points[i] = nil
end
local playersCountedInMM = 0
for i, playerdata in ipairs(the_allPlayersPointsMM) do
	listaTop10name = playerdata[player_nick]
	listaTop10points = playerdata[player_points]
	playersCountedInMM = i
	outputDebugString("function playerReSortMeTableRankMM(the_allPlayersPointsMM) - nick: " ..playerdata[player_nick].. "/points: " ..playerdata[player_points], 3, 255, 0, 255)
end
algorytmSortowania(playersCountedInMM)
end
addEvent( "onPlayerReSortMeTableRankMM", true )
addEventHandler( "onPlayerReSortMeTableRankMM", g_Root, playerReSortMeTableRankMM )

error on the client side:

ERROR: ...ods\deathmatch\resources\2paq-mm\stats-mm_client.lua:12: attempt to concatenate field '?' (a nil value)
Edited by Guest
Link to comment

What line you get this error at?

If you showed all your code here then you don't have player_nick variable declared anywhere. You try to get what's in table by variable which doesn't exist (thus 'nil value').

Use either: playerdata.player_nick or playerdata[ "player_nick" ].

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