Gravestone Posted August 26, 2016 Share Posted August 26, 2016 (edited) I have created a gridlist which should display all the available team names but the problem is that the code only gets the team name of the first team tho it adds the correct number of rows to the column. e.g If there are 4 teams, Ballas, Grove, Aztecs and Vagos, it writes Ballas in all the four lines also it displays in the chatbox only Ballas. rankinggrid = guiCreateGridList(24, 58, 439, 240, false, Window) Edited August 30, 2016 by Guest Link to comment
!#NssoR_) Posted August 26, 2016 Share Posted August 26, 2016 rankinggrid = guiCreateGridList(24, 58, 439, 240, false, Window) guiGridListAddColumn(rankinggrid, "Team name", 0.2) for key,value in ipairs ( getElementsByType("team") ) do guiGridListAddRow(rankinggrid, getTeamName(value)) outputChatBox(getTeamName(value)) -- Added this for testing end Link to comment
LabiVila Posted August 26, 2016 Share Posted August 26, 2016 (edited) for _,v in ipairs (getElementsByType ("team")) do guiGridListAddRow (rankinggrid, getTeamName (v)) end Replace all your lines above with these ones, should work. So you literally don't need to 'unpack' the table when loops like this above exist. EDIT: I had the page open for like 30 minutes than I replied, didn't see your comment (the guy above) x) Edited August 29, 2016 by Guest Link to comment
!#NssoR_) Posted August 26, 2016 Share Posted August 26, 2016 for _,v in ipairs (getElementsByType ("team")) do guiGridListAddRow (rankinggrid, getTeamName (v)) end Replace all your lines above with these ones, should work. So you literally don't need to 'unpack' the table when loops like this above exist. what's the difference between your code and my code ! Link to comment
Gravestone Posted August 30, 2016 Author Share Posted August 30, 2016 Thanks, another thing. I am adding the team name with it's kills to a gridlist. I want to sort it according to the kills, how do I use this table.sort function in combination with this code? local allteams = getElementsByType("team") local function sort (a,b) return (getElementData(a,"Kills") or 0) > (getElementData(b,"Kills") or 0) end for key,value in ipairs (allteams) do local row = guiGridListAddRow(rankinggrid, getTeamName(value)) setTimer( function() local r, g, b = getTeamColor(value) local kills = getElementData(value, "Kills") guiGridListSetItemColor(rankinggrid, row, 1, r, g, b) guiGridListSetItemText(rankinggrid, row, 2, tonumber(kills), false, true) guiGridListSetItemColor(rankinggrid, row, 2, 0, 255, 0) end, 1000, 0) end And there's a problem with the above code, the teams keep moving if I click on the column name to sort. Link to comment
!#NssoR_) Posted August 30, 2016 Share Posted August 30, 2016 Thanks, another thing. I am adding the team name with it's kills to a gridlist. I want to sort it according to the kills, how do I use this table.sort function in combination with this code? local allteams = getElementsByType("team") local function sort (a,b) return (getElementData(a,"Kills") or 0) > (getElementData(b,"Kills") or 0) end for key,value in ipairs (allteams) do local row = guiGridListAddRow(rankinggrid, getTeamName(value)) setTimer( function() local r, g, b = getTeamColor(value) local kills = getElementData(value, "Kills") guiGridListSetItemColor(rankinggrid, row, 1, r, g, b) guiGridListSetItemText(rankinggrid, row, 2, tonumber(kills), false, true) guiGridListSetItemColor(rankinggrid, row, 2, 0, 255, 0) end, 1000, 0) end And there's a problem with the above code, the teams keep moving if I click on the column name to sort. for The first Problem . How to create a list of highest to lowest And about Teams Sorting. guiGridListSetSortingEnabled Link to comment
Gravestone Posted August 30, 2016 Author Share Posted August 30, 2016 (edited) table.sort only sorts number values so even if the kills are sorted, how do I sort the teams according to the kills? Edit: Tried this and adds the values successfully according to the kills but it doesn't change the order in the gridlist every second if the data changes of a team. Restart is required. kills = {} setTimer(function () for _,team in ipairs (getElementsByType ("team")) do -- local account = getPlayerAccount (player) local teamkills = getElementData (team, "Kills") if not table.contains(kills, teamkills) then table.insert (kills, teamkills) end end function sortData() setTimer(function() table.sort (percentages, function (a, b) return a > b end )end, 1000, 0) for _,v in ipairs (kills) do for _,team in ipairs (getElementsByType ("team")) do local teamkills = getElementData (team, "Kills") if v == teamkills then -- outputChatBox("Team "..getTeamName(team).." has "..v) if not isTextInGridList(rankinggrid, getTeamName(team)) then local row = guiGridListAddRow(rankinggrid, getTeamName(team)) setTimer( function() local r, g, b = getTeamColor(team) local kills = getElementData(team, "Kills") guiGridListSetItemColor(rankinggrid, row, 1, r, g, b) guiGridListSetItemText(rankinggrid, row, 2, tonumber(kills), false, true) guiGridListSetItemColor(rankinggrid, row, 2, 0, 255, 0) end end end end , 1000, 0) end setTimer (sortData, 1000, 0) Edited August 30, 2016 by Guest Link to comment
GTX Posted August 30, 2016 Share Posted August 30, 2016 1. Percentages table isn't defined 2. Gridlist sorting should sort just fine, why do you need to sort it again? 3. Use guiGridListClear and add rows again to refresh and add new teams. 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