Jump to content

help, keeps adding more to the gridlist


Extinction

Recommended Posts

SERVER SIDE

function getCharacters()
local result = {}
local query = dbQuery(db, "SELECT * FROM characters WHERE account=?", getPlayerUsername(source))
result = dbPoll(query,-1)
dbFree(query)
  if #result > 0 then
     triggerClientEvent(client,"setCharacters",client,result)
  else
    triggerClientEvent(client,"setCharacters",client,{})
  end
end
addEvent("getCharacters",true)
addEventHandler("getCharacters", root, getCharacters)

CLIENT SIDE

charGrid = guiCreateGridList(0.37, 0.32, 0.31, 0.25, true)
guiGridListAddColumn(charGrid, "id", 0.3)
guiGridListAddColumn(charGrid, "name", 0.3)
guiGridListAddColumn(charGrid, "skin", 0.3)
guiSetVisible(charGrid, false)
guiSetVisible(playBtn, false)


function setData(tab)
for i=1,#tab do
local row = guiGridListAddRow ( charGrid )
guiGridListSetItemText ( charGrid, row, 1, tab[i]['id'] , false, false )
guiGridListSetItemText ( charGrid, row, 2, tab[i]['name'] , false, false )
guiGridListSetItemText ( charGrid, row, 3, tab[i]['skin'] , false, false )
end
end
addEvent("setCharacters",true)
addEventHandler("setCharacters",root,setData)
------------------------

function onClick()
if source == characters then
	triggerServerEvent("getCharacters",getLocalPlayer())
  end
end
addEventHandler("onClientGUIClick", root, onClick)

 

everytime i will click on characters button, it will keep adding more rows of the same character again and again, how can i fix this issue?

Link to comment
function setData(tab)
	guiGridListClear(charGrid)
	for i=1,#tab do
		local row = guiGridListAddRow ( charGrid )
		guiGridListSetItemText ( charGrid, row, 1, tab[i]['id'] , false, false )
		guiGridListSetItemText ( charGrid, row, 2, tab[i]['name'] , false, false )
		guiGridListSetItemText ( charGrid, row, 3, tab[i]['skin'] , false, false )
	end
end
addEvent("setCharacters",true)
addEventHandler("setCharacters",root,setData)

Try this one.

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