Feche1320 Posted May 7, 2011 Share Posted May 7, 2011 Everytime a maps ends, a maps played counter will increase by one. The way I do it is like this: addEvent("onPostFinish", true) addEventHandler("onPostFinish", g_Root, function() for i, player in ipairs(getElementsByType("player")) do if getElementData(player, "isLogged") == true then local mapsplayed = executeSQLSelect("stats", "mapsplayed", "account = '" ..getElementData(player, "playerAcc").. "'") executeSQLUpdate("stats", "mapsplayed = '" ..(mapsplayed+1).. "'", "account = '" ..getElementData(player, "playerAcc").. "'") end end end ) As you can see, I'm using executeSQLSelect to get the value into a variable, and then executeSQLUpdate to add +1 to the variable, but is there a faster way like just add +1 inside executeSQLUpdate without have to use every time executeSQLSelect and a variable? Something like: addEvent("onPostFinish", true) addEventHandler("onPostFinish", g_Root, function() for i, player in ipairs(getElementsByType("player")) do if getElementData(player, "isLogged") == true then executeSQLUpdate("stats", "mapsplayed = '+1'", "account = '" ..getElementData(player, "playerAcc").. "'") end end end ) Thanks. Link to comment
Castillo Posted May 8, 2011 Share Posted May 8, 2011 Try this: addEvent("onPostFinish", true) addEventHandler("onPostFinish", g_Root, function() for i, player in ipairs(getElementsByType("player")) do if getElementData(player, "isLogged") == true then local mapsplayed = executeSQLSelect("stats", "mapsplayed", "account = '" ..getElementData(player, "playerAcc").. "'") local newvalue = tonumber(mapsplayed[1]["mapsplayed"]) +1 executeSQLUpdate("stats", "mapsplayed = '".. newvalue .."'", "account = '".. getElementData(player, "playerAcc") .."'") end end end ) Link to comment
wannaknow Posted May 10, 2011 Share Posted May 10, 2011 Try this: addEvent("onPostFinish", true) addEventHandler("onPostFinish", g_Root, function() for i, player in ipairs(getElementsByType("player")) do if getElementData(player, "isLogged") == true then executeSQLUpdate("stats", "mapsplayed = mapsplayed +1", "account = '".. getElementData(player, "playerAcc") .."'") end end end ) Link to comment
Feche1320 Posted May 10, 2011 Author Share Posted May 10, 2011 Try this: addEvent("onPostFinish", true) addEventHandler("onPostFinish", g_Root, function() for i, player in ipairs(getElementsByType("player")) do if getElementData(player, "isLogged") == true then executeSQLUpdate("stats", "mapsplayed = mapsplayed +1", "account = '".. getElementData(player, "playerAcc") .."'") end end end ) Thank you! 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