Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.33 KB | None | 0 0
  1. #include <a_samp>
  2. #include <zcmd>
  3. #include <foreach>
  4. #include <sscanf>
  5.  
  6. #define MAX_GAMES 500 // infinite, aka 500 as we'll never play this many games
  7.  
  8. // Player Information
  9. enum player_data
  10. {
  11. pLogged,
  12. pReg,
  13. pTeam, // 0 America, 1 Canada
  14. // ^ Temps
  15. pMoney,
  16. pKills,
  17. pDeaths,
  18. pFlagCaps,
  19. pFlagReturns
  20. }
  21. new p_data[MAX_PLAYERS][player_data];
  22.  
  23. // Game Information
  24. enum game_data
  25. {
  26. gStatus, // 0 Stopped, 1 Prep, 2 Started
  27. gRound,
  28. gTimeLeft
  29. }
  30. new g_data[MAX_GAMES][game_data];
  31.  
  32.  
  33. // Team Information (1 - USA) (2 - Canada)
  34. static usa = 1;
  35. static can = 2;
  36.  
  37. enum team_data
  38. {
  39. tName[24],
  40. tFlagScore,
  41. tFlag,
  42. tFlagCarrier, // Equal to the ID of the player who has the flag
  43. tFlagState // 0 At base, 1 taken
  44. }
  45. new t_data[3][team_data];
  46.  
  47. // Team Vars
  48. new usa_guns[5][] = {2, 3, 4, 5, 6};
  49. new can_guns[5][] = {7, 10, 4, 5, 15};
  50.  
  51. new usa_skins[5][] = {207, 135, 241, 182, 36};
  52. new can_skins[5][] = {138, 146, 251, 154, 140};
  53.  
  54. #define FLAG 2993
  55. // Dialog Information
  56. #define REG_DIA 1
  57. #define LOG_DIA 2
  58. #define TEAM_SELECT_DIA 3
  59.  
  60. //SQL Information
  61. new DB:ctfDB;
  62.  
  63. main() print("Script Started");
  64.  
  65. public OnGameModeInit()
  66. {
  67. ctfDB = db_open("ctf.db");
  68. SetGameModeText("CTF:Pro");
  69.  
  70. AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
  71.  
  72.  
  73. TeamSetup();
  74. return 1;
  75. }
  76.  
  77. public OnGameModeExit()
  78. {
  79. return 1;
  80. }
  81.  
  82. public OnPlayerConnect(playerid)
  83. {
  84. if(existingUser(playerid) == 1) ShowPlayerDialog(playerid,LOG_DIA,DIALOG_STYLE_INPUT,"Login","Enter your password below:","Login","Quit");
  85. else ShowPlayerDialog(playerid,REG_DIA,DIALOG_STYLE_INPUT,"Register","Enter your password below:","Register","Quit");
  86. return 1;
  87. }
  88.  
  89. public OnPlayerRequestSpawn(playerid)
  90. {
  91. if(p_data[playerid][pLogged] != 1) return 0;
  92. if(p_data[playerid][pTeam] == 0) return ShowPlayerDialog(playerid, TEAM_SELECT_DIA, DIALOG_STYLE_LIST, "Team Select", "United States of America\nCanada", "Select", "Quit");
  93. return 1;
  94. }
  95.  
  96. public OnPlayerSpawn(playerid)
  97. {
  98. if(p_data[playerid][pTeam] == can)
  99. {
  100. PlayerTeamSetup(playerid, can , 1928.8804,1273.2756,10.6719);
  101. }
  102. if(p_data[playerid][pTeam] == usa)
  103. {
  104. PlayerTeamSetup(playerid, usa , 2039.3749,1273.2112,10.6797);
  105. }
  106. return 1;
  107. }
  108.  
  109. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  110. {
  111. switch(dialogid)
  112. {
  113. case REG_DIA:
  114. {
  115. if(!response) return Kick(playerid);
  116. else
  117. {
  118. new tmp[150], DBResult:result;
  119. format(tmp, sizeof(tmp), "INSERT INTO accounts (username, password) VALUES ('%s', '%s')", name(playerid), DB_Escape(inputtext));
  120. result = db_query(ctfDB, tmp);
  121. db_free_result(result);
  122. SendClientMessage(playerid, -1, "Account registered!");
  123. ShowPlayerDialog(playerid, TEAM_SELECT_DIA, DIALOG_STYLE_LIST, "Team Select", "United States of America\nCanada", "Select", "Quit");
  124. }
  125. }
  126. case LOG_DIA:
  127. {
  128. if(!response) return Kick(playerid);
  129. else
  130. {
  131. new tmp[150], DBResult:result;
  132. format(tmp, sizeof(tmp), "SELECT * FROM accounts WHERE username = '%s' AND password = '%s'", name(playerid), inputtext);
  133. result = db_query(ctfDB, tmp);
  134. if(db_num_rows(result) > 0)
  135. {
  136. SendClientMessage(playerid, -1, "Login Success!");
  137. p_data[playerid][pLogged] = 1;
  138. }
  139. else
  140. {
  141. SendClientMessage(playerid, -1, "Login failure! [ Kicked ]");
  142. Kick(playerid);
  143. }
  144. db_free_result(result);
  145. ShowPlayerDialog(playerid, TEAM_SELECT_DIA, DIALOG_STYLE_LIST, "Team Select", "United States of America\nCanada", "Select", "Quit");
  146. }
  147. }
  148. case TEAM_SELECT_DIA:
  149. {
  150. if(!response) return Kick(playerid);
  151. else
  152. {
  153. switch(listitem)
  154. {
  155. case 0:
  156. {
  157. SendClientMessage(playerid, -1, "You've chosen USA!");
  158. p_data[playerid][pTeam] = usa;
  159. PlayerTeamSetup(playerid, usa , 2039.3749,1273.2112,10.6797);
  160. SpawnPlayer(playerid);
  161. }
  162. case 1:
  163. {
  164. SendClientMessage(playerid, -1, "You've chosen Canada!");
  165. p_data[playerid][pTeam] = can;
  166. PlayerTeamSetup(playerid, can , 1928.8804,1273.2756,10.6719);
  167. SpawnPlayer(playerid);
  168. }
  169. }
  170. }
  171. }
  172. }
  173. return 1;
  174. }
  175.  
  176. public OnPlayerPickUpPickup(playerid, pickupid)
  177. {
  178. new tmp[128];
  179. if(pickupid == t_data[usa][tFlag]) // USA
  180. {
  181. if(p_data[playerid][pTeam] == usa && t_data[usa][tFlagState] == 0) return SendClientMessage(playerid, -1, "You can't steal your team flag!");
  182. if(p_data[playerid][pTeam] == usa && t_data[usa][tFlagState] == 1)
  183. {
  184. format(tmp, sizeof(tmp), "%s has returned his team flag!", name(playerid));
  185. GameTextForAll(tmp, 3000, 6);
  186. DestroyPickup(t_data[usa][tFlag]);
  187. t_data[usa][tFlag] = CreatePickup(FLAG, 23, 2034.6960,1273.2317,10.6719, 0);
  188. t_data[usa][tFlagState] = 0;
  189. }
  190. if(p_data[playerid][pTeam] == can && t_data[usa][tFlagState] == 0)
  191. {
  192. format(tmp, sizeof(tmp), "~r~%s ~g~has stolen team %s's flag!", name(playerid), t_data[usa][tName]);
  193. GameTextForAll(tmp, 3000, 6);
  194. t_data[usa][tFlagCarrier] = playerid;
  195. t_data[usa][tFlagState] = 1;
  196. DestroyPickup(t_data[usa][tFlag]);
  197. }
  198. }
  199. if(pickupid == t_data[can][tFlag]) // CANADA
  200. {
  201. if(p_data[playerid][pTeam] == can && t_data[can][tFlagState] == 0) return SendClientMessage(playerid, -1, "You can't steal your team flag!");
  202. if(p_data[playerid][pTeam] == can && t_data[can][tFlagState] == 1)
  203. {
  204. format(tmp, sizeof(tmp), "%s has returned his team flag!", name(playerid));
  205. GameTextForAll(tmp, 3000, 6);
  206. DestroyPickup(t_data[can][tFlag]);
  207. t_data[can][tFlag] = CreatePickup(FLAG, 23, 1934.6691,1273.2633,10.6719, 0);
  208. t_data[can][tFlagState] = 0;
  209.  
  210. }
  211. if(p_data[playerid][pTeam] == usa && t_data[can][tFlagState] == 0)
  212. {
  213. format(tmp, sizeof(tmp), "~r~%s ~g~has stolen team %s's flag!", name(playerid), t_data[can][tName]);
  214. GameTextForAll(tmp, 3000, 6);
  215. t_data[can][tFlagCarrier] = playerid;
  216. t_data[can][tFlagState] = 1;
  217. DestroyPickup(t_data[can][tFlag]);
  218. }
  219. }
  220. return 1;
  221. }
  222.  
  223. public OnPlayerDeath(playerid, killerid, reason)
  224. {
  225. new Float:x, Float:y, Float:z;
  226. GetPlayerPos(playerid, x, y, z);
  227. for(new team = 0; team < 3; team++)
  228. {
  229. if(t_data[team][tFlagCarrier] == playerid)
  230. {
  231. t_data[team][tFlag] = CreatePickup(FLAG, 23, x, y, z, 0);
  232. t_data[team][tFlagState] = 1;
  233. t_data[team][tFlagCarrier] = -1;
  234. }
  235. }
  236.  
  237. return 1;
  238. }
  239.  
  240. stock TeamSetup()
  241. {
  242. format(t_data[usa][tName], 24, "USA");
  243. t_data[usa][tFlag] = CreatePickup(FLAG, 23, 2034.6960,1273.2317,10.6719, 0);
  244. t_data[usa][tFlagState] = 0;
  245. t_data[usa][tFlagCarrier] = -1;
  246. t_data[usa][tFlagScore] = 0;
  247.  
  248. format(t_data[can][tName], 24, "Canada");
  249. t_data[can][tFlag] = CreatePickup(FLAG, 23, 1934.6691,1273.2633,10.6719, 0);
  250. t_data[can][tFlagState] = 0;
  251. t_data[can][tFlagCarrier] = -1;
  252. t_data[can][tFlagScore] = 0;
  253. }
  254.  
  255. stock existingUser(playerid) //Returns 1 if the user exists
  256. {
  257. new tmp[150], DBResult:result;
  258. format(tmp, sizeof(tmp), "SELECT * FROM accounts WHERE username = '%s'", name(playerid));
  259. result = db_query(ctfDB, tmp);
  260. if(db_num_rows(result) > 0)
  261. {
  262. db_free_result(result);
  263. return 1;
  264. }
  265. else
  266. {
  267. db_free_result(result);
  268. return 0;
  269. }
  270. }
  271.  
  272. stock name(playerid)
  273. {
  274. new temp[MAX_PLAYER_NAME];
  275. GetPlayerName(playerid, temp, sizeof(temp));
  276. return temp;
  277. }
  278.  
  279. stock PlayerTeamSetup(playerid, teamid, Float:x, Float:y, Float:z)
  280. {
  281. new ran = random(5);
  282. p_data[playerid][pTeam] = teamid;
  283. SetPlayerPos(playerid, x, y, z);
  284. if(teamid == usa) // Usa
  285. {
  286. GivePlayerWeapon(playerid, usa_guns[ran][0], 1);
  287. SetPlayerSkin(playerid, usa_skins[ran][0]);
  288. }
  289. if(teamid == can) // Canada
  290. {
  291. GivePlayerWeapon(playerid, can_guns[ran][0], 1);
  292. SetPlayerSkin(playerid, can_skins[ran][0]);
  293. }
  294. printf("[DEBUG] ran number: %d", ran);
  295. }
  296.  
  297. //DB Escape function (Y_LESS)
  298. #define MAX_INI_ENTRY_TEXT 80
  299.  
  300. stock DB_Escape(text[])
  301. {
  302. new
  303. ret[MAX_INI_ENTRY_TEXT * 2],
  304. ch,
  305. i,
  306. j;
  307. while ((ch = text[i++]) && j < sizeof (ret))
  308. {
  309. if (ch == '\'')
  310. {
  311. if (j < sizeof (ret) - 2)
  312. {
  313. ret[j++] = '\'';
  314. ret[j++] = '\'';
  315. }
  316. }
  317. else if (j < sizeof (ret))
  318. {
  319. ret[j++] = ch;
  320. }
  321. else
  322. {
  323. j++;
  324. }
  325. }
  326. ret[sizeof (ret) - 1] = '\0';
  327. return ret;
  328. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement