· 8 years ago · Jan 02, 2018, 03:32 PM
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
19enum Info
20{
21 DHeadShots,
22 DHsTomados,
23 DKills,
24 mID
25}
26new Dados[MAX_PLAYERS][Info];
27new MySQL:ConexaoBDD, Query[300];
28new Text:TDEditor_TD[6];
29
30public 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
108public OnFilterScriptExit()
109{
110 mysql_close(ConexaoBDD);
111 return 1;
112}
113
114public OnPlayerRequestClass(playerid, classid)
115{
116 SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
117 SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
118 SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
119 return 1;
120}
121
122public OnPlayerConnect(playerid)
123{
124 new row;
125 mysql_format(ConexaoBDD, Query, sizeof(Query), "SELECT * FROM `Ranking` WHERE `Nick`='%s'", Nome(playerid));
126 mysql_query(ConexaoBDD, Query, true);
127 cache_get_row_count(row);
128 if(row > 0)
129 {
130 ShowPlayerDialog(playerid, Dialog_Login, DIALOG_STYLE_MSGBOX, "Base - Não use", "Logando", "Logar", "Sair");
131 }
132 else
133 {
134 ShowPlayerDialog(playerid, Dialog_Registro, DIALOG_STYLE_MSGBOX, "Base - Não use", "Registrando", "Registrar", "Sair");
135 }
136 return 1;
137}
138
139public OnPlayerDisconnect(playerid, reason)
140{
141 AtualizarRanking();
142 return 1;
143}
144
145public OnPlayerDeath(playerid, killerid, reason)
146{
147 SendDeathMessage(killerid, playerid, reason);
148 if(killerid != INVALID_PLAYER_ID)
149 {
150 Dados[killerid][DKills]++;
151 }
152 SetTimerEx("Morto", 1500, false, "i", playerid);
153 return 1;
154}
155
156forward Morto(playerid);
157public Morto(playerid)
158{
159 SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
160 for(new i = 0; i < 7; i++) TextDrawHideForPlayer(playerid, TDEditor_TD[i]);
161 return 1;
162}
163
164public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid, bodypart)
165{
166 if(issuerid != INVALID_PLAYER_ID && bodypart == 9)
167 {
168 new string[55], Float: Distancia;
169 Distancia = GetDistanciaEntrePlayers(issuerid, playerid);
170 SetPlayerHealth(playerid, 0);
171 format(string, sizeof(string), "Arma:_%s", Weapon(issuerid));
172 TextDrawSetString(TDEditor_TD[2], string);
173 format(string, sizeof(string), "Distancia:_%.1f Metros", Distancia);
174 TextDrawSetString(TDEditor_TD[4], string);
175 format(string, sizeof(string), "Voce_levou_um_headshot_de:_%s", Nome(issuerid));
176 TextDrawSetString(TDEditor_TD[5], string);
177 for(new i = 0; i < 6; i++) TextDrawShowForPlayer(playerid, TDEditor_TD[i]);
178 if(issuerid != INVALID_PLAYER_ID)
179 {
180 Dados[issuerid][DHeadShots]++;
181 Dados[playerid][DHsTomados]++;
182 }
183 AtualizarRanking();
184 }
185 return 1;
186}
187
188public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
189{
190 if(dialogid == Dialog_Registro)
191 {
192 if(!response) return Kick(playerid);
193 if(response)
194 {
195 format(Query, sizeof(Query), "INSERT INTO `Ranking` (Nick, DHeadShots, DHSTomados, DKills) VALUES ('%s', '0', '0','0')", Nome(playerid));
196 mysql_query(ConexaoBDD, Query, true);
197 Dados[playerid][mID] = cache_insert_id();
198 return 1;
199 }
200 return 1;
201 }
202 if(dialogid == Dialog_Login)
203 {
204 if(!response) return Kick(playerid);
205 if(response)
206 {
207 CarregarRanking(playerid);
208 SendClientMessage(playerid, -1, "Logado com sucesso!");
209 return 1;
210 }
211 return 1;
212 }
213 if(dialogid == Dialog_Top10)
214 {
215 new QueryHeadShot[100];
216 if(response)
217 {
218 if(listitem == 0)
219 {
220 format(QueryHeadShot, sizeof(QueryHeadShot), "SELECT `Nick`, `DHeadShots` FROM `Ranking` WHERE `DHeadShots`>'0' ORDER BY DHeadShots DESC LIMIT 10;");
221 mysql_tquery(ConexaoBDD, QueryHeadShot, "TopHSs", "i", playerid);
222 }
223 if(listitem == 1)
224 {
225 format(QueryHeadShot, sizeof(QueryHeadShot), "SELECT `Nick`, `DHSTomados` FROM `Ranking` WHERE `DHSTomados`>'0' ORDER BY DHSTomados DESC LIMIT 10;");
226 mysql_tquery(ConexaoBDD, QueryHeadShot, "TopHSTomados", "i", playerid);
227 }
228 if(listitem == 2)
229 {
230 format(QueryHeadShot, sizeof(QueryHeadShot), "SELECT `Nick`, `DKills` FROM `Ranking` WHERE `DKills`>'0' ORDER BY DKills DESC LIMIT 10;");
231 mysql_tquery(ConexaoBDD, QueryHeadShot, "TopKills", "i", playerid);
232 }
233 }
234 }
235 switch(dialogid)
236 {
237 case Dialog_NA: if(response) return ShowPlayerDialog(playerid, Dialog_Top10, DIALOG_STYLE_LIST, "#Ranking MySQL!", "DHeadShots\nDHsTomados\nDKills", "Confirmar", "Cancelar");
238 }
239 return 1;
240}
241
242CMD:armas(playerid)
243{
244 GivePlayerWeapon(playerid, 24, 999);
245 GivePlayerWeapon(playerid, 25, 999);
246 GivePlayerWeapon(playerid, 29, 999);
247 GivePlayerWeapon(playerid, 31, 999);
248 GivePlayerWeapon(playerid, 32, 999);
249 GivePlayerWeapon(playerid, 34, 999);
250 return 1;
251}
252
253CMD:top10(playerid)
254{
255 AtualizarRanking();
256 ShowPlayerDialog(playerid, Dialog_Top10, DIALOG_STYLE_LIST, "#Ranking MySQL!", "DHeadShots\nDHSTomados\nDKills", "Confirmar", "Cancelar");
257 return 1;
258}
259
260forward TopHSs(playerid);
261public TopHSs(playerid)
262{
263 new string[200], Nick[70], HSs, contagem = 0;
264 for(new i, r = cache_num_rows(); i < r; ++i)
265 {
266 cache_get_value_name(i, "Nick", Nick);
267 cache_get_value_name_int(i, "DHeadShots", HSs);
268 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")));
269 contagem++;
270 }
271 ShowPlayerDialog(playerid, Dialog_NA, DIALOG_STYLE_MSGBOX, "#Ranking HeadShots!", string, "Voltar", "Fechar");
272 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");
273 return 1;
274}
275
276forward TopHSTomados(playerid);
277public TopHSTomados(playerid)
278{
279 new string[200], Nick[70], HSs, contagem = 0;
280 for(new i, r = cache_num_rows(); i < r; ++i)
281 {
282 cache_get_value_name(i, "Nick", Nick);
283 cache_get_value_name_int(i, "DHSTomados", HSs);
284 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")));
285 contagem++;
286 }
287 ShowPlayerDialog(playerid, Dialog_NA, DIALOG_STYLE_MSGBOX, "#Ranking DHSTomados!", string, "Voltar", "Fechar");
288 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");
289 return 1;
290}
291
292forward TopKills(playerid);
293public TopKills(playerid)
294{
295 new string[200], Nick[70], HSs, contagem = 0;
296 for(new i, r = cache_num_rows(); i < r; ++i)
297 {
298 cache_get_value_name(i, "Nick", Nick);
299 cache_get_value_name_int(i, "DKills", HSs);
300 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")));
301 contagem++;
302 }
303 ShowPlayerDialog(playerid, Dialog_NA, DIALOG_STYLE_MSGBOX, "#Ranking DKills!", string, "Voltar", "Fechar");
304 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");
305 return 1;
306}
307
308stock CarregarRanking(playerid)
309{
310 format(Query, sizeof(Query), "SELECT * FROM `Ranking` WHERE `Nick`='%s'", Nome(playerid));
311 mysql_query(ConexaoBDD, Query, true);
312 cache_get_value_name_int(0, "ID", Dados[playerid][mID]);
313 cache_get_value_name_int(0, "DHeadShots", Dados[playerid][DHeadShots]);
314 cache_get_value_name_int(0, "DHSTomados", Dados[playerid][DHsTomados]);
315 cache_get_value_name_int(0, "DKills", Dados[playerid][DKills]);
316 mysql_query(ConexaoBDD, Query, false);
317 return 1;
318}
319
320stock AtualizarRanking()
321{
322 for(new i = 0; i < MAX_PLAYERS; i++)
323 {
324 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]);
325 mysql_query(ConexaoBDD, Query, false);
326 }
327 return 1;
328}
329
330stock Nome(playerid)
331{
332 new pNome[MAX_PLAYER_NAME];
333 GetPlayerName(playerid, pNome, 24);
334 return pNome;
335}
336
337stock Weapon(playerid)
338{
339 new ArmaName[15];
340 GetWeaponName(GetPlayerWeapon(playerid), ArmaName, 15);
341 return ArmaName;
342}
343
344stock GetPlayerConnect(const pName[])
345{
346 static gpName[MAX_PLAYER_NAME];
347 for(new i, j = GetPlayerPoolSize(); i <= j; i++)
348 {
349 GetPlayerName(i, gpName, sizeof(gpName));
350 if(strcmp(pName, gpName, false) == 0)
351 return i;
352 }
353 return INVALID_PLAYER_ID;
354}
355
356stock GetDistanciaEntrePlayers(playerid, playerid2)
357{
358 new Float: Pos1[3], Float: Pos2[3], Float: distancia;
359 GetPlayerPos(playerid, Pos1[0], Pos1[1], Pos1[2]);
360 GetPlayerPos(playerid2,Pos2[0], Pos2[1], Pos2[2]);
361 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));
362 return floatround(distancia);
363}