· 10 years ago · Mar 31, 2016, 09:09 PM
1#include <a_samp>
2#include <zcmd>
3#include <streamer>
4#include <sscanf2>
5#include <a_mysql>
6
7main( ) { }
8
9
10#define Cops 1
11#define Indians 2
12#define Corleone 3
13#define Mafia 4
14
15#define DIALOG_LOGIN 1
16#define DIALOG_WELCOME 2
17#define DIALOG_WEAPONS 3
18
19#define WEAP_DIALOG 10
20
21#define IndiansColor 0x800080AA
22#define CopsColor 0x0000BBAA
23#define CorleoneColor 0xFF9900AA
24#define MafiaColor 0xFF0000AA
25
26#define mysql_host "localhost"
27#define mysql_user "root"
28#define mysql_password "password"
29#define mysql_database "ls-tdm"
30
31new IsRegistered[MAX_PLAYERS];
32//We are using this variable so we don't have to query later to
33//check if the player is registered in the database.
34
35new MoneyGiven[MAX_PLAYERS];
36
37new Logged[MAX_PLAYERS]; //The variable to check if the player is logged.
38
39
40stock GetName(playerid)
41{
42 new pName[24];
43 GetPlayerName(playerid, (pName), sizeof(pName));
44 return pName;
45}
46
47new Float:CopsRandomSpawns[][] = {
48 {1554.133666,-1608.230346,13.382812,117.002998},
49 {1572.711425,-1607.012451,13.382812,121.645599},
50 {1589.231567,-1623.851562,13.382812,104.733299},
51 {1599.028198,-1669.861328,5.886267,20.171667}
52};
53
54new Float:IndiansRandomSpawns[][] = {
55 {740.726989,-1335.585571,13.538015,271.709381},
56 {751.906005,-1348.883300,13.508790,235.895050},
57 {760.812622,-1338.046752,13.532607,286.963623},
58 {762.870056,-1356.796997,13.522253,204.060043}
59};
60
61new Float:CorleoneRandomSpawns[][] = {
62 {1188.675415,-2042.791137,69.000610,290.271942},
63 {1176.040405,-2025.707763,69.007812,279.313140},
64 {1158.581787,-2028.848754,69.000610,256.431884},
65 {1156.478027,-2043.563110,69.007812,289.261657}
66};
67
68new Float:MafiaRandomSpawns[][] = {
69 {1234.127075,-1651.634765,11.796875,271.355010},
70 {1228.939208,-1661.328369,11.796875,250.178848},
71 {1236.953979,-1669.668212,11.796875,295.708984},
72 {1249.952026,-1651.675170,12.671875,279.128204}
73};
74
75public OnGameModeInit()
76{
77 mysql_connect(mysql_host, mysql_user, mysql_database, mysql_password);
78 mysql_query("CREATE TABLE IF NOT EXISTS playerdata(user VARCHAR(24), password VARCHAR(41), score INT(20), money INT(20), IP VARCHAR(16) )");
79 //Fields:
80 //Field Name - Use - Type
81 //user- Player Name - String
82 //password- Players password - String
83 //score - Players score - int
84 //money - Players Cash - int
85 //IP - Players IP - int
86
87 SetGameModeText("Team Deathmatch");
88 AddPlayerClass(71, 1553.5217, -1675.1289, 16.1953, 87.6010, 31, 200, 24, 50, 27, 100); //Cops
89 AddPlayerClass(220, 647.9924, -1357.6821, 13.5736, 87.3431, 32, 500, 26, 100, 31, 100); //Indians
90 AddPlayerClass(187, 1125.1790, -2036.4707, 69.8823, 266.1564, 31, 200, 24, 50 ,27 ,100); //Corleone
91 AddPlayerClass(249, 1273.9409, -1652.3606, 13.5469, 270.9812, 32, 500, 26, 100, 31, 100); //Mafia
92
93 CreateVehicle(451, 783.5051, -1342.2067, 13.9757, 90.0000, -1, -1, 100);
94 CreateVehicle(451, 783.6219, -1347.5856, 14.2159, 90.0000, -1, -1, 100);
95 CreateVehicle(451, 783.4503, -1353.1494, 14.2358, 90.0000, -1, -1, 100);
96 CreateVehicle(451, 783.5088, -1358.0281, 14.5762, 90.0000, -1, -1, 100);
97 CreateVehicle(451, 783.8336, -1363.0353, 14.7970, 90.0000, -1, -1, 100);
98 CreateVehicle(451, 783.4510, -1368.2708, 14.3529, 90.0000, -1, -1, 100);
99 CreateVehicle(451, 783.6689, -1373.7399, 14.5264, 90.0000, -1, -1, 100);
100 CreateVehicle(451, 784.0999, -1337.6704, 14.0509, 90.0000, -1, -1, 100);
101 CreateVehicle(596, 1551.9240, -1614.4730, 12.3719, 180.0000, -1, -1, 100);
102 CreateVehicle(596, 1559.0480, -1614.3455, 12.3727, 180.0000, -1, -1, 100);
103 CreateVehicle(596, 1565.9263, -1614.1643, 12.3730, 180.0000, -1, -1, 100);
104 CreateVehicle(596, 1562.2905, -1614.2620, 12.5421, 180.0000, -1, -1, 100);
105 CreateVehicle(596, 1555.2487, -1614.2629, 12.5420, 180.0000, -1, -1, 100);
106 CreateVehicle(596, 1572.3033, -1614.1459, 12.5423, 180.0000, -1, -1, 100);
107 CreateVehicle(596, 1569.0901, -1614.1743, 12.3732, 180.0000, -1, -1, 100);
108 CreateVehicle(487, 1554.7389, -1628.1759, 13.9079, 90.0000, -1, -1, 100);
109 CreateVehicle(447, 1569.9305, -1627.8193, 13.7216, 90.0000, -1, -1, 100);
110 CreateVehicle(487, 1154.0099, -2019.0278, 71.2536, 0.0000, -1, -1, 100);
111 CreateVehicle(447, 1153.5662, -2051.5271, 70.5370, 0.0000, -1, -1, 100);
112 CreateVehicle(494, 1246.4553, -2020.8715, 60.3879, -90.0000, -1, -1, 100);
113 CreateVehicle(494, 1246.3883, -2027.1262, 61.5117, -90.0000, -1, -1, 100);
114 CreateVehicle(494, 1246.3470, -2033.6591, 62.3051, -90.0000, -1, -1, 100);
115 CreateVehicle(494, 1246.3175, -2036.7081, 61.1060, -90.0000, -1, -1, 100);
116 CreateVehicle(494, 1246.3638, -2023.8877, 61.6319, -90.0000, -1, -1, 100);
117 CreateVehicle(494, 1246.3533, -2030.5167, 60.6882, -90.0000, -1, -1, 100);
118 CreateVehicle(494, 1246.3788, -2039.5834, 61.3145, -90.0000, -1, -1, 100);
119 CreateVehicle(494, 1246.4369, -2042.6887, 60.5220, -90.0000, -1, -1, 100);
120 CreateVehicle(506, 1291.6561, -1638.1107, 13.9096, 0.0000, -1, -1, 100);
121 CreateVehicle(506, 1292.5537, -1652.2797, 16.2871, 0.0000, -1, -1, 100);
122 CreateVehicle(506, 1292.2551, -1645.8733, 13.8077, 0.0000, -1, -1, 100);
123 CreateVehicle(506, 1292.1995, -1659.8727, 14.2256, 0.0000, -1, -1, 100);
124 CreateVehicle(506, 1292.1940, -1666.6029, 13.2865, 0.0000, -1, -1, 100);
125 CreateVehicle(506, 1302.5026, -1639.0504, 13.3553, 0.0000, -1, -1, 100);
126 CreateVehicle(506, 1302.8295, -1644.9762, 13.4195, 0.0000, -1, -1, 100);
127 CreateVehicle(506, 1302.7009, -1651.8605, 15.5742, 0.0000, -1, -1, 100);
128 CreateVehicle(506, 1302.6436, -1659.9562, 15.8937, 0.0000, -1, -1, 100);
129 CreateVehicle(506, 1302.5717, -1666.2211, 14.6043, 0.0000, -1, -1, 100);
130 CreateVehicle(487, 1312.6306, -1652.6840, 13.9501, 0.0000, -1, -1, 100);
131 CreateVehicle(447, 1312.1071, -1669.8120, 13.9698, 0.0000, -1, -1, 100);
132 CreateVehicle(487, 767.2487, -1373.1849, 13.8443, 0.0000, -1, -1, 100);
133 CreateVehicle(447, 768.3797, -1337.8193, 18.0970, 0.0000, -1, -1, 100);
134
135 Create3DTextLabel("{0000FF}Cops Spawn", 0x008080FF, 1544.6005, -1621.4094, 14.5437, 0, 0);
136 Create3DTextLabel("{9932CC}Indians Spawn", 0x008080FF, 777.5306, -1386.3491, 14.6852, 0, 0);
137 Create3DTextLabel("{9932CC}Indians Spawn", 0x008080FF, 778.1620, -1329.8835, 14.5440, 0, 0);
138 Create3DTextLabel("{FFCC00}Corleone Spawn", 0x008080FF, 1239.4467, -2037.1244, 60.8900, 0, 0);
139 Create3DTextLabel("{FF0000}Mafia Spawn", 0x008080FF, 1285.9448, -1652.7422, 14.5407, 0, 0);
140
141 GangZoneCreate( 1207.483, -1708.295, 1207.483, -1568.295 ); // MAFIA
142
143 return 1;
144}
145
146public OnGameModeExit()
147{
148 return 1;
149}
150
151public OnPlayerRequestClass(playerid, classid)
152{
153// So, we're gonna simply use a switch instead of if-else if structure
154
155 switch(classid) // Switching between the classids
156 {
157 case 0/* The first classid is of the cops*/:
158 {
159 SetPlayerTeam(playerid, Cops); // Setting players team
160 GameTextForPlayer(playerid, "~b~Cops", 1000, 3); // Screen msg for player to show what team
161 }
162
163 case 1/* The second classid is of the criminals*/:
164 {
165 SetPlayerTeam(playerid, Indians); // Same as above
166 GameTextForPlayer(playerid, "~p~Indians", 1000, 3); //Same as above
167 }
168
169 case 2:
170 {
171 SetPlayerTeam(playerid, Corleone);
172 GameTextForPlayer(playerid, "~y~Corleone", 1000, 3);
173 }
174
175 case 3:
176 {
177 SetPlayerTeam(playerid, Mafia);
178 GameTextForPlayer(playerid, "~r~Mafia", 1000, 3);
179 }
180 }
181 return 1;
182}
183
184public OnPlayerSpawn(playerid)
185{
186
187 if(GetPlayerTeam(playerid) == Cops)
188 {
189 SetPlayerColor(playerid, CopsColor); // Set his color to CopsColor (BLUE)
190 SetPlayerRandomCopsSpawn(playerid); /// NEW LINE! Enabling random spawns
191 /* Any other bonus you want for Cops team! A special gun, skin, color, attachedobject, A random spawn! */
192 }
193
194 else if(GetPlayerTeam(playerid) == Indians)
195 {
196 SetPlayerColor(playerid, IndiansColor); // Same as above but in this case, CriminalsColor (RED)
197 SetPlayerRandomIndiansSpawn(playerid);///// Same as above
198 }
199
200 else if(GetPlayerTeam(playerid) == Corleone)
201 {
202 SetPlayerColor(playerid, CorleoneColor);
203 SetPlayerRandomCorleoneSpawn(playerid);
204 }
205
206 else if(GetPlayerTeam(playerid) == Mafia)
207 {
208 SetPlayerColor(playerid, MafiaColor);
209 SetPlayerRandomMafiaSpawn(playerid);
210 }
211
212 if(MoneyGiven[playerid] != -1)
213 {
214 GivePlayerMoney(playerid, MoneyGiven[playerid]);
215 MoneyGiven[playerid] = -1;
216 }
217 return 1;
218}
219
220public OnPlayerText(playerid,text[])
221{
222 if(text[0] == '@') // @ can be changed to whatever symbol u wanna use for player to enable the teamchat.
223 {
224 new string[128]; GetPlayerName(playerid, string, sizeof(string)); // Making the new's
225 format(string, sizeof(string), "{FFFF00}[Team Radio]{FFFFFF} %s: %s", string, text[1]); // Formatted the message
226 printf("%s", string); // Printed it BOTH ingame + the server log
227
228 for(new i = 0; i < MAX_PLAYERS; i++) // Getting the player team and color, required for formatting the msg.
229 {
230 if(IsPlayerConnected(i) && GetPlayerTeam(i) == GetPlayerTeam(playerid)) SendClientMessage(i, GetPlayerColor(playerid), string);
231 }
232 return 0;
233 }
234
235 return 1;
236}
237
238public OnPlayerRequestSpawn(playerid)
239{
240 if(!Logged[playerid]) //If the player isn't logged in and (s)he tries to spawn.
241 {
242 if(!IsRegistered[playerid]) //If the player isn't registered
243 {
244 ShowPlayerDialog(playerid, 15000, DIALOG_STYLE_INPUT, "Register","This username is {FF0000}not{FFFFFF} registered! Please {FF0000}register{FFFFFF} with a password below!\n {FF0000}ERROR:You must register before spawning!","Register","Cancel"); //Shows our register dialog :).
245 return 0; //Prevents the player from spawning
246 }
247 if(IsRegistered[playerid] == 1) //Our handy variable comes into use now
248 {
249 ShowPlayerDialog(playerid, 15500, DIALOG_STYLE_INPUT, "Login","This username is {FFFF00}registered{FFFFFF}! Please {FFFF00}login{FFFFFF} with your password below!\n{FF0000} You must logged in before you spawn!","Login","Cancel"); //Shows our login dialog :).
250 return 0; //Prevents the player from spawning
251 }
252 }
253 return 1;
254}
255
256public OnPlayerDeath(playerid, killerid, reason)
257{
258 SendDeathMessage(killerid, playerid, reason); // Shows the kill in the killfeed
259
260 // Check that the killerid is valid before doing anything with it
261 if(killerid != INVALID_PLAYER_ID)
262 {
263 GivePlayerMoney(killerid, 500); // change xx to amount of money do you want
264 SetPlayerScore(killerid,GetPlayerScore(killerid)+1); // change xx to score
265
266 new string[256];
267 format(string, sizeof(string), "{FFFF00}[KILL]{FFFFFF} You killed {FFFF00}%s{FFFFFF} and recieved {FFFF00}$500{FFFFFF} and {FFFF00}1{FFFFFF} score.", GetName(playerid));
268 SendClientMessage(killerid,-1,string);
269
270 format(string, sizeof(string), "{FFFF00}[DEATH]{FFFFFF} You were killed by {FFFF00}%s{FFFFFF} and lost {FFFF00}$100.", GetName(killerid));
271 SendClientMessage(playerid,-1,string);
272 }
273
274 return 1;
275}
276
277public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
278{
279 if(dialogid==WEAP_DIALOG)
280 {
281 if(response)
282 {
283 switch(listitem)
284 {
285 case 0:SellWeapon(playerid,1000,4,1);
286 case 1:SellWeapon(playerid,2000,29,500);
287 case 2:SellWeapon(playerid,5000,24,500);
288 case 3:SellWeapon(playerid,10000,27,500);
289 case 4:SellWeapon(playerid,20000,35,10);
290 }
291 }
292
293 if(dialogid == 15000) //If Dialog is our register dialog
294 {
295 if(response) //If they click the button register
296 {
297 if(!strlen(inputtext) || strlen(inputtext) > 100) //Password is not 1 to 100 characters
298 {
299 SendClientMessage(playerid, 0xFF0000, "You must insert a password between 1-100 characters!"); //Sends the client a error message
300 ShowPlayerDialog(playerid, 15000, DIALOG_STYLE_INPUT, "Register","{FFFFFF}This username is {FF0000}not{FFFFFF} registered! Create an {FF0000}account{FFFFFF} with a password below!\n {FF0000}ERROR:Please enter a password between 1-100 characters!","Register","Cancel"); //Shows our register dialog :).
301 }
302 else if(strlen(inputtext) > 0 && strlen(inputtext) < 100)
303 {
304 new escpass[100];
305 mysql_real_escape_string(inputtext, escpass);
306 MySQL_Register(playerid, escpass);
307 }
308 //If the password is between 1 and 100 characters then we will
309 //call our MySQL_register function which will register the player.
310 }
311 if(!response)
312 {
313 SendClientMessage(playerid, 0xFF0000, "You must register before logging in!"); //Sends the client a error message
314 ShowPlayerDialog(playerid, 15000, DIALOG_STYLE_INPUT, "Register","{FFFFFF}This username is {FF0000}not{FFFFFF} registered! Create an {FF0000}account{FFFFFF} with a password below!\n {FF0000}ERROR:Please enter a password !","Register","Cancel"); //Shows our register dialog :).
315 }
316 }
317 if(dialogid == 15500) //Dialog login
318 {
319 if(!response) //If they click the cancel button
320 {
321 SendClientMessage(playerid, 0xFF0000, "You must login before you spawn!"); //Sends the client a error message
322 ShowPlayerDialog(playerid, 15500, DIALOG_STYLE_INPUT, "Login","This username is {FFFF00}registered{FFFFFF}! Please {FFFF00}login{FFFFFF} with your password below!\n{FF0000} You must login before you spawn!","Login","Cancel"); //Shows our login dialog :).
323 }
324 if(response) //If the player clicked login
325 {
326 new query[200], pname[24], escapepass[100]; //
327 GetPlayerName(playerid, pname, 24); //Gets the players name
328 mysql_real_escape_string(inputtext, escapepass); //We escape the inputtext to avoid SQL injections.
329 format(query, sizeof(query), "SELECT `user` FROM playerdata WHERE user = '%s' AND password = SHA1('%s')", pname, escapepass);
330 mysql_query(query);
331 mysql_store_result();
332 new numrows = mysql_num_rows();
333 if(numrows == 1) MySQL_Login(playerid);
334 //This means that there is a user in the database with the same
335 //password that we typed, we now proceed by using the login function.
336 if(!numrows)
337 {
338 //This means that the password that the player
339 //typed was incorrect and we will resend the dialog.
340 ShowPlayerDialog(playerid, 15500, DIALOG_STYLE_INPUT, "Login","This username is {FFFF00}registered{FFFFFF}! Please {FFFF00}login{FFFFFF} with your password below!\n{FF0000} The password you typed was incorrect!","Login","Cancel"); //Shows our login dialog :).
341 SendClientMessage(playerid, 0xFF0000, "Incorrect password!"); //Sends the client a error message
342 }
343 mysql_free_result(); //Remember to always free a result if you stored one!
344 }
345 }
346}
347 return 1;
348}
349
350stock SellWeapon(playerid,money,weapon,ammo)
351{
352 new playermoney = GetPlayerMoney(playerid);
353 if(playermoney>money)
354 {
355 new string[80],weaponname[32];
356 GivePlayerMoney(playerid,-money);
357 GivePlayerWeapon(playerid,weapon,ammo);
358 GetWeaponName(weapon,weaponname,sizeof(weaponname));
359 format(string,sizeof(string),"{FFFF00}[INFO]{FFFFFF} You bought {FFFF00}%i{FFFFFF} ammo of weapon {FFFF00}%s{FFFFFF} for {FFFF00}$%i",ammo,weaponname,money);
360 return SendClientMessage(playerid,-1,string);
361 }
362 else return SendClientMessage(playerid,-1,"{FFFF00}[INFO]{FFFFFF} You don't have to enough money to purchase this weapon.");
363}
364
365public OnPlayerDisconnect(playerid, reason)
366{
367 new pname[MAX_PLAYER_NAME], string[39 + MAX_PLAYER_NAME];
368 GetPlayerName(playerid, pname, sizeof(pname));
369 switch(reason)
370 {
371 case 0: format(string, sizeof(string), "{FFFF00} %s {FFFFFF}has left the server. {FFFF00}(Lost Connection)", pname);
372 case 1: format(string, sizeof(string), "{FFFF00} %s {FFFFFF}has left the server. {FFFF00}(Leaving)", pname);
373 case 2: format(string, sizeof(string), "{FFFF00} %s {FFFFFF}has left the server. {FFFF00}(Kicked)", pname);
374 }
375 SendClientMessageToAll(0xAAAAAAAA, string);
376
377 if(Logged[playerid] == 1)
378 {
379 //If the player disconnects before registering,
380 //we want to make sure it doesn't try update
381 //so we check if the player is logged in.
382 new score = GetPlayerScore(playerid); //Gets players score
383 new money = GetPlayerMoney(playerid); //Gets players money
384 new query[200], pname[24]; //Creates the variables
385 GetPlayerName(playerid, pname, 24); //Gets the players name.
386 format(query, sizeof(query), "UPDATE 'playerdata' SET 'score'=%d, 'money'=%d WHERE 'user'='%s'", score, money, pname);
387 mysql_query(query);*/
388 }
389 return 1;
390}
391
392public OnPlayerConnect(playerid)
393{
394
395 MoneyGiven[playerid] = -1; //Resets the variable that you will discover later in the tutorial.
396 new query[200], pname[24]; //Creates our variables.
397 GetPlayerName(playerid, pname, 24); //Gets the players name
398 format(query, sizeof(query), "SELECT IP FROM `playerdata` WHERE user = '%s' LIMIT 1", pname); //Formats the query, view above the code for a explanation
399 mysql_query(query); //This is our query function to query the string
400 mysql_store_result(); //We store the result.
401 new rows = mysql_num_rows(); //We get how many rows the query returned.
402 if(!rows)
403 {
404 //If the rows are equal to 0. This means that the query did not find
405 //anyone under the name we connected under in the database.
406 //So here we send the player the register dialog.
407 ShowPlayerDialog(playerid, 15000, DIALOG_STYLE_INPUT, "Register","This username is {FF0000}not{FFFFFF} registered! Create an {FF0000}account{FFFFFF} with a password below!","Register","Cancel"); //Shows our register dialog :).
408 }
409 if(rows == 1)
410 {
411 //If the rows are equal to 1, this means there is a player already registered
412 //so we can initiate the login dialog to the player or check if the players
413 //current IP is the same one as in the database.
414 new IP[2][16]; //We create a variable with two IP strings, one for retrieving the mysql field and one for GetPlayerIP.
415 mysql_fetch_field_row(IP[0],"IP");
416 GetPlayerIp(playerid, IP[1], 16);
417 if(strlen(IP[0]) != 0 && !strcmp(IP[0], IP[1], true)) //Checks that the MySQL IP has a value and that they are the same.
418 {
419 MySQL_Login(playerid);
420 }
421 else if(!strlen(IP[0]) || strcmp(IP[0], IP[1], true))
422 {
423 ShowPlayerDialog(playerid, 15500, DIALOG_STYLE_INPUT, "Login","This username is {FFFF00}registered!{FFFFFF} Please {FFFF00}login{FFFFFF} with your password below!","Login","Cancel"); //Shows our login dialog :).
424 IsRegistered[playerid] = 1; //Sets the registered variable to 1 (Shows that the player is registered).
425 }
426 }
427 mysql_free_result();
428 //You must always free the mysql result to avoid
429 //there being massive memory usage.
430
431 new string[956];
432 strcat(string, "{FFFFFF}Welcome to {FFFF00}Los Santos Team Deathmatch\n\n");
433 strcat(string, "{FFFFFF}This server is still in {FFFF00}beta{FFFFFF} version, there might be alot of bugs\n\n");
434 strcat(string, "{FFFF00}Information:\n\n");
435 strcat(string, "{FFFFFF}Do not complain about the server and it's features.\n");
436 strcat(string, "Suggestions are accepted\n");
437 strcat(string, "There are {FFFF00}4{FFFFFF} teams:\n\n");
438 strcat(string, "{0000FF}Cops\n");
439 strcat(string, "{9932CC}Indians\n");
440 strcat(string, "{FFCC00}Corleone\n");
441 strcat(string, "{FF0000}Mafia\n\n");
442 strcat(string, "{FFFF00}Objective:\n\n");
443 strcat(string, "{FFFFFF}Kill the other team players");
444 strcat(string, "{FFFFFF}If you need any help in the near future type {FFFF00}/help\n\n");
445 strcat(string, "{FFFFFF}Server is scripted by {FFFF00}Melktert");
446 ShowPlayerDialog(playerid, 44, DIALOG_STYLE_MSGBOX, "Los Santos Team Deathmatch", string, "Accept", "");
447
448 new pname[MAX_PLAYER_NAME], strtok[22 + MAX_PLAYER_NAME];
449 GetPlayerName(playerid, pname, sizeof(pname));
450 format(string, sizeof(string), "{FFFF00}%s {FFFFFF}has joined the server", pname);
451 SendClientMessageToAll(0xAAAAAAAA, string);
452 return 1;
453}
454
455CMD:help(playerid, params[])
456{
457 SendClientMessage(playerid, 0xFFFFFFF, "{FFFF00}[INFO]{FFFFFF} Objective: Kill the other team's players");
458 SendClientMessage(playerid, 0xFFFFFFF, "{FFFF00}[INFO]{FFFFFF} Type /commands to view the commands.");
459 return 1;
460}
461
462CMD:commands(playerid, params[])
463{
464 ShowPlayerDialog(playerid, DIALOG_WELCOME, DIALOG_STYLE_MSGBOX, "Commands", "{FFFF00}/help -{FFFFFF} Gives objective of the game\n{FFFF00}/weaponshop{FFFFFF} - The purchasing of weapons{FFFFFF}\n\nThere are not a lot of commands at this stadium\n\n{FFFFFF}Use {FFFF00}@{FFFFFF} for team chat.", "Close", "");
465 return 1;
466}
467
468CMD:weaponshop(playerid,params[])
469{
470 ShowPlayerDialog(playerid,WEAP_DIALOG,DIALOG_STYLE_LIST,"Weapon Shop","Knife {FFFF00}($1000)\n{FFFFFF}MP5{FFFF00} ($2000)\n{FFFFFF}Deagle{FFFF00} ($5000)\n{FFFFFF}Combat Shotgun{FFFF00} ($10000)\n{FFFFFF}RPG{FFFF00} ($20000)","Buy","Close");
471 return 1;
472}
473
474/// Outside all callbacks //
475forward SetPlayerRandomCopsSpawn(playerid); // Forwarding the function
476public SetPlayerRandomCopsSpawn(playerid) // Setting it up
477{
478 new rand = random(sizeof(CopsRandomSpawns)); // Making it select random options instead of a definite one
479 SetPlayerPos(playerid, CopsRandomSpawns[rand][0], CopsRandomSpawns[rand][1], CopsRandomSpawns[rand][2]); // [rand] tag means random, [0] = X, [1] = Y, [2] = Z
480 return 1;
481}
482
483/// Rest is same as above, just Cops replaced Criminals
484forward SetPlayerRandomIndiansSpawn(playerid);
485public SetPlayerRandomIndiansSpawn(playerid)
486{
487 new rand = random(sizeof(IndiansRandomSpawns));
488 SetPlayerPos(playerid, IndiansRandomSpawns[rand][0], IndiansRandomSpawns[rand][1], IndiansRandomSpawns[rand][2]);
489 return 1;
490}
491
492forward SetPlayerRandomCorleoneSpawn(playerid);
493public SetPlayerRandomCorleoneSpawn(playerid)
494{
495 new rand = random(sizeof(CorleoneRandomSpawns));
496 SetPlayerPos(playerid, CorleoneRandomSpawns[rand][0], CorleoneRandomSpawns[rand][1], CorleoneRandomSpawns[rand][2]);
497 return 1;
498}
499
500forward SetPlayerRandomMafiaSpawn(playerid);
501public SetPlayerRandomMafiaSpawn(playerid)
502{
503 new rand = random(sizeof(MafiaRandomSpawns));
504 SetPlayerPos(playerid, MafiaRandomSpawns[rand][0], MafiaRandomSpawns[rand][1], MafiaRandomSpawns[rand][2]);
505 return 1;
506}
507
508//NOTE:Passwordstring has already been escaped. If you want to use
509//this in another script, make sure that you escape the passwordstring
510//before you
511stock MySQL_Register(playerid, passwordstring[])
512{
513 new query[200], pname[24], IP[16];
514 GetPlayerName(playerid, pname, 24);
515 GetPlayerIp(playerid, IP, 16);
516 format(query, sizeof(query), "INSERT INTO playerdata (user, password, score, money, IP) VALUES('%s', SHA1('%s'), 0, 0, '%s')", pname, passwordstring, IP);
517 mysql_query(query);
518 //We do not need to store or free a result as it
519 //is not a select statement. We can now send the
520 //client a registration success message and set the
521 //Login variable to 1.
522 SendClientMessage(playerid, -1, "{FFFF00}[INFO]{FFFFFF} You have created a new account!");
523 Logged[playerid] = 1; //Sets the login variable
524 return 1;
525}
526
527stock MySQL_Login(playerid)
528{
529 new query[300], pname[24], savingstring[20];
530 GetPlayerName(playerid, pname, 24);
531 format(query, sizeof(query), "SELECT * FROM playerdata WHERE user = '%s'", pname);
532 //We only select the variables that we want to use.
533 //We don't need things like the password string or the user string.
534 mysql_query(query); //Queries the result
535 mysql_store_result(); //Store a result because it's a SELECT statement.
536 while(mysql_fetch_row_format(query,"|"))
537 {
538 //We use while so that it does a single query, not multiple
539 //Especially when we have more variables. If there is more
540 //Variables, you should just split the line with sscanf. To
541 //Make it easier.
542 mysql_fetch_field_row(savingstring, "score"); SetPlayerScore(playerid, strval(savingstring));
543 mysql_fetch_field_row(savingstring, "money"); MoneyGiven[playerid] = strval(savingstring);
544 //If you are wondering why I'm using savingstring instead
545 //Of a variable like using MoneyGiven right away, it's because
546 //mysql_fetch_field_row requires a string.
547 }
548 mysql_free_result(); //We must always free a stored result
549 SendClientMessage(playerid, -1, "You have been logged in!"); //Sends the client a message.
550 Logged[playerid] = 1; //Sets our logged in variable to one
551 return 1;
552}