Advertisement
DelKxD

Sistema de HeadShot MySql - DelK

Jan 2nd, 2018
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 12.54 KB | None | 0 0
  1. //=============Defines===================//
  2. #define FILTERSCRIPT
  3. #if defined FILTERSCRIPT
  4.  
  5. #define     Dialog_Top10    1
  6. #define     Dialog_NA       2
  7. #define     Dialog_Registro 3
  8. #define     Dialog_Login    4
  9.  
  10. #define     Host            "localhost"
  11. #define     Usuario         "root"
  12. #define     Senha           ""
  13. #define     Database        "HeadShot"
  14. //============Includes==================//
  15. #include a_samp
  16. #include a_mysql
  17. #include izcmd
  18.  
  19. enum Info
  20. {
  21.     DHeadShots,
  22.     DHsTomados,
  23.     DKills,
  24.     mID
  25. }
  26. new Dados[MAX_PLAYERS][Info];
  27. new MySQL:ConexaoBDD, Query[300];
  28. new Text:TDEditor_TD[6];
  29.  
  30. public OnFilterScriptInit()
  31. {
  32.     print("--------------------------------------");
  33.     print("Sistema de DHeadShots Carregado by: DelK");
  34.     print("--------------------------------------");
  35.    
  36.     ConexaoBDD = mysql_connect(Host, Usuario, Senha, Database);
  37.     if(mysql_errno(ConexaoBDD) != 0) printf("Falha na conexao com o banco de dados MySQL [error %d]", mysql_errno(ConexaoBDD));
  38.     else print("Conexao com o banco de dados MySQL estabelecida com sucesso");
  39.     mysql_query(ConexaoBDD, "CREATE TABLE IF NOT EXISTS Ranking(ID int AUTO_INCREMENT PRIMARY KEY, Nick varchar(24) NOT NULL, DHeadShots int NOT NULL, DHSTomados int NOT NULL, DKills int NOT NULL)", false);
  40.  
  41.     TDEditor_TD[0] = TextDrawCreate(254.939559, 106.649986, "__HeadShot~n~____~n~~n~");
  42.     TextDrawLetterSize(TDEditor_TD[0], 0.703526, 2.539165);
  43.     TextDrawTextSize(TDEditor_TD[0], 416.000000, 0.000000);
  44.     TextDrawAlignment(TDEditor_TD[0], 1);
  45.     TextDrawColor(TDEditor_TD[0], -1);
  46.     TextDrawUseBox(TDEditor_TD[0], 1);
  47.     TextDrawBoxColor(TDEditor_TD[0], 370546326);
  48.     TextDrawSetShadow(TDEditor_TD[0], 0);
  49.     TextDrawSetOutline(TDEditor_TD[0], 1);
  50.     TextDrawBackgroundColor(TDEditor_TD[0], -16776961);
  51.     TextDrawFont(TDEditor_TD[0], 1);
  52.     TextDrawSetProportional(TDEditor_TD[0], 1);
  53.  
  54.     TDEditor_TD[1] = TextDrawCreate(292.774566, 128.435012, "Detalhes_de_sua_morte");
  55.     TextDrawLetterSize(TDEditor_TD[1], 0.230114, 0.888329);
  56.     TextDrawAlignment(TDEditor_TD[1], 1);
  57.     TextDrawColor(TDEditor_TD[1], -16776961);
  58.     TextDrawSetShadow(TDEditor_TD[1], 0);
  59.     TextDrawSetOutline(TDEditor_TD[1], 0);
  60.     TextDrawBackgroundColor(TDEditor_TD[1], 370546198);
  61.     TextDrawFont(TDEditor_TD[1], 1);
  62.     TextDrawSetProportional(TDEditor_TD[1], 1);
  63.  
  64.     TDEditor_TD[2] = TextDrawCreate(253.770202, 138.534988, "Arma:_%s");
  65.     TextDrawLetterSize(TDEditor_TD[2], 0.230114, 0.888329);
  66.     TextDrawAlignment(TDEditor_TD[2], 1);
  67.     TextDrawColor(TDEditor_TD[2], -1378294017);
  68.     TextDrawSetShadow(TDEditor_TD[2], 0);
  69.     TextDrawSetOutline(TDEditor_TD[2], 1);
  70.     TextDrawBackgroundColor(TDEditor_TD[2], 1296911693);
  71.     TextDrawFont(TDEditor_TD[2], 1);
  72.     TextDrawSetProportional(TDEditor_TD[2], 1);
  73.  
  74.     TDEditor_TD[3] = TextDrawCreate(253.629074, 147.351791, "Dano:_100");
  75.     TextDrawLetterSize(TDEditor_TD[3], 0.230114, 0.888329);
  76.     TextDrawAlignment(TDEditor_TD[3], 1);
  77.     TextDrawColor(TDEditor_TD[3], -1378294017);
  78.     TextDrawSetShadow(TDEditor_TD[3], 0);
  79.     TextDrawSetOutline(TDEditor_TD[3], 1);
  80.     TextDrawBackgroundColor(TDEditor_TD[3], 1296911693);
  81.     TextDrawFont(TDEditor_TD[3], 1);
  82.     TextDrawSetProportional(TDEditor_TD[3], 1);
  83.  
  84.     TDEditor_TD[4] = TextDrawCreate(253.629074, 156.552352, "Distancia:_%f");
  85.     TextDrawLetterSize(TDEditor_TD[4], 0.230114, 0.888329);
  86.     TextDrawAlignment(TDEditor_TD[4], 1);
  87.     TextDrawColor(TDEditor_TD[4], -1378294017);
  88.     TextDrawSetShadow(TDEditor_TD[4], 0);
  89.     TextDrawSetOutline(TDEditor_TD[4], 1);
  90.     TextDrawBackgroundColor(TDEditor_TD[4], 1296911693);
  91.     TextDrawFont(TDEditor_TD[4], 1);
  92.     TextDrawSetProportional(TDEditor_TD[4], 1);
  93.  
  94.     TDEditor_TD[5] = TextDrawCreate(253.629074, 169.653152, "Voce_levou_um_headshot_de:_%s");
  95.     TextDrawLetterSize(TDEditor_TD[5], 0.230114, 0.888329);
  96.     TextDrawAlignment(TDEditor_TD[5], 1);
  97.     TextDrawColor(TDEditor_TD[5], -1378294017);
  98.     TextDrawSetShadow(TDEditor_TD[5], 0);
  99.     TextDrawSetOutline(TDEditor_TD[5], 1);
  100.     TextDrawBackgroundColor(TDEditor_TD[5], 370546198);
  101.     TextDrawFont(TDEditor_TD[5], 1);
  102.     TextDrawSetProportional(TDEditor_TD[5], 1);
  103.     return 1;
  104. }
  105.  
  106. #endif
  107.  
  108. public OnFilterScriptExit()
  109. {
  110.     mysql_close(ConexaoBDD);
  111.     return 1;
  112. }
  113.  
  114. public OnPlayerConnect(playerid)
  115. {
  116.     new row;
  117.     mysql_format(ConexaoBDD, Query, sizeof(Query), "SELECT * FROM `Ranking` WHERE `Nick`='%s'", Nome(playerid));
  118.     mysql_query(ConexaoBDD, Query, true);
  119.     cache_get_row_count(row);
  120.     if(row > 0)
  121.     {
  122.         ShowPlayerDialog(playerid, Dialog_Login, DIALOG_STYLE_MSGBOX, "Base - Não use", "Logando", "Logar", "Sair");
  123.     }
  124.     else
  125.     {
  126.         ShowPlayerDialog(playerid, Dialog_Registro, DIALOG_STYLE_MSGBOX, "Base - Não use", "Registrando", "Registrar", "Sair");
  127.     }
  128.     return 1;
  129. }
  130.  
  131. public OnPlayerDisconnect(playerid, reason)
  132. {
  133.     AtualizarRanking();
  134.     return 1;
  135. }
  136.  
  137. public OnPlayerDeath(playerid, killerid, reason)
  138. {
  139.     SendDeathMessage(killerid, playerid, reason);
  140.     if(killerid != INVALID_PLAYER_ID)
  141.     {
  142.         Dados[killerid][DKills]++;
  143.     }
  144.     SetTimerEx("Morto", 1500, false, "i", playerid);
  145.     return 1;
  146. }
  147.  
  148. forward Morto(playerid);
  149. public Morto(playerid)
  150. {
  151.     SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
  152.     for(new i = 0; i < 7; i++) TextDrawHideForPlayer(playerid, TDEditor_TD[i]);
  153.     return 1;
  154. }
  155.  
  156. public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid, bodypart)
  157. {
  158.     if(issuerid != INVALID_PLAYER_ID && bodypart == 9)
  159.     {
  160.         new string[55], Float: Distancia;
  161.         Distancia = GetDistanciaEntrePlayers(issuerid, playerid);
  162.         SetPlayerHealth(playerid, 0);
  163.         format(string, sizeof(string), "Arma:_%s", Weapon(issuerid));
  164.         TextDrawSetString(TDEditor_TD[2], string);
  165.         format(string, sizeof(string), "Distancia:_%.1f Metros", Distancia);
  166.         TextDrawSetString(TDEditor_TD[4], string);
  167.         format(string, sizeof(string), "Voce_levou_um_headshot_de:_%s", Nome(issuerid));
  168.         TextDrawSetString(TDEditor_TD[5], string);
  169.         for(new i = 0; i < 6; i++) TextDrawShowForPlayer(playerid, TDEditor_TD[i]);
  170.         if(issuerid != INVALID_PLAYER_ID)
  171.         {
  172.             Dados[issuerid][DHeadShots]++;
  173.             Dados[playerid][DHsTomados]++;
  174.         }
  175.         AtualizarRanking();
  176.     }
  177.     return 1;
  178. }
  179.  
  180. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  181. {
  182.     if(dialogid == Dialog_Registro)
  183.     {
  184.         if(!response) return Kick(playerid);
  185.         if(response)
  186.         {
  187.             format(Query, sizeof(Query), "INSERT INTO `Ranking` (Nick, DHeadShots, DHSTomados, DKills) VALUES ('%s', '0', '0','0')", Nome(playerid));
  188.             mysql_query(ConexaoBDD, Query, true);
  189.             Dados[playerid][mID] = cache_insert_id();
  190.             return 1;
  191.         }
  192.         return 1;
  193.     }
  194.     if(dialogid == Dialog_Login)
  195.     {
  196.         if(!response) return Kick(playerid);
  197.         if(response)
  198.         {
  199.             CarregarRanking(playerid);
  200.             SendClientMessage(playerid, -1, "Logado com sucesso!");
  201.             return 1;
  202.         }
  203.         return 1;
  204.     }
  205.     if(dialogid == Dialog_Top10)
  206.     {
  207.         new QueryHeadShot[100];
  208.         if(response)
  209.         {
  210.             if(listitem == 0)
  211.             {
  212.                 format(QueryHeadShot, sizeof(QueryHeadShot), "SELECT `Nick`, `DHeadShots` FROM `Ranking` WHERE `DHeadShots`>'0' ORDER BY DHeadShots DESC LIMIT 10;");
  213.                 mysql_tquery(ConexaoBDD, QueryHeadShot, "TopHSs", "i", playerid);
  214.             }
  215.             if(listitem == 1)
  216.             {
  217.                 format(QueryHeadShot, sizeof(QueryHeadShot), "SELECT `Nick`, `DHSTomados` FROM `Ranking` WHERE `DHSTomados`>'0' ORDER BY DHSTomados DESC LIMIT 10;");
  218.                 mysql_tquery(ConexaoBDD, QueryHeadShot, "TopHSTomados", "i", playerid);
  219.             }
  220.             if(listitem == 2)
  221.             {
  222.                 format(QueryHeadShot, sizeof(QueryHeadShot), "SELECT `Nick`, `DKills` FROM `Ranking` WHERE `DKills`>'0' ORDER BY DKills DESC LIMIT 10;");
  223.                 mysql_tquery(ConexaoBDD, QueryHeadShot, "TopKills", "i", playerid);
  224.             }
  225.         }
  226.     }
  227.     switch(dialogid)
  228.     {
  229.         case Dialog_NA: if(response) return ShowPlayerDialog(playerid, Dialog_Top10, DIALOG_STYLE_LIST, "#Ranking MySQL!", "DHeadShots\nDHsTomados\nDKills", "Confirmar", "Cancelar");
  230.     }
  231.     return 1;
  232. }
  233.  
  234. CMD:armas(playerid)
  235. {
  236.     GivePlayerWeapon(playerid, 24, 999);
  237.     GivePlayerWeapon(playerid, 25, 999);
  238.     GivePlayerWeapon(playerid, 29, 999);
  239.     GivePlayerWeapon(playerid, 31, 999);
  240.     GivePlayerWeapon(playerid, 32, 999);
  241.     GivePlayerWeapon(playerid, 34, 999);
  242.     return 1;
  243. }
  244.  
  245. CMD:top10(playerid)
  246. {
  247.     AtualizarRanking();
  248.     ShowPlayerDialog(playerid, Dialog_Top10, DIALOG_STYLE_LIST, "#Ranking MySQL!", "DHeadShots\nDHSTomados\nDKills", "Confirmar", "Cancelar");
  249.     return 1;
  250. }
  251.  
  252. forward TopHSs(playerid);
  253. public TopHSs(playerid)
  254. {
  255.     new string[200], Nick[70], HSs, contagem = 0;
  256.     for(new i, r = cache_num_rows(); i < r; ++i)
  257.     {
  258.         cache_get_value_name(i, "Nick", Nick);
  259.         cache_get_value_name_int(i, "DHeadShots", HSs);
  260.         format(string, sizeof(string),"%sNª %d° - %s | HeadShots: %d | %s\n\n{FFFFFF}", string, i+1, Nick, HSs, (GetPlayerConnect(Nick) == INVALID_PLAYER_ID ? ("{8B0000}Desconectado"):("{00FF00}Conectado")));
  261.         contagem++;
  262.     }
  263.     ShowPlayerDialog(playerid, Dialog_NA, DIALOG_STYLE_MSGBOX, "#Ranking HeadShots!", string, "Voltar", "Fechar");
  264.     if(contagem == 0) return ShowPlayerDialog(playerid, Dialog_NA, DIALOG_STYLE_MSGBOX, "#Ranking HeadShots!", "Não tem ninguém no Ranking de HeadShots!\n", "Voltar", "Fechar");
  265.     return 1;
  266. }
  267.  
  268. forward TopHSTomados(playerid);
  269. public TopHSTomados(playerid)
  270. {
  271.     new string[200], Nick[70], HSs, contagem = 0;
  272.     for(new i, r = cache_num_rows(); i < r; ++i)
  273.     {
  274.         cache_get_value_name(i, "Nick", Nick);
  275.         cache_get_value_name_int(i, "DHSTomados", HSs);
  276.         format(string, sizeof(string),"%sNª %d° - %s | DHSTomados: %d | %s\n\n{FFFFFF}", string, i+1, Nick, HSs, (GetPlayerConnect(Nick) == INVALID_PLAYER_ID ? ("{8B0000}Desconectado"):("{00FF00}Conectado")));
  277.         contagem++;
  278.     }
  279.     ShowPlayerDialog(playerid, Dialog_NA, DIALOG_STYLE_MSGBOX, "#Ranking DHSTomados!", string, "Voltar", "Fechar");
  280.     if(contagem == 0) return ShowPlayerDialog(playerid, Dialog_NA, DIALOG_STYLE_MSGBOX, "#Ranking DHSTomados!", "Não tem ninguém no Ranking de DHSTomados!\n", "Voltar", "Fechar");
  281.     return 1;
  282. }
  283.  
  284. forward TopKills(playerid);
  285. public TopKills(playerid)
  286. {
  287.     new string[200], Nick[70], HSs, contagem = 0;
  288.     for(new i, r = cache_num_rows(); i < r; ++i)
  289.     {
  290.         cache_get_value_name(i, "Nick", Nick);
  291.         cache_get_value_name_int(i, "DKills", HSs);
  292.         format(string, sizeof(string),"%sNª %d° - %s | DKills: %d | %s\n\n{FFFFFF}", string, i+1, Nick, HSs, (GetPlayerConnect(Nick) == INVALID_PLAYER_ID ? ("{8B0000}Desconectado"):("{00FF00}Conectado")));
  293.         contagem++;
  294.     }
  295.     ShowPlayerDialog(playerid, Dialog_NA, DIALOG_STYLE_MSGBOX, "#Ranking DKills!", string, "Voltar", "Fechar");
  296.     if(contagem == 0) return ShowPlayerDialog(playerid, Dialog_NA, DIALOG_STYLE_MSGBOX, "#Ranking DKills!", "Não tem ninguém no Ranking de DKills!\n", "Voltar", "Fechar");
  297.     return 1;
  298. }
  299.  
  300. stock CarregarRanking(playerid)
  301. {
  302.     format(Query, sizeof(Query), "SELECT * FROM `Ranking` WHERE `Nick`='%s'", Nome(playerid));
  303.     mysql_query(ConexaoBDD, Query, true);
  304.     cache_get_value_name_int(0, "ID", Dados[playerid][mID]);
  305.     cache_get_value_name_int(0, "DHeadShots", Dados[playerid][DHeadShots]);
  306.     cache_get_value_name_int(0, "DHSTomados", Dados[playerid][DHsTomados]);
  307.     cache_get_value_name_int(0, "DKills", Dados[playerid][DKills]);
  308.     mysql_query(ConexaoBDD, Query, false);
  309.     return 1;
  310. }
  311.  
  312. stock AtualizarRanking()
  313. {
  314.     for(new i = 0; i < MAX_PLAYERS; i++)
  315.     {
  316.         format(Query, sizeof(Query), "UPDATE `Ranking` SET `Nick`='%s',`DHeadShots`=%d,`DHSTomados`=%d, `DKills`=%d WHERE `ID`=%d", Nome(i), Dados[i][DHeadShots], Dados[i][DHsTomados], Dados[i][DKills], Dados[i][mID]);
  317.         mysql_query(ConexaoBDD, Query, false);
  318.     }
  319.     return 1;
  320. }
  321.  
  322. stock Nome(playerid)
  323. {
  324.     new pNome[MAX_PLAYER_NAME];
  325.     GetPlayerName(playerid, pNome, 24);
  326.     return pNome;
  327. }
  328.  
  329. stock Weapon(playerid)
  330. {
  331.     new ArmaName[15];
  332.     GetWeaponName(GetPlayerWeapon(playerid), ArmaName, 15);
  333.     return ArmaName;
  334. }
  335.  
  336. stock GetPlayerConnect(const pName[])
  337. {
  338.     static gpName[MAX_PLAYER_NAME];
  339.     for(new i, j = GetPlayerPoolSize(); i <= j; i++)
  340.     {
  341.         GetPlayerName(i, gpName, sizeof(gpName));
  342.         if(strcmp(pName, gpName, false) == 0)
  343.         return i;
  344.     }
  345.     return INVALID_PLAYER_ID;
  346. }
  347.  
  348. stock GetDistanciaEntrePlayers(playerid, playerid2)
  349. {
  350.     new Float: Pos1[3], Float: Pos2[3], Float: distancia;
  351.     GetPlayerPos(playerid, Pos1[0], Pos1[1], Pos1[2]);
  352.     GetPlayerPos(playerid2,Pos2[0], Pos2[1], Pos2[2]);
  353.     distancia = floatsqroot(floatpower(floatabs(floatsub(Pos2[0], Pos1[0])),2)+floatpower(floatabs(floatsub(Pos2[1], Pos1[1])),2)+floatpower(floatabs(floatsub(Pos2[2], Pos1[2])),2));
  354.     return floatround(distancia);
  355. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement