Gravestone Posted August 28, 2016 Share Posted August 28, 2016 (edited) Hello everyone. I am creating something to save team kills when the resource stops. The kills are successfully saved but I want to load them when resource starts back, I mean the db is connected and sets the element (team) data to which it had before the resource had stopped. The coloumn in which the kills are stored is known as "Kills" and where the team name is before that column named "teamname". I tried this: addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), function () for i, team in ipairs(getElementsByType("team")) do local name = getTeamName(team) local data = getTeamData(name) outputChatBox(tostring(false)) setElementData(team, "Kills", data) end end ) function getTeamData(team) local results = dbPoll( dbQuery( connection, "SELECT * FROM claninfo WHERE teamname = ?", teamname), -1 ) if type(results) == "table" and #results == 0 or not results then return false else return results[2]["Kills"] end end Error: it is returning false Edited August 29, 2016 by Guest Link to comment
JR10 Posted August 29, 2016 Share Posted August 29, 2016 teamname is not defined in the getTeamData function. getTeamName Link to comment
Gravestone Posted August 30, 2016 Author Share Posted August 30, 2016 Alright so now I want to get all the data in the database even if the team doesn't exist. Table name: teaminfo Colum1: kills I load the team data when the resource starts but how do I load the data for the teams who don't exist but they were saved when the resource stopped? Link to comment
Simple0x47 Posted August 30, 2016 Share Posted August 30, 2016 If they're would been saved, they would exist. Explain better what are you tring to do, please. Link to comment
bebo1king Posted August 30, 2016 Share Posted August 30, 2016 addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), function () for i, team in ipairs(getElementsByType("team")) do local name = getTeamName(team) local data = getTeamData(name) if data ~= false then outputChatBox(tostring(false)) setElementData(team, "Kills", data) end end end ) function getTeamData(team) local results = dbPoll( dbQuery( connection, "SELECT * FROM claninfo WHERE teamname = ?", team), -1 ) if type(results) == "table" and #results == 0 or not results then return false else return results[2]["Kills"] end end Link to comment
Gravestone Posted August 31, 2016 Author Share Posted August 31, 2016 @Bebo1king, JR10 has already told me the solution. Thanks tho. Link to comment
Gravestone Posted September 1, 2016 Author Share Posted September 1, 2016 If they're would been saved, they would exist. Explain better what are you tring to do, please. I'm trying to say that two teams exist in the server, Ballas and Grove. I destroy one team by /destroyteam Grove so now only Ballas exists. I want to load the data for Grove as well and output it to the chatbox, how do I? Link to comment
Simple0x47 Posted September 1, 2016 Share Posted September 1, 2016 If you saved it's data on SQLite, then make use of dbQuery Link to comment
Gravestone Posted September 5, 2016 Author Share Posted September 5, 2016 function getTeams() local results = dbPoll( dbQuery( connection, "SELECT * FROM teaminfo WHERE teamname = ?"), -1 ) if type(results) == "table" and #results == 0 or not results then return false else return results[1]["teamname"] end end function doo() local names = getTeams() for i, v in ipairs(names) do outputChatBox(v) end end addCommandHandler("teams", doo) Tried this but the returns of the getTeams function are false even tho the table name is teaminfo and column name is teamname. Link to comment
Walid Posted September 5, 2016 Share Posted September 5, 2016 local results = dbPoll( dbQuery( connection, "SELECT * FROM teaminfo WHERE teamname = ?", Added team name here ), -1 ) -- added the team name Or try to use something like this . function getTeams() local data = dbPoll(dbQuery(connection,"SELECT * FROM teaminfo"), -1) return data end function doo(player) local names = getTeams() if names then for i, v in ipairs(names) do outputChatBox(v.teamname) end end end addCommandHandler("teams", doo) 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