SHARE
TWEET

Untitled

a guest Apr 19th, 2019 109 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //ranks.inc by Jimmy (a_sampdb.inc)
  2.  
  3. #include "a_samp"
  4.  
  5. new DB:rankdb;
  6. new DBResult:result;
  7. new DBResult:resulttwo;
  8. new query[256];
  9.  
  10. public OnGameModeInit()
  11. {
  12.     rankdb = db_open("ranks.db");
  13.     return CallLocalFunction("_OnGameModeInit", "");
  14. }
  15. forward _OnGameModeInit();
  16.  
  17. stock createrank(rankname[]){
  18.  
  19.     format(query, 50, "SELECT * FROM %s", rankname);
  20.     result = db_query(rankdb, query);
  21.  
  22.     if(!db_num_rows(result)){
  23.  
  24.         query[0] = EOS;
  25.         format(query, 150, "CREATE TABLE IF NOT EXISTS %s (ID INTEGER PRIMARY KEY AUTOINCREMENT, NOME TEXT DEFAULT '', PONTOS INTEGER DEFAULT 0)", rankname);
  26.         db_query(rankdb, query);
  27.     }
  28.     return 1;
  29. }
  30.  
  31. stock atualizarrank(rankname, name[], pontos){
  32.  
  33.     query[0] = EOS;
  34.     format(query, 150, "SELECT NOME FROM %s WHERE NOME='%s' LIMIT 1" , rankname, name);
  35.     result = db_query(rankdb, query);
  36.  
  37.     if(db_num_rows(result)){
  38.    
  39.         format(query, 150, "UPDATE %s SET 'PONTOS'='%d' WHERE (`NOME` = '%s')" , rankname, pontos, name);
  40.         db_free_result(db_query(rankdb, query));
  41.     }
  42.     else if(!db_num_rows(result)){
  43.    
  44.         format(query, 160,  "INSERT INTO %s (`NOME`, 'PONTOS') VALUES('%s',%d)" , rankname, name, pontos);
  45.         db_free_result(db_query(rankdb, query));
  46.     }
  47.     return 1;
  48. }
  49.  
  50. stock getrank(rankname, maxrank = 10){
  51.  
  52.     format(query, 200, "SELECT `NOME` FROM %s ORDER BY ('PONTOS' * 1 ) DESC limit %d", rankname, maxrank);
  53.     result = db_query(rankdb, query);
  54.  
  55.     new zStrFormat[150], zStringTwo[128], zStrDlg[1024],;
  56.  
  57.     for(new a , zTotal = db_num_rows(result); a < zTotal ;a++ )
  58.     {
  59.         db_get_field(result, 0 , zStrFormat , 128 );
  60.         format(query, sizeof(query) , "SELECT 'PONTOS' FROM %s WHERE `NOME` ='%s'" , rankname, zStrFormat );
  61.         resulttwo = db_query(rankdb, query);
  62.         db_get_field(resulttwo, 0 , zStringTwo , 128 );
  63.  
  64.         format(zStrDlg , 1023 , "Lugar: %02d  | Pontos: %d    | Player: %s \n" , ( a + 1 ) , zStringTwo , zStrFormat );
  65.  
  66.         db_next_row(result);
  67.         db_free_result(resulttwo);
  68.     }
  69.     db_free_result(result);
  70.     ShowPlayerDialog(playerid, 0, DIALOG_STYLE_MSGBOX, "ranks", zStrDlg, "Fechar", "");
  71.     return 1;
  72. }
  73.  
  74. #if defined _ALS_OnGameModeInit
  75.     #undef OnGameModeInit
  76. #else
  77.     #define _ALS_OnGameModeInit
  78. #endif
  79. #define OnGameModeInit _OnGameModeInit
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top