Jump to content

SQL Data ranking players


freudo

Recommended Posts

Hey I want ranking players for experience.

Example:

Scoreboard exam:

playername experience rank

barikat 25000 1.

skyturk 12055 2.

Can you help me?

Example codes:

Checking experience

function getPlayerExperiencet(thePlayer) 
    local handler = connection 
    if (isElement(thePlayer) and getElementType(thePlayer) == "player") then 
        account = getPlayerAccount(thePlayer) 
    else 
        account = thePlayer 
    end 
    if (not account or isGuestAccount(account)) then return false end 
    local accountName = getAccountName(account) 
    local query = dbQuery( handler, "SELECT experiencet FROM `levels` WHERE accountName='".. tostring(accountName) .."'") 
    local result, numrows, errmsg = dbPoll( query, -1 ) 
    if (result) then 
        return tonumber(result[1]["experiencet"]) 
    end 
end 

Link to comment

I have only account rank system

How to I change to SQL

function getAllRankSB() 
     local tableOrder = { } 
            for i, v in ipairs ( getAccounts ( ) ) do 
                table.insert ( 
                    tableOrder, 
                    { 
                        name = getAccountName(v), 
                        data = getAccountData ( v, "experiencet" ) 
                    } 
                ) 
            end 
            table.sort ( 
                tableOrder, 
                function ( a, b ) 
                    return ( tonumber ( a.data ) or 0 ) > ( tonumber ( b.data ) or 0 ) 
                end 
            ) 
    for i,player in pairs(getElementsByType("player")) do 
        if not (isGuestAccount(getPlayerAccount(player))) then 
            for i=1,#tableOrder do 
                if tableOrder[i].name == getAccountName(getPlayerAccount(player)) then 
                    setElementData(player,"Sıra",i) 
                end 
            end 
        end 
    end 
    outputDebugString("Updating rank for all player") 
end 
setTimer(function() getAllRankSB() end,300000,0) 

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