· 8 years ago · Jan 22, 2018, 03:42 PM
1//=============Defines===================//
2#define FILTERSCRIPT
3#if defined FILTERSCRIPT
4
5#define Dialog_Top10 1
6#define Dialog_NA 2
7#define Dialog_Register 3
8#define Dialog_Login 4
9
10#define Host "localhost"
11#define Username "root"
12#define Pass ""
13#define Database "HeadShot"
14//============Includes==================//
15#include a_samp
16#include a_mysql
17#include izcmd
18
19enum Info
20{
21 HeadShotsW,
22 HeadShotsL,
23 Kills,
24 mID
25}
26new PlayerData[MAX_PLAYERS][Info];
27new MySQL:ConexaoBDD, Query[300];
28new Text:TDEditor_TD[6];
29
30public OnFilterScriptInit()
31{
32 print("--------------------------------------");
33 print("HeadShots System Uploaded by: DelK");
34 print("--------------------------------------");
35
36 ConexaoBDD = mysql_connect(Host, Username, Pass, Database);
37 if(mysql_errno(ConexaoBDD) != 0) printf("Failed to connect to MySQL database [error %d]", mysql_errno(ConexaoBDD));
38 else print("Connection to the MySQL database successfully established");
39 mysql_query(ConexaoBDD, "CREATE TABLE IF NOT EXISTS Ranking(ID int AUTO_INCREMENT PRIMARY KEY, Nick varchar(24) NOT NULL, HeadShotsW int NOT NULL, HeadShotsL int NOT NULL, Kills 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, "information_of_his_death");
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, "Weapon:_%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, "Damage:_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, "Distance:_%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, "You_Ittook_one_headshot_in:_%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 OnPlayerConnect(playerid)
115{
116 new row;
117 mysql_format(ConexaoBDD, Query, sizeof(Query), "SELECT * FROM `Ranking` WHERE `Nick`='%s'", Name(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 - Do not use", "logging in", "Log Into", "Exit");
123 }
124 else
125 {
126 ShowPlayerDialog(playerid, Dialog_Register, DIALOG_STYLE_MSGBOX, "Base - Do not use", "Recording", "Register", "Exit");
127 }
128 return 1;
129}
130
131public OnPlayerDisconnect(playerid, reason)
132{
133 UpdateRanking();
134 return 1;
135}
136
137public OnPlayerDeath(playerid, killerid, reason)
138{
139 SendDeathMessage(killerid, playerid, reason);
140 if(killerid != INVALID_PLAYER_ID)
141 {
142 PlayerData[killerid][Kills]++;
143 }
144 SetTimerEx("Death", 1500, false, "i", playerid);
145 return 1;
146}
147
148forward Death(playerid);
149public Death(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
156public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid, bodypart)
157{
158 if(issuerid != INVALID_PLAYER_ID && bodypart == 9)
159 {
160 new string[55], Float: Distance;
161 Distance = DistanceBetweenTwoPlayers(issuerid, playerid);
162 SetPlayerHealth(playerid, 0);
163 format(string, sizeof(string), "Weapon:_%s", Weapon(issuerid));
164 TextDrawSetString(TDEditor_TD[2], string);
165 format(string, sizeof(string), "Distance:_%.1f Meters", Distance);
166 TextDrawSetString(TDEditor_TD[4], string);
167 format(string, sizeof(string), "You_Ittook_one_headshot_in:_%s", Name(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 PlayerData[issuerid][HeadShotsW]++;
173 PlayerData[playerid][HeadShotsL]++;
174 }
175 UpdateRanking();
176 }
177 return 1;
178}
179
180public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
181{
182 if(dialogid == Dialog_Register)
183 {
184 if(!response) return Kick(playerid);
185 if(response)
186 {
187 format(Query, sizeof(Query), "INSERT INTO `Ranking` (Nick, HeadShotsW, HeadShotsL, Kills) VALUES ('%s', '0', '0','0')", Name(playerid));
188 mysql_query(ConexaoBDD, Query, true);
189 PlayerData[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 ToChargeRanking(playerid);
200 SendClientMessage(playerid, -1, "Successfully logged in!");
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`, `HeadShotsW` FROM `Ranking` WHERE `HeadShotsW`>'0' ORDER BY HeadShotsW DESC LIMIT 10;");
213 mysql_tquery(ConexaoBDD, QueryHeadShot, "TopHeadShotsW", "i", playerid);
214 }
215 if(listitem == 1)
216 {
217 format(QueryHeadShot, sizeof(QueryHeadShot), "SELECT `Nick`, `HeadShotsL` FROM `Ranking` WHERE `HeadShotsL`>'0' ORDER BY HeadShotsL DESC LIMIT 10;");
218 mysql_tquery(ConexaoBDD, QueryHeadShot, "TopHeadShotsL", "i", playerid);
219 }
220 if(listitem == 2)
221 {
222 format(QueryHeadShot, sizeof(QueryHeadShot), "SELECT `Nick`, `Kills` FROM `Ranking` WHERE `Kills`>'0' ORDER BY Kills 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!", "HeadShotsW\nHeadShotsL\nKills", "Confirm", "Cancel");
230 }
231 return 1;
232}
233
234CMD: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
245CMD:top10(playerid)
246{
247 UpdateRanking();
248 ShowPlayerDialog(playerid, Dialog_Top10, DIALOG_STYLE_LIST, "#Ranking MySQL!", "HeadShotsW\nHeadShotsL\nKills", "Confirm", "Cancel");
249 return 1;
250}
251
252forward TopHeadShotsW(playerid);
253public TopHeadShotsW(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, "HeadShotsW", HSs);
260 format(string, sizeof(string),"%sNª %d° - %s | HeadShotsW: %d | %s\n\n{FFFFFF}", string, i+1, Nick, HSs, (GetPlayerConnect(Nick) == INVALID_PLAYER_ID ? ("{8B0000}Disconnected"):("{00FF00}Connected")));
261 contagem++;
262 }
263 ShowPlayerDialog(playerid, Dialog_NA, DIALOG_STYLE_MSGBOX, "#Ranking HeadShotsW!", string, "Voltar", "Fechar");
264 if(contagem == 0) return ShowPlayerDialog(playerid, Dialog_NA, DIALOG_STYLE_MSGBOX, "#Ranking HeadShotsW!", "There is no one in the Kills Ranking!\n", "Back", "Close");
265 return 1;
266}
267
268forward TopHeadShotsL(playerid);
269public TopHeadShotsL(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, "HeadShotsL", HSs);
276 format(string, sizeof(string),"%sNª %d° - %s | HeadShotsL: %d | %s\n\n{FFFFFF}", string, i+1, Nick, HSs, (GetPlayerConnect(Nick) == INVALID_PLAYER_ID ? ("{8B0000}Disconnected"):("{00FF00}Connected")));
277 contagem++;
278 }
279 ShowPlayerDialog(playerid, Dialog_NA, DIALOG_STYLE_MSGBOX, "#Ranking HeadShotsL!", string, "Back", "Close");
280 if(contagem == 0) return ShowPlayerDialog(playerid, Dialog_NA, DIALOG_STYLE_MSGBOX, "#Ranking HeadShotsL!", "There is no one in the Kills Ranking!\n", "Back", "Close");
281 return 1;
282}
283
284forward TopKills(playerid);
285public 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 | Kills: %d | %s\n\n{FFFFFF}", string, i+1, Nick, HSs, (GetPlayerConnect(Nick) == INVALID_PLAYER_ID ? ("{8B0000}Disconnected"):("{00FF00}Connected")));
293 contagem++;
294 }
295 ShowPlayerDialog(playerid, Dialog_NA, DIALOG_STYLE_MSGBOX, "#Ranking Kills!", string, "Back", "Close");
296 if(contagem == 0) return ShowPlayerDialog(playerid, Dialog_NA, DIALOG_STYLE_MSGBOX, "#Ranking Kills!", "There is no one in the Kills Ranking!\n", "Back", "Close");
297 return 1;
298}
299
300stock ToChargeRanking(playerid)
301{
302 format(Query, sizeof(Query), "SELECT * FROM `Ranking` WHERE `Nick`='%s'", Name(playerid));
303 mysql_query(ConexaoBDD, Query, true);
304 cache_get_value_name_int(0, "ID", PlayerData[playerid][mID]);
305 cache_get_value_name_int(0, "HeadShotsW", PlayerData[playerid][HeadShotsW]);
306 cache_get_value_name_int(0, "HeadShotsL", PlayerData[playerid][HeadShotsL]);
307 cache_get_value_name_int(0, "Kills", PlayerData[playerid][Kills]);
308 mysql_query(ConexaoBDD, Query, false);
309 return 1;
310}
311
312stock UpdateRanking()
313{
314 for(new i = 0; i < MAX_PLAYERS; i++)
315 {
316 format(Query, sizeof(Query), "UPDATE `Ranking` SET `Nick`='%s',`HeadShotsW`=%d,`HeadShotsL`=%d, `Kills`=%d WHERE `ID`=%d", Name(i), PlayerData[i][HeadShotsW], PlayerData[i][HeadShotsL], PlayerData[i][Kills], PlayerData[i][mID]);
317 mysql_query(ConexaoBDD, Query, false);
318 }
319 return 1;
320}
321
322stock Name(playerid)
323{
324 new pName[MAX_PLAYER_NAME];
325 GetPlayerName(playerid, pName, 24);
326 return pName;
327}
328
329stock Weapon(playerid)
330{
331 new ArmaName[15];
332 GetWeaponName(GetPlayerWeapon(playerid), ArmaName, 15);
333 return ArmaName;
334}
335
336stock 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
348stock DistanceBetweenTwoPlayers(playerid, playerid2)
349{
350 new Float: Pos1[3], Float: Pos2[3], Float: distance;
351 GetPlayerPos(playerid, Pos1[0], Pos1[1], Pos1[2]);
352 GetPlayerPos(playerid2,Pos2[0], Pos2[1], Pos2[2]);
353 distance = 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(distance);
355}