steadyfi Posted March 7, 2015 Posted March 7, 2015 Hello I have a little problem. It's my first time when I use tables and I wonder how can I make my script work. This is what I do: 1. I loop through all of the accounts 2. Find the ones with the account data equal to what I need 3. Get the players name what is also stored as account data 4. Use table.insert to insert it into the table (then loop again from 1 until there is nothing left) 5. And pass the table Client-Side where I need it Client-Side Script: addEvent("openteams.getPlayersFromAccounts.serverGave", true) addEventHandler("openteams.getPlayersFromAccounts.serverGave", getRootElement(), function(playerTable) guiGridListClear(teamPlayersGrid) for index, player in ipairs(playerTable) do local row = guiGridListAddRow(teamPlayersGrid) guiGridListSetItemText(teamPlayersGrid, row, 1, player, false, false) getPlayerRow[players] = row end end) I also have a trigger: (Client-Side too) triggerServerEvent("openteams.getPlayersFromAccounts", localPlayer) Server-Side Script: addEvent("openteams.getPlayersFromAccounts", true) addEventHandler("openteams.getPlayersFromAccounts", getRootElement(), function() local team = getPlayerTeam(source) if team then --CODE local playerTable = {} local allAccounts = getAccounts() for _, account in ipairs(getAccounts()) do if getTeamName(team) == getAccountData(account, "openteams.team.name") then local playerName = getAccountData(account, "openteams.account.name") table.insert(playerTable, playerName) end end --END CODE triggerClientEvent(source, "openteams.getPlayersFromAccounts.serverGave", source, playerTable) end end) Hope you understand what I want to do, i tried my best to explain. Thank you My Work: OpenTeams | DayZ Admin Panel | vAuth Must-Have Library: MTA Lua Async ApocalipZ Owner coming back soon!
steadyfi Posted March 7, 2015 Author Posted March 7, 2015 Anyone ? My Work: OpenTeams | DayZ Admin Panel | vAuth Must-Have Library: MTA Lua Async ApocalipZ Owner coming back soon!
steadyfi Posted March 7, 2015 Author Posted March 7, 2015 debugscript 3? Oh, sorry. I completely forgot. Error: ERROR: openteams/client.lua:243: table index is nil My Work: OpenTeams | DayZ Admin Panel | vAuth Must-Have Library: MTA Lua Async ApocalipZ Owner coming back soon!
Enargy, Posted March 7, 2015 Posted March 7, 2015 EDIT:(not tested). --- SERVER addEvent("openteams.getPlayersFromAccounts", true) addEventHandler("openteams.getPlayersFromAccounts", getRootElement(), function() local team = getPlayerTeam(source) if team then --CODE local allAccounts = getAccounts() for _, account in ipairs(getAccounts()) do if getTeamName(team) == getAccountData(account, "openteams.team.name") then local playerName = getAccountData(account, "openteams.account.name") triggerClientEvent(source, "openteams.getPlayersFromAccounts.serverGave", source, playerName) end end --END CODE end end) ---CLIENT local playerTable = {} addEvent("openteams.getPlayersFromAccounts.serverGave", true) addEventHandler("openteams.getPlayersFromAccounts.serverGave", getRootElement(), function(pName) guiGridListClear(teamPlayersGrid) table.insert(playerTable, {pName}) for index, player in ipairs(playerTable) do local row = guiGridListAddRow(teamPlayersGrid) guiGridListSetItemText(teamPlayersGrid, row, 1, player, false, false) getPlayerRow[players] = row end end) - Inactivo.
steadyfi Posted March 7, 2015 Author Posted March 7, 2015 EDIT:(not tested). --- SERVER addEvent("openteams.getPlayersFromAccounts", true) addEventHandler("openteams.getPlayersFromAccounts", getRootElement(), function() local team = getPlayerTeam(source) if team then --CODE local allAccounts = getAccounts() for _, account in ipairs(getAccounts()) do if getTeamName(team) == getAccountData(account, "openteams.team.name") then local playerName = getAccountData(account, "openteams.account.name") triggerClientEvent(source, "openteams.getPlayersFromAccounts.serverGave", source, playerName) end end --END CODE end end) ---CLIENT local playerTable = {} addEvent("openteams.getPlayersFromAccounts.serverGave", true) addEventHandler("openteams.getPlayersFromAccounts.serverGave", getRootElement(), function(pName) guiGridListClear(teamPlayersGrid) table.insert(playerTable, {pName}) for index, player in ipairs(playerTable) do local row = guiGridListAddRow(teamPlayersGrid) guiGridListSetItemText(teamPlayersGrid, row, 1, player, false, false) getPlayerRow[players] = row end end) Didn't work. Error: My Work: OpenTeams | DayZ Admin Panel | vAuth Must-Have Library: MTA Lua Async ApocalipZ Owner coming back soon!
darhal Posted March 7, 2015 Posted March 7, 2015 Why you dont pass the elements that you need in players table to client side then insert them there #include <iostream> int main() { std::cout << "C++ is amazing <3" << std::endl; return 0; } I left MTA !... I m doing some tuts about (servers and scripting here) subscribe please
steadyfi Posted March 7, 2015 Author Posted March 7, 2015 Why you dont pass the elements that you need in players table to client side then insert them there I kinda imagine what you are talking about but i'm not sure. Could you please make it for me ? Like i said, it's the first time I use tables so I don't know anything about them. My Work: OpenTeams | DayZ Admin Panel | vAuth Must-Have Library: MTA Lua Async ApocalipZ Owner coming back soon!
darhal Posted March 7, 2015 Posted March 7, 2015 NearGreen code is correct just replace the line 31 with this getPlayerRow[player] = row dont forget to define the table outside the function local getPlayerRow = {} #include <iostream> int main() { std::cout << "C++ is amazing <3" << std::endl; return 0; } I left MTA !... I m doing some tuts about (servers and scripting here) subscribe please
Enargy, Posted March 7, 2015 Posted March 7, 2015 getPlayerRow[player] = row dont forget to define the table outside the function local getPlayerRow = {} I didnt see that, my wrong. - Inactivo.
steadyfi Posted March 7, 2015 Author Posted March 7, 2015 getPlayerRow[player] = row dont forget to define the table outside the function local getPlayerRow = {} I didnt see that, my wrong. Still getting an error My Work: OpenTeams | DayZ Admin Panel | vAuth Must-Have Library: MTA Lua Async ApocalipZ Owner coming back soon!
darhal Posted March 7, 2015 Posted March 7, 2015 guiGridListSetItemText(teamPlayersGrid, row, 1, player[index], false, false) replace that line (247) with this one of course this problem happen because player still a table and to access player namz you should put the table index #include <iostream> int main() { std::cout << "C++ is amazing <3" << std::endl; return 0; } I left MTA !... I m doing some tuts about (servers and scripting here) subscribe please
steadyfi Posted March 7, 2015 Author Posted March 7, 2015 guiGridListSetItemText(teamPlayersGrid, row, 1, player[index], false, false) replace that line (247) with this one of course this problem happen because player still a table and to access player namz you should put the table index It's working, but it still gives me an error: expected string at argument 4, got nil My Work: OpenTeams | DayZ Admin Panel | vAuth Must-Have Library: MTA Lua Async ApocalipZ Owner coming back soon!
darhal Posted March 7, 2015 Posted March 7, 2015 Ok hmmm post the new code #include <iostream> int main() { std::cout << "C++ is amazing <3" << std::endl; return 0; } I left MTA !... I m doing some tuts about (servers and scripting here) subscribe please
steadyfi Posted March 7, 2015 Author Posted March 7, 2015 Ok hmmm post the new code Client-Side: local playerTable = {} addEvent("openteams.getPlayersFromAccounts.serverGave", true) addEventHandler("openteams.getPlayersFromAccounts.serverGave", getRootElement(), function(pName) guiGridListClear(teamPlayersGrid) table.insert(playerTable, {pName}) for index, player in ipairs(playerTable) do local row = guiGridListAddRow(teamPlayersGrid) guiGridListSetItemText(teamPlayersGrid, row, 1, player[index], false, false) getPlayerRow[player] = row end end) The getPlayerRow = {} is also added, it's just not in this part of the file Server-Side: addEvent("openteams.getPlayersFromAccounts", true) addEventHandler("openteams.getPlayersFromAccounts", getRootElement(), function() local team = getPlayerTeam(source) if team then --CODE local allAccounts = getAccounts() for _, account in ipairs(getAccounts()) do if getTeamName(team) == getAccountData(account, "openteams.team.name") then local playerName = getAccountData(account, "openteams.account.name") triggerClientEvent(source, "openteams.getPlayersFromAccounts.serverGave", source, playerName) end end --END CODE end end) My Work: OpenTeams | DayZ Admin Panel | vAuth Must-Have Library: MTA Lua Async ApocalipZ Owner coming back soon!
darhal Posted March 7, 2015 Posted March 7, 2015 Oh my god its my mistake replace player[index] to player[1] #include <iostream> int main() { std::cout << "C++ is amazing <3" << std::endl; return 0; } I left MTA !... I m doing some tuts about (servers and scripting here) subscribe please
steadyfi Posted March 7, 2015 Author Posted March 7, 2015 (edited) Oh my god its my mistake replace player[index] to player[1] Ok, but it now duplicates everytime I run the function. The gridlist doesn't get cleared EDIT: Nevermind, I just added the table in my gui function so everytime when I open it the table gets reseted Edited March 7, 2015 by Guest My Work: OpenTeams | DayZ Admin Panel | vAuth Must-Have Library: MTA Lua Async ApocalipZ Owner coming back soon!
darhal Posted March 7, 2015 Posted March 7, 2015 (edited) All works fine now Edited March 7, 2015 by Guest #include <iostream> int main() { std::cout << "C++ is amazing <3" << std::endl; return 0; } I left MTA !... I m doing some tuts about (servers and scripting here) subscribe please
steadyfi Posted March 7, 2015 Author Posted March 7, 2015 Post code EDIT: Nevermind, I just added the table in my gui function so everytime when I open it the table gets reseted Thank you My Work: OpenTeams | DayZ Admin Panel | vAuth Must-Have Library: MTA Lua Async ApocalipZ Owner coming back soon!
darhal Posted March 7, 2015 Posted March 7, 2015 you are welcome #include <iostream> int main() { std::cout << "C++ is amazing <3" << std::endl; return 0; } I left MTA !... I m doing some tuts about (servers and scripting here) subscribe please
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