MisterQuestions Posted April 17, 2015 Posted April 17, 2015 It is possible to order elements from a table For example a players table, order players with team first, then players without team. It is possible make that? How? "El conocimiento jamás debe detenerse, por que es lo único que nos salvará cuando no nos quede más". Att: -|TG|-Mister[Q]<.
Ryancit2 Posted April 17, 2015 Posted April 17, 2015 Try this: function getAllPlayers() local pTable = {} local teams = getElementsByType("team") if (not teams) then return end for k, v in pairs(teams) do local plrs = getPlayersInTeam(v) if (not plrs) then return end pTable[getTeamName(v)] = plrs end return pTable end You can call this function in other functions by typing getAllPlayers() and it will return a teable like this: teams ={ ['teamName'] = {plr, plr, plr, plr}, ['otherTeam'] = {plr, plr, plr, plr} } -- Use it like this: for k, v in pairs(teams) do for i, d in pairs(v) do outputChatBox("Player "..getPlayerName(d).." is in team "..k) end end or i made another function like this, it contains players without team names: function getAllPlayersV2() local pTable = {} local teams = getElementsByType("team") if (not teams) then return end for k, v in pairs(teams) do local plrs = getPlayersInTeam(v) if (not plrs) then return end for i, d in pairs(plrs) do pTable[#pTable+1] = d end end return pTable end You can call this function in other functions like getAllPlayersV2() and will get table like this: teams = { [1] = plr, [2] = plr, [3] = plr, [4] = plr } -- And use it like this: for k, v in pairs(teams) do outputChatBox(getPlayerName(v)) -- Will output players per team in a row. end [Resource] Advance Voice Messaging system with 120+ languages support! [Resource] Information markers with ingame management + editable permissions! [Resource] Live weather telling app! [Resource] Send Emails from game! [HELP?] Ask Pakistani's, have fun %3C3
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