Jump to content

A faster way..?


Recommended Posts

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

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
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
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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...