01.01.2011, 04:27
Introduзгo
Resolvi fazer este Filterscript com base de um Tutorial americano,o sistema й 100% funcional e rбpido
Utiliza banco de dados *db
Pasta Plugar Jogar
Lembrando que estou utilizando GetPlayerScore para os Recordes
Basta Mudar:
Para array ou funзгo que deseja!
E Brevemente mais projetos relacionado a banco de dados.
Valeu Gente,Feliz 2011.
Paz e Amor.
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;
}
Lembrando que estou utilizando GetPlayerScore para os Recordes
Basta Mudar:
Код:
GetPlayerScore(playerid);
E Brevemente mais projetos relacionado a banco de dados.
Valeu Gente,Feliz 2011.
Paz e Amor.