Advertisement
DiazSRB

Ship Wars

Jan 11th, 2021
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.81 KB | None | 0 0
  1. //Ship wars
  2.  
  3. #define FILTERSCRIPT
  4. #include <a_samp>
  5. #include <streamer>
  6. #include <zcmd>
  7.  
  8. #define EVENT_WORLD 4 // VW
  9. #define EVENT_AMMO 5000 // AMMO
  10. #define EVENT_ICONID 42 // MAPICON
  11. #define EVENT_LIMIT 100 // MAX PLAYERS
  12. #define EVENT_DISTANCE 850.0
  13. #define DEFAULT_SPEED 7.0
  14.  
  15. #define WINNER_MONEY 25000 // WINNER MONEY
  16.  
  17. #define SHIP_COLOR_RED 0xE74C3CFF // color of red team
  18. #define SHIP_COLOR_BLUE 0x3498DBFF // color of blue team
  19.  
  20. enum e_swteams
  21. {
  22. SHIP_RED,
  23. SHIP_BLUE
  24. }
  25.  
  26. enum e_teaminfo
  27. {
  28. ShipObject,
  29. Float: ShipSpeed,
  30. TeamPoint
  31. }
  32.  
  33. new
  34. PlayersInGame,
  35. ShipTimer = -1,
  36. bool: GameStarted,
  37. ShipWarsInfo[2][e_teaminfo],
  38. ShipTeam[MAX_PLAYERS] = {-1, ...},
  39. LastFallCheck[MAX_PLAYERS];
  40.  
  41. new
  42. Text: shipText[4],
  43. PlayerText: shipWithTeamColor[MAX_PLAYERS];
  44.  
  45. new
  46. EventWeapons[] = {WEAPON_DEAGLE, WEAPON_SHOTGSPA, WEAPON_M4, WEAPON_RIFLE};
  47.  
  48. stock GivePoints(team, points)
  49. {
  50. new point_string[6];
  51. ShipWarsInfo[team][TeamPoint] += points;
  52. valstr(point_string, ShipWarsInfo[team][TeamPoint]);
  53. TextDrawSetString(shipText[ (team == _:SHIP_RED) ? 2 : 3 ], point_string);
  54.  
  55. if(ShipWarsInfo[team][TeamPoint] % 5 == 0 && ShipWarsInfo[team][ShipSpeed] < 20.0)
  56. {
  57. ShipWarsInfo[team][ShipSpeed] = floatadd(ShipWarsInfo[team][ShipSpeed], 0.75);
  58. if(ShipWarsInfo[team][ShipSpeed] > 20.0) ShipWarsInfo[team][ShipSpeed] = 20.0;
  59. new string[96];
  60. format(string, sizeof(string), "[%s TEAM] Mi dobijamo brzinu, pokusaj ih jos ubiti!", (team == _:SHIP_RED) ? ("Black Pearl Ship") : ("White Pearl Ship"));
  61.  
  62. for(new i; i < GetMaxPlayers(); ++i)
  63. {
  64. if(!IsPlayerConnected(i)) continue;
  65. if(ShipTeam[i] == team) SendClientMessage(i, (team == _:SHIP_RED) ? SHIP_COLOR_RED : SHIP_COLOR_BLUE, string);
  66. }
  67.  
  68. StopDynamicObject(ShipWarsInfo[team][ShipObject]);
  69. MoveDynamicObject(ShipWarsInfo[team][ShipObject], (team == _:SHIP_RED) ? 402.896 : 352.896, floatsub(-2137.920, EVENT_DISTANCE), 17.415, ShipWarsInfo[team][ShipSpeed]);
  70. }
  71.  
  72. return 1;
  73. }
  74.  
  75. stock LeaveGame(playerid, reason = 0)
  76. {
  77. if(reason != 1)
  78. {
  79. RemovePlayerMapIcon(playerid, EVENT_ICONID);
  80. ResetPlayerWeapons(playerid);
  81. SetPlayerTeam(playerid, NO_TEAM);
  82. SetPlayerVirtualWorld(playerid, 0);
  83. SpawnPlayer(playerid);
  84. }
  85.  
  86. ShipTeam[playerid] = -1;
  87. PlayersInGame--;
  88.  
  89. if(PlayersInGame < 2 && reason < 2)
  90. {
  91. if(GameStarted) SendClientMessageToAll(-1, "[SHIP WARS] Event Zavrsen. (nema dovoljno igraca)");
  92. ResetGame();
  93. }
  94.  
  95. for(new i; i < sizeof(shipText); ++i) TextDrawHideForPlayer(playerid, shipText[i]);
  96. PlayerTextDrawHide(playerid, shipWithTeamColor[playerid]);
  97. PlayerTextDrawDestroy(playerid, shipWithTeamColor[playerid]);
  98. return 1;
  99. }
  100.  
  101. stock ResetGame(unload = 0)
  102. {
  103. for(new i; i < GetMaxPlayers(); ++i)
  104. {
  105. if(!IsPlayerConnected(i)) continue;
  106. if(ShipTeam[i] != -1) LeaveGame(i, 2);
  107. }
  108.  
  109. if(!unload)
  110. {
  111. if(ShipTimer != -1)
  112. {
  113. KillTimer(ShipTimer);
  114. ShipTimer = -1;
  115. }
  116.  
  117. GameStarted = false;
  118. PlayersInGame = 0;
  119. StopDynamicObject(ShipWarsInfo[SHIP_RED][ShipObject]);
  120. StopDynamicObject(ShipWarsInfo[SHIP_BLUE][ShipObject]);
  121. SetDynamicObjectPos(ShipWarsInfo[SHIP_RED][ShipObject], 402.896, -2137.920, 17.415);
  122. SetDynamicObjectPos(ShipWarsInfo[SHIP_BLUE][ShipObject], 352.896, -2137.920, 17.415);
  123. ShipWarsInfo[SHIP_RED][ShipSpeed] = DEFAULT_SPEED;
  124. ShipWarsInfo[SHIP_BLUE][ShipSpeed] = DEFAULT_SPEED;
  125. ShipWarsInfo[SHIP_RED][TeamPoint] = 0;
  126. ShipWarsInfo[SHIP_BLUE][TeamPoint] = 0;
  127.  
  128. TextDrawSetString(shipText[2], "0");
  129. TextDrawSetString(shipText[3], "0");
  130. }
  131.  
  132. return 1;
  133. }
  134.  
  135. public OnFilterScriptInit()
  136. {
  137. ShipWarsInfo[SHIP_RED][ShipObject] = CreateDynamicObject(8493, 402.896, -2137.920, 17.415, 0.000, 0.000, 180.000, EVENT_WORLD, 0);
  138. ShipWarsInfo[SHIP_BLUE][ShipObject] = CreateDynamicObject(8493, 352.896, -2137.920, 17.415, 0.000, 0.000, 180.000, EVENT_WORLD, 0);
  139. SetDynamicObjectMaterial(ShipWarsInfo[SHIP_RED][ShipObject], 2, -1, "none", "none", -1618884);
  140. SetDynamicObjectMaterial(ShipWarsInfo[SHIP_RED][ShipObject], 3, -1, "none", "none", -1618884);
  141. SetDynamicObjectMaterial(ShipWarsInfo[SHIP_BLUE][ShipObject], 2, -1, "none", "none", -13330213);
  142. SetDynamicObjectMaterial(ShipWarsInfo[SHIP_BLUE][ShipObject], 3, -1, "none", "none", -13330213);
  143.  
  144. ShipWarsInfo[SHIP_RED][ShipSpeed] = DEFAULT_SPEED;
  145. ShipWarsInfo[SHIP_BLUE][ShipSpeed] = DEFAULT_SPEED;
  146.  
  147. shipText[0] = TextDrawCreate(495.000000, 355.000000, "_");
  148. TextDrawBackgroundColor(shipText[0], 0);
  149. TextDrawFont(shipText[0], 5);
  150. TextDrawLetterSize(shipText[0], 0.500000, 1.000000);
  151. TextDrawColor(shipText[0], -414434049);
  152. TextDrawSetOutline(shipText[0], 0);
  153. TextDrawSetProportional(shipText[0], 1);
  154. TextDrawSetShadow(shipText[0], 1);
  155. TextDrawUseBox(shipText[0], 1);
  156. TextDrawBoxColor(shipText[0], 0);
  157. TextDrawTextSize(shipText[0], 16.000000, 16.000000);
  158. TextDrawSetPreviewModel(shipText[0], 1254);
  159. TextDrawSetPreviewRot(shipText[0], 0.000000, 0.000000, 0.000000, 0.875000);
  160. TextDrawSetSelectable(shipText[0], 0);
  161.  
  162. shipText[1] = TextDrawCreate(495.000000, 375.000000, "_");
  163. TextDrawBackgroundColor(shipText[1], 0);
  164. TextDrawFont(shipText[1], 5);
  165. TextDrawLetterSize(shipText[1], 0.500000, 1.000000);
  166. TextDrawColor(shipText[1], 882433023);
  167. TextDrawSetOutline(shipText[1], 0);
  168. TextDrawSetProportional(shipText[1], 1);
  169. TextDrawSetShadow(shipText[1], 1);
  170. TextDrawUseBox(shipText[1], 1);
  171. TextDrawBoxColor(shipText[1], 0);
  172. TextDrawTextSize(shipText[1], 16.000000, 16.000000);
  173. TextDrawSetPreviewModel(shipText[1], 1254);
  174. TextDrawSetPreviewRot(shipText[1], 0.000000, 0.000000, 0.000000, 0.875000);
  175. TextDrawSetSelectable(shipText[1], 0);
  176.  
  177. shipText[2] = TextDrawCreate(511.000000, 357.000000, "0");
  178. TextDrawBackgroundColor(shipText[2], 255);
  179. TextDrawFont(shipText[2], 1);
  180. TextDrawLetterSize(shipText[2], 0.210000, 1.100000);
  181. TextDrawColor(shipText[2], -414434049);
  182. TextDrawSetOutline(shipText[2], 1);
  183. TextDrawSetProportional(shipText[2], 1);
  184. TextDrawSetSelectable(shipText[2], 0);
  185.  
  186. shipText[3] = TextDrawCreate(511.000000, 377.000000, "0");
  187. TextDrawBackgroundColor(shipText[3], 255);
  188. TextDrawFont(shipText[3], 1);
  189. TextDrawLetterSize(shipText[3], 0.210000, 1.100000);
  190. TextDrawColor(shipText[3], 882433023);
  191. TextDrawSetOutline(shipText[3], 1);
  192. TextDrawSetProportional(shipText[3], 1);
  193. TextDrawSetSelectable(shipText[3], 0);
  194. return 1;
  195. }
  196.  
  197. public OnFilterScriptExit()
  198. {
  199. for(new i; i < sizeof(shipText); ++i)
  200. {
  201. TextDrawHideForAll(shipText[i]);
  202. TextDrawDestroy(shipText[i]);
  203. }
  204.  
  205. ResetGame(1);
  206. return 1;
  207. }
  208.  
  209. public OnPlayerConnect(playerid)
  210. {
  211. ShipTeam[playerid] = -1;
  212. LastFallCheck[playerid] = 0;
  213. return 1;
  214. }
  215.  
  216. public OnPlayerDisconnect(playerid, reason)
  217. {
  218. if(ShipTeam[playerid] != -1) LeaveGame(playerid, 1);
  219. return 1;
  220. }
  221.  
  222. public OnPlayerUpdate(playerid)
  223. {
  224. if(ShipTeam[playerid] != -1 && LastFallCheck[playerid] < tickcount())
  225. {
  226. LastFallCheck[playerid] = tickcount()+500;
  227.  
  228. new Float: temp, Float: z;
  229. GetPlayerPos(playerid, temp, temp, z);
  230. if(z < 3.0)
  231. {
  232. SetPlayerHealth(playerid, -1.0);
  233. GivePoints((ShipTeam[playerid] == _:SHIP_RED) ? SHIP_BLUE : SHIP_RED, 1);
  234. }
  235. }
  236.  
  237. return 1;
  238. }
  239.  
  240. public OnPlayerSpawn(playerid)
  241. {
  242. if(ShipTeam[playerid] != -1)
  243. {
  244. new Float: x, Float: y, Float: z;
  245. GetDynamicObjectPos(ShipWarsInfo[ ShipTeam[playerid] ][ShipObject], x, y, z);
  246. SetPlayerVirtualWorld(playerid, EVENT_WORLD);
  247. SetPlayerPos(playerid, x, y - (-22.22), 9.5);
  248. SetPlayerTeam(playerid, ShipTeam[playerid]);
  249. ResetPlayerWeapons(playerid);
  250. if(GameStarted) for(new i; i < sizeof(EventWeapons); ++i) GivePlayerWeapon(playerid, EventWeapons[i], EVENT_AMMO);
  251. }
  252.  
  253. return 1;
  254. }
  255.  
  256. public OnPlayerDeath(playerid, killerid, reason)
  257. {
  258. if(killerid != INVALID_PLAYER_ID && ShipTeam[playerid] != -1 && ShipTeam[killerid] != -1 && ShipTeam[playerid] != ShipTeam[killerid])
  259. {
  260. new Float: temp, Float: z;
  261. GetPlayerPos(playerid, temp, temp, z);
  262. if(z > 5.0) GivePoints(ShipTeam[killerid], 1);
  263. }
  264.  
  265. return 1;
  266. }
  267.  
  268. public OnDynamicObjectMoved(objectid)
  269. {
  270. new team = -1;
  271. if(objectid == ShipWarsInfo[SHIP_RED][ShipObject]) {
  272. team = SHIP_RED;
  273. }else if(objectid == ShipWarsInfo[SHIP_BLUE][ShipObject]) {
  274. team = SHIP_BLUE;
  275. }else{
  276. team = -1;
  277. }
  278.  
  279. if(team == -1) return 1;
  280. new Float: x, Float: y, Float: z, Float: fin_x = (team == _:SHIP_RED) ? 402.896 : 352.896, Float: fin_y = floatsub(-2137.920, EVENT_DISTANCE);
  281. GetDynamicObjectPos(objectid, x, y, z);
  282. new Float: dist = floatsqroot(floatpower(fin_x-x, 2.0) + floatpower(fin_y-y, 2.0));
  283. if(dist < 10.0)
  284. {
  285. if(ShipWarsInfo[SHIP_RED][ShipSpeed] == ShipWarsInfo[SHIP_BLUE][ShipSpeed])
  286. {
  287. if(ShipWarsInfo[SHIP_RED][TeamPoint] > ShipWarsInfo[SHIP_BLUE][TeamPoint]) {
  288. team = SHIP_RED;
  289. }else if(ShipWarsInfo[SHIP_BLUE][TeamPoint] > ShipWarsInfo[SHIP_RED][TeamPoint]) {
  290. team = SHIP_BLUE;
  291. }else if(ShipWarsInfo[SHIP_RED][TeamPoint] == ShipWarsInfo[SHIP_BLUE][TeamPoint]) {
  292. team = -1;
  293. }
  294. }
  295.  
  296. new string[128];
  297. if(team != -1) {
  298. for(new i; i < GetMaxPlayers(); ++i)
  299. {
  300. if(!IsPlayerConnected(i)) continue;
  301. if(ShipTeam[i] == team)
  302. {
  303. GivePlayerMoney(i, WINNER_MONEY);
  304. }
  305. }
  306.  
  307. format(string, sizeof(string), "[SHIP WARS] Tim %s je pobedio u Ship Wars eventu!", (team == _:SHIP_RED) ? ("Black Pearl Ship") : ("White Pearl Ship"));
  308. SendClientMessageToAll((team == _:SHIP_RED) ? SHIP_COLOR_RED : SHIP_COLOR_BLUE, string);
  309. }else{
  310. SendClientMessageToAll(-1, "[SHIP WARS] Igra je zavrsila nereseno, Cestitke svima na dobroj igri.");
  311. }
  312.  
  313. ResetGame();
  314. }
  315.  
  316. return 1;
  317. }
  318.  
  319. forward StartGame(time, move);
  320. public StartGame(time, move)
  321. {
  322. if(move) {
  323. SendClientMessageToAll(-1, "[SHIP WARS] Event je pokrenut od strane servera. Za ucesce /shipwars!.");
  324. MoveDynamicObject(ShipWarsInfo[SHIP_RED][ShipObject], 402.896, floatsub(-2137.920, EVENT_DISTANCE), 17.415, ShipWarsInfo[SHIP_RED][ShipSpeed]);
  325. MoveDynamicObject(ShipWarsInfo[SHIP_BLUE][ShipObject], 352.896, floatsub(-2137.920, EVENT_DISTANCE), 17.415, ShipWarsInfo[SHIP_BLUE][ShipSpeed]);
  326. }else{
  327. if(time > 1) {
  328. time--;
  329. new string[54];
  330. format(string, sizeof(string), "~n~~w~pokretanje ~r~~h~%d ~n~~g~~h~budi spreman!", time);
  331.  
  332. for(new i; i < GetMaxPlayers(); ++i)
  333. {
  334. if(!IsPlayerConnected(i)) continue;
  335. if(ShipTeam[i] == -1) continue;
  336. PlayerPlaySound(i, 1056, 0.0, 0.0, 0.0);
  337. GameTextForPlayer(i, string, 1000, 3);
  338. }
  339.  
  340. ShipTimer = SetTimerEx("StartGame", 1000, false, "ii", time, 0);
  341. }else if(time == 1) {
  342. if(PlayersInGame < 2) {
  343. SendClientMessageToAll(-1, "[SHIP WARS] Event je zavrsio (Nema dovoljno igraca)");
  344. ResetGame();
  345. }else{
  346. GameStarted = true;
  347.  
  348. for(new i; i < GetMaxPlayers(); ++i)
  349. {
  350. if(!IsPlayerConnected(i)) continue;
  351. if(ShipTeam[i] == -1) continue;
  352. PlayerPlaySound(i, 1057, 0.0, 0.0, 0.0);
  353. for(new x; x < sizeof(EventWeapons); ++x) GivePlayerWeapon(i, EventWeapons[x], EVENT_AMMO);
  354. }
  355.  
  356. SendClientMessageToAll(-1, "[SHIP WARS] Brodovi ce se poceti kretati za 3sekunde.");
  357. ShipTimer = SetTimerEx("StartGame", 3000, false, "ii", 0, 1);
  358. }
  359. }
  360. }
  361.  
  362.  
  363. return 1;
  364. }
  365.  
  366. CMD:shipwars(playerid, params[])
  367. {
  368. if(GameStarted) return SendClientMessage(playerid, 0xE74C3CFF, "[ERROR] {FFFFFF}Ne mozes sada na Ship Wars event.");
  369. if(ShipTeam[playerid] != -1) return SendClientMessage(playerid, 0xE74C3CFF, "[ERROR] {FFFFFF}Vec si na eventu.");
  370. if(PlayersInGame >= EVENT_LIMIT) return SendClientMessage(playerid, 0xE74C3CFF, "[ERROR] {FFFFFF}Brodovi su popunjeni.");
  371. new team = (PlayersInGame % 2 == 0) ? SHIP_RED : SHIP_BLUE;
  372. ShipTeam[playerid] = team;
  373. SetPlayerVirtualWorld(playerid, EVENT_WORLD);
  374. SetPlayerPos(playerid, (team == _:SHIP_RED) ? 402.896 : 352.896, -2109.0, 9.0);
  375. SetPlayerTeam(playerid, team);
  376. ResetPlayerWeapons(playerid);
  377. PlayersInGame++;
  378. new string[128], name[MAX_PLAYER_NAME];
  379. GetPlayerName(playerid, name, MAX_PLAYER_NAME);
  380.  
  381. if(PlayersInGame == 1) {
  382. ShipTimer = SetTimerEx("StartGame", 1000, false, "ii", 20, 0);
  383. format(string, sizeof(string), "[SHIP WARS] %s(%d) je pokrenuo ship wars, mozes se pridruziti na event narednih 20sec.", name, playerid);
  384. format(string, sizeof(string), "[SHIP WARS] %s(%d) se pridruzio. (Team %s) [%d/%d]", name, playerid, (team == _:SHIP_RED) ? ("Black Pearl Ship") : ("White Pearl Ship"), PlayersInGame, EVENT_LIMIT);
  385. }
  386.  
  387. SendClientMessageToAll(-1, string);
  388. SendClientMessage(playerid, (team == _:SHIP_RED) ? SHIP_COLOR_RED : SHIP_COLOR_BLUE, "NAPOMENA: Ubijaj neprijatelje kako bih ubrzao svoj brod, ko prvi dodje do kraja, pobjednik!");
  389. SendClientMessage(playerid, (team == _:SHIP_RED) ? SHIP_COLOR_RED : SHIP_COLOR_BLUE, "Oruzje ce vam se setovati kada odbrojavanje zavrsi.");
  390. SendClientMessage(playerid, (team == _:SHIP_RED) ? SHIP_COLOR_RED : SHIP_COLOR_BLUE, "Mozete napustiti event komandom /izadjisw.");
  391. SetPlayerMapIcon(playerid, EVENT_ICONID, (team == _:SHIP_RED) ? 402.896 : 352.896, floatsub(-2137.920, EVENT_DISTANCE), 17.415, 53, 0, MAPICON_GLOBAL);
  392.  
  393. shipWithTeamColor[playerid] = CreatePlayerTextDraw(playerid, 493.000000, 310.000000, "_");
  394. PlayerTextDrawBackgroundColor(playerid, shipWithTeamColor[playerid], 0);
  395. PlayerTextDrawFont(playerid, shipWithTeamColor[playerid], 5);
  396. PlayerTextDrawLetterSize(playerid, shipWithTeamColor[playerid], 0.500000, 1.000000);
  397. PlayerTextDrawColor(playerid, shipWithTeamColor[playerid], (team == _:SHIP_RED) ? SHIP_COLOR_RED : SHIP_COLOR_BLUE);
  398. PlayerTextDrawSetOutline(playerid, shipWithTeamColor[playerid], 0);
  399. PlayerTextDrawSetProportional(playerid, shipWithTeamColor[playerid], 1);
  400. PlayerTextDrawSetShadow(playerid, shipWithTeamColor[playerid], 1);
  401. PlayerTextDrawUseBox(playerid, shipWithTeamColor[playerid], 1);
  402. PlayerTextDrawBoxColor(playerid, shipWithTeamColor[playerid], 0);
  403. PlayerTextDrawTextSize(playerid, shipWithTeamColor[playerid], 130.000000, 130.000000);
  404. PlayerTextDrawSetPreviewModel(playerid, shipWithTeamColor[playerid], 8493);
  405. PlayerTextDrawSetPreviewRot(playerid, shipWithTeamColor[playerid], 0.000000, 0.000000, -60.000000, 0.574999);
  406. PlayerTextDrawSetSelectable(playerid, shipWithTeamColor[playerid], 0);
  407.  
  408. for(new i; i < sizeof(shipText); ++i) TextDrawShowForPlayer(playerid, shipText[i]);
  409. PlayerTextDrawShow(playerid, shipWithTeamColor[playerid]);
  410. return 1;
  411. }
  412.  
  413. CMD:izadjisw(playerid, params[])
  414. {
  415. if(ShipTeam[playerid] == -1) return SendClientMessage(playerid, 0xE74C3CFF, "[Greska] {FFFFFF}Nisi bio na eventu.");
  416. if(!GameStarted) return SendClientMessage(playerid, 0xE74C3CFF, "[Greska] {FFFFFF}Ne mozes u ovoj fazi napustiti ratne brodove.");
  417. LeaveGame(playerid);
  418. return 1;
  419. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement