Gravestone Posted August 28, 2016 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 Clan war system http://sh.st/7r4nI
JR10 Posted August 29, 2016 Posted August 29, 2016 teamname is not defined in the getTeamData function. getTeamName Business System viewtopic.php?f=108&t=35797 Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726 SQLite Tutorial viewtopic.php?f=148&t=38203
Gravestone Posted August 29, 2016 Author Posted August 29, 2016 wrong Clan war system http://sh.st/7r4nI
Gravestone Posted August 30, 2016 Author 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? Clan war system http://sh.st/7r4nI
Simple0x47 Posted August 30, 2016 Posted August 30, 2016 If they're would been saved, they would exist. Explain better what are you tring to do, please. "Keep making it simplex."
bebo1king Posted August 30, 2016 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 Skype :bebo.ahmad34 My channel on youtupe : https://www.youtube.com/channel/UCOXfmMopyyBL5NBeO0RS04g/videos
Gravestone Posted August 31, 2016 Author Posted August 31, 2016 @Bebo1king, JR10 has already told me the solution. Thanks tho. Clan war system http://sh.st/7r4nI
Gravestone Posted September 1, 2016 Author 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? Clan war system http://sh.st/7r4nI
Simple0x47 Posted September 1, 2016 Posted September 1, 2016 If you saved it's data on SQLite, then make use of dbQuery "Keep making it simplex."
Gravestone Posted September 5, 2016 Author 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. Clan war system http://sh.st/7r4nI
Walid Posted September 5, 2016 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) Do not yield your back to your enemy, might feel something strange in your ass. Two things are infinite the universe and human stupidity and i'm not sure about the universe. UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators
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