[FilterScript] Sistema de Rank DataBase
#1

Introduзгo
Resolvi fazer este Filterscript com base de um Tutorial americano,o sistema й 100% funcional e rбpido

Utiliza banco de dados *db

pawn Код:
#include <a_samp.inc>

#define MAX_CHARS 56            //Mбximo de caracters por palavras
#define MAX_STRNS 256           //Mбximo de string de dados
#define BASE_NOME "Players.db"  //Arquivo para salvar os dados

static
        zStringTwo[128] ,
        DBResult:sResult ,
        DBResult:sResultTwo ,
        zStrFormat[150],
        DB:DataBase,
        zStrDlg[1024],
        zQuery[MAX_STRNS]
;


public
    OnFilterScriptInit()
{
    DataBase = db_open(BASE_NOME);
    format(zQuery , sizeof(zQuery ) , "CREATE TABLE IF NOT EXISTS `Usuarios` (`Nome` , 'Pontos' )" ) ;
    db_free_result(db_query(DataBase , zQuery ) ) ;
    return true;
}

public
    OnPlayerDisconnect(playerid,reason)
{
    SaveDataRankPlayer(playerid);
    return true;
}

public
    OnPlayerCommandText(playerid, cmdtext[])
{
    if(!strcmp(cmdtext, "/ver-rank", true))
    {
        LoadDataRankPlayer(playerid);
        return true;
    }
    if(!strcmp(cmdtext, "/save-rank", true))
    {
        for(new a; a < 500; a++)
            if(IsPlayerConnected(a))
                SaveDataRankPlayer(a);
        return true;
    }
    if(!strcmp(cmdtext, "/ajuda-rank", true))
    {
        SendClientMessage(playerid,0xFFFFFF,"- Sistema de Rank DataBase -");
        SendClientMessage(playerid,0xFFFFFF,"-      http://www.feksquad.net  -");
        SendClientMessage(playerid,0xFFFFFF,"/ver-rank > Veja o Rank");
        SendClientMessage(playerid,0xFFFFFF,"/save-rank > Salve o Rank");
        return true;
    }
    return false;
}

stock
    SaveDataRankPlayer(playerid)
{
    format(zQuery , 150 , "SELECT `Nome` FROM `Usuarios` WHERE `Nome`='%s' LIMIT 1" , GetPlayerNick(playerid ) );
    sResult = db_query(DataBase , zQuery );
    if (db_num_rows(sResult ) == 1 )
    {
        format(zQuery , 150 , "UPDATE `Usuarios` SET 'Pontos'='%d' WHERE (`Nome` = '%s')" , GetPlayerScore(playerid ) , GetPlayerNick(playerid ) );
        db_free_result(db_query(DataBase , zQuery ) );
    }
    else if (db_num_rows(sResult ) == 0 )
    {
        format(zQuery , 160 ,  "INSERT INTO `Usuarios` (`Nome`, 'Pontos') VALUES('%s',%d)" , GetPlayerNick(playerid ) , GetPlayerScore(playerid ) );
        db_free_result(db_query(DataBase , zQuery ) );
    }
    return true;
}

stock
    LoadDataRankPlayer(playerid,maxrank = 10)
{
    format(zQuery , 200 , "SELECT `Nome` FROM `Usuarios` ORDER BY ('Pontos' * 1 ) DESC limit %d",maxrank);
    sResult = db_query(DataBase , zQuery );
    format(zStrDlg ,  sizeof(zStrDlg ) , "<<<<<<<<<<<<<<<<<<<<<<<<*>>>>>>>>>>>>>>>>>>>>>>>>\r\n" );
    for(new a , zTotal = db_num_rows(sResult ); a < zTotal ;a++ )
    {
        db_get_field(sResult , 0 , zStrFormat , 128 );
        format(zQuery , sizeof(zQuery ) , "SELECT 'Pontos' FROM `Usuarios` WHERE `Nome` ='%s'" , zStrFormat );
        sResultTwo = db_query(DataBase , zQuery );
        db_get_field(sResultTwo , 0 , zStringTwo , 128 );

        format(zStrDlg , 1023 , "%sLugar: %02d  | Pontos: %d    | Player: %s \n" , zStrDlg , ( a + 1 ) , zStringTwo , zStrFormat );

        db_next_row(sResult );
        db_free_result(sResultTwo );
    }
    db_free_result(sResult );
    ShowPlayerDialog(playerid , 122 , DIALOG_STYLE_MSGBOX , "Sistema de Ranks [FeK]" , zStrDlg , "Fechar" ,  "" );
    return true;
}

stock
    GetPlayerNick(playerid)
{
    static Naming[24];
    GetPlayerName(playerid,Naming,24);
    return Naming;
}
Pasta Plugar Jogar


Lembrando que estou utilizando GetPlayerScore para os Recordes

Basta Mudar:
Код:
GetPlayerScore(playerid);
Para array ou funзгo que deseja!

E Brevemente mais projetos relacionado a banco de dados.

Valeu Gente,Feliz 2011.

Paz e Amor.
Reply


Messages In This Thread
Sistema de Rank DataBase - by ipsBruno - 01.01.2011, 04:27
Respuesta: Sistema de Rank DataBase - by Ichigo_Kurosaki - 01.01.2011, 10:12
AW: Sistema de Rank DataBase - by [Banido]HigorOliver - 01.01.2011, 10:33
Re: Sistema de Rank DataBase - by PsyShotter - 01.01.2011, 11:44
Respuesta: AW: Sistema de Rank DataBase - by Ichigo_Kurosaki - 01.01.2011, 12:13
Respuesta: Re: Sistema de Rank DataBase - by ipsBruno - 01.01.2011, 14:27
AW: Sistema de Rank DataBase - by [Banido]HigorOliver - 01.01.2011, 14:58
Respuesta: Sistema de Rank DataBase - by ipsBruno - 01.01.2011, 15:19
AW: Respuesta: Sistema de Rank DataBase - by [Banido]HigorOliver - 01.01.2011, 16:03
Respuesta: Sistema de Rank DataBase - by Ichigo_Kurosaki - 01.01.2011, 18:27

Forum Jump:


Users browsing this thread: 1 Guest(s)