Advertisement
Guest User

Ship Wars

a guest
Sep 15th, 2015
653
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 15.05 KB | None | 0 0
  1. #define     FILTERSCRIPT
  2. #include    <a_samp>
  3. #include    <streamer>
  4. #include    <zcmd>
  5.  
  6. #define     EVENT_WORLD         4           // virtualworld id of ship wars event
  7. #define     EVENT_AMMO          5000        // how many ammo players will get for their weapons
  8. #define     EVENT_ICONID        42          // mapicon id for finish icon (not the markertype) for removeplayermapicon
  9. #define     EVENT_LIMIT         24          // max. number of people can join
  10. #define     EVENT_DISTANCE      850.0
  11. #define     DEFAULT_SPEED       7.0
  12.  
  13. #define     WINNER_MONEY        20000       // how much money will winner team get
  14. #define     WINNER_SCORE        5           // how much score will winner team get
  15.  
  16. #define     SHIP_COLOR_RED      0xE74C3CFF  // color of red team
  17. #define     SHIP_COLOR_BLUE     0x3498DBFF  // color of blue team
  18.  
  19. enum    e_swteams
  20. {
  21.     SHIP_RED,
  22.     SHIP_BLUE
  23. }
  24.  
  25. enum    e_teaminfo
  26. {
  27.     ShipObject,
  28.     Float: ShipSpeed,
  29.     TeamPoint
  30. }
  31.  
  32. new
  33.     PlayersInGame,
  34.     ShipTimer = -1,
  35.     bool: GameStarted,
  36.     ShipWarsInfo[2][e_teaminfo],
  37.     ShipTeam[MAX_PLAYERS] = {-1, ...},
  38.     LastFallCheck[MAX_PLAYERS];
  39.    
  40. new
  41.     Text: shipText[4],
  42.     PlayerText: shipWithTeamColor[MAX_PLAYERS];
  43.  
  44. new
  45.     EventWeapons[] = {WEAPON_DEAGLE, WEAPON_SHOTGSPA, WEAPON_M4, WEAPON_RIFLE};
  46.     // will give player a deagle, combat shotgun, m4 and country rifle
  47.     // https://wiki.sa-mp.com/wiki/Weapons
  48.  
  49. stock GivePoints(team, points)
  50. {
  51.     new point_string[6];
  52.     ShipWarsInfo[team][TeamPoint] += points;
  53.     valstr(point_string, ShipWarsInfo[team][TeamPoint]);
  54.     TextDrawSetString(shipText[ (team == _:SHIP_RED) ? 2 : 3 ], point_string);
  55.    
  56.     if(ShipWarsInfo[team][TeamPoint] % 5 == 0 && ShipWarsInfo[team][ShipSpeed] < 20.0)
  57.     {
  58.         ShipWarsInfo[team][ShipSpeed] = floatadd(ShipWarsInfo[team][ShipSpeed], 0.75);
  59.         if(ShipWarsInfo[team][ShipSpeed] > 20.0) ShipWarsInfo[team][ShipSpeed] = 20.0;
  60.         new string[96];
  61.         format(string, sizeof(string), "[%s TEAM] We're gaining speed, keep killing them!", (team == _:SHIP_RED) ? ("RED") : ("BLUE"));
  62.        
  63.         for(new i; i < GetMaxPlayers(); ++i)
  64.         {
  65.             if(!IsPlayerConnected(i)) continue;
  66.             if(ShipTeam[i] == team) SendClientMessage(i, (team == _:SHIP_RED) ? SHIP_COLOR_RED : SHIP_COLOR_BLUE, string);
  67.         }
  68.        
  69.         StopDynamicObject(ShipWarsInfo[team][ShipObject]);
  70.         MoveDynamicObject(ShipWarsInfo[team][ShipObject], (team == _:SHIP_RED) ? 402.896 : 352.896, floatsub(-2137.920, EVENT_DISTANCE), 17.415, ShipWarsInfo[team][ShipSpeed]);
  71.     }
  72.    
  73.     return 1;
  74. }
  75.  
  76. stock LeaveGame(playerid, reason = 0)
  77. {
  78.     if(reason != 1)
  79.     {
  80.         RemovePlayerMapIcon(playerid, EVENT_ICONID);
  81.         ResetPlayerWeapons(playerid);
  82.         SetPlayerTeam(playerid, NO_TEAM);
  83.         SetPlayerVirtualWorld(playerid, 0);
  84.         SpawnPlayer(playerid);
  85.     }
  86.    
  87.     ShipTeam[playerid] = -1;
  88.     PlayersInGame--;
  89.  
  90.     if(PlayersInGame < 2 && reason < 2)
  91.     {
  92.         if(GameStarted) SendClientMessageToAll(-1, "[SHIP WARS] Game cancelled. (not enough players)");
  93.         ResetGame();
  94.     }
  95.    
  96.     for(new i; i < sizeof(shipText); ++i) TextDrawHideForPlayer(playerid, shipText[i]);
  97.     PlayerTextDrawHide(playerid, shipWithTeamColor[playerid]);
  98.     PlayerTextDrawDestroy(playerid, shipWithTeamColor[playerid]);
  99.     return 1;
  100. }
  101.  
  102. stock ResetGame(unload = 0)
  103. {
  104.     for(new i; i < GetMaxPlayers(); ++i)
  105.     {
  106.         if(!IsPlayerConnected(i)) continue;
  107.         if(ShipTeam[i] != -1) LeaveGame(i, 2);
  108.     }
  109.    
  110.     if(!unload)
  111.     {
  112.         if(ShipTimer != -1)
  113.         {
  114.             KillTimer(ShipTimer);
  115.             ShipTimer = -1;
  116.         }
  117.  
  118.         GameStarted = false;
  119.         PlayersInGame = 0;
  120.         StopDynamicObject(ShipWarsInfo[SHIP_RED][ShipObject]);
  121.         StopDynamicObject(ShipWarsInfo[SHIP_BLUE][ShipObject]);
  122.         SetDynamicObjectPos(ShipWarsInfo[SHIP_RED][ShipObject], 402.896, -2137.920, 17.415);
  123.         SetDynamicObjectPos(ShipWarsInfo[SHIP_BLUE][ShipObject], 352.896, -2137.920, 17.415);
  124.         ShipWarsInfo[SHIP_RED][ShipSpeed] = DEFAULT_SPEED;
  125.         ShipWarsInfo[SHIP_BLUE][ShipSpeed] = DEFAULT_SPEED;
  126.         ShipWarsInfo[SHIP_RED][TeamPoint] = 0;
  127.         ShipWarsInfo[SHIP_BLUE][TeamPoint] = 0;
  128.        
  129.         TextDrawSetString(shipText[2], "0");
  130.         TextDrawSetString(shipText[3], "0");
  131.     }
  132.    
  133.     return 1;
  134. }
  135.  
  136. public OnFilterScriptInit()
  137. {
  138.     ShipWarsInfo[SHIP_RED][ShipObject] = CreateDynamicObject(8493, 402.896, -2137.920, 17.415, 0.000, 0.000, 180.000, EVENT_WORLD, 0);
  139.     ShipWarsInfo[SHIP_BLUE][ShipObject] = CreateDynamicObject(8493, 352.896, -2137.920, 17.415, 0.000, 0.000, 180.000, EVENT_WORLD, 0);
  140.     SetDynamicObjectMaterial(ShipWarsInfo[SHIP_RED][ShipObject], 2, -1, "none", "none", -1618884);
  141.     SetDynamicObjectMaterial(ShipWarsInfo[SHIP_RED][ShipObject], 3, -1, "none", "none", -1618884);
  142.     SetDynamicObjectMaterial(ShipWarsInfo[SHIP_BLUE][ShipObject], 2, -1, "none", "none", -13330213);
  143.     SetDynamicObjectMaterial(ShipWarsInfo[SHIP_BLUE][ShipObject], 3, -1, "none", "none", -13330213);
  144.    
  145.     ShipWarsInfo[SHIP_RED][ShipSpeed] = DEFAULT_SPEED;
  146.     ShipWarsInfo[SHIP_BLUE][ShipSpeed] = DEFAULT_SPEED;
  147.    
  148.     shipText[0] = TextDrawCreate(495.000000, 355.000000, "_");
  149.     TextDrawBackgroundColor(shipText[0], 0);
  150.     TextDrawFont(shipText[0], 5);
  151.     TextDrawLetterSize(shipText[0], 0.500000, 1.000000);
  152.     TextDrawColor(shipText[0], -414434049);
  153.     TextDrawSetOutline(shipText[0], 0);
  154.     TextDrawSetProportional(shipText[0], 1);
  155.     TextDrawSetShadow(shipText[0], 1);
  156.     TextDrawUseBox(shipText[0], 1);
  157.     TextDrawBoxColor(shipText[0], 0);
  158.     TextDrawTextSize(shipText[0], 16.000000, 16.000000);
  159.     TextDrawSetPreviewModel(shipText[0], 1254);
  160.     TextDrawSetPreviewRot(shipText[0], 0.000000, 0.000000, 0.000000, 0.875000);
  161.     TextDrawSetSelectable(shipText[0], 0);
  162.  
  163.     shipText[1] = TextDrawCreate(495.000000, 375.000000, "_");
  164.     TextDrawBackgroundColor(shipText[1], 0);
  165.     TextDrawFont(shipText[1], 5);
  166.     TextDrawLetterSize(shipText[1], 0.500000, 1.000000);
  167.     TextDrawColor(shipText[1], 882433023);
  168.     TextDrawSetOutline(shipText[1], 0);
  169.     TextDrawSetProportional(shipText[1], 1);
  170.     TextDrawSetShadow(shipText[1], 1);
  171.     TextDrawUseBox(shipText[1], 1);
  172.     TextDrawBoxColor(shipText[1], 0);
  173.     TextDrawTextSize(shipText[1], 16.000000, 16.000000);
  174.     TextDrawSetPreviewModel(shipText[1], 1254);
  175.     TextDrawSetPreviewRot(shipText[1], 0.000000, 0.000000, 0.000000, 0.875000);
  176.     TextDrawSetSelectable(shipText[1], 0);
  177.    
  178.     shipText[2] = TextDrawCreate(511.000000, 357.000000, "0");
  179.     TextDrawBackgroundColor(shipText[2], 255);
  180.     TextDrawFont(shipText[2], 1);
  181.     TextDrawLetterSize(shipText[2], 0.210000, 1.100000);
  182.     TextDrawColor(shipText[2], -414434049);
  183.     TextDrawSetOutline(shipText[2], 1);
  184.     TextDrawSetProportional(shipText[2], 1);
  185.     TextDrawSetSelectable(shipText[2], 0);
  186.  
  187.     shipText[3] = TextDrawCreate(511.000000, 377.000000, "0");
  188.     TextDrawBackgroundColor(shipText[3], 255);
  189.     TextDrawFont(shipText[3], 1);
  190.     TextDrawLetterSize(shipText[3], 0.210000, 1.100000);
  191.     TextDrawColor(shipText[3], 882433023);
  192.     TextDrawSetOutline(shipText[3], 1);
  193.     TextDrawSetProportional(shipText[3], 1);
  194.     TextDrawSetSelectable(shipText[3], 0);
  195.     return 1;
  196. }
  197.  
  198. public OnFilterScriptExit()
  199. {
  200.     for(new i; i < sizeof(shipText); ++i)
  201.     {
  202.         TextDrawHideForAll(shipText[i]);
  203.         TextDrawDestroy(shipText[i]);
  204.     }
  205.    
  206.     ResetGame(1);
  207.     return 1;
  208. }
  209.  
  210. public OnPlayerConnect(playerid)
  211. {
  212.     ShipTeam[playerid] = -1;
  213.     LastFallCheck[playerid] = 0;
  214.     return 1;
  215. }
  216.  
  217. public OnPlayerDisconnect(playerid, reason)
  218. {
  219.     if(ShipTeam[playerid] != -1) LeaveGame(playerid, 1);
  220.     return 1;
  221. }
  222.  
  223. public OnPlayerUpdate(playerid)
  224. {
  225.     if(ShipTeam[playerid] != -1 && LastFallCheck[playerid] < tickcount())
  226.     {
  227.         LastFallCheck[playerid] = tickcount()+500;
  228.        
  229.         new Float: temp, Float: z;
  230.         GetPlayerPos(playerid, temp, temp, z);
  231.         if(z < 3.0)
  232.         {
  233.             SetPlayerHealth(playerid, -1.0);
  234.             GivePoints((ShipTeam[playerid] == _:SHIP_RED) ? SHIP_BLUE : SHIP_RED, 1);
  235.         }
  236.     }
  237.    
  238.     return 1;
  239. }
  240.  
  241. public OnPlayerSpawn(playerid)
  242. {
  243.     if(ShipTeam[playerid] != -1)
  244.     {
  245.         new Float: x, Float: y, Float: z;
  246.         GetDynamicObjectPos(ShipWarsInfo[ ShipTeam[playerid] ][ShipObject], x, y, z);
  247.         SetPlayerVirtualWorld(playerid, EVENT_WORLD);
  248.         SetPlayerPos(playerid, x, y - (-22.22), 9.5);
  249.         SetPlayerTeam(playerid, ShipTeam[playerid]);
  250.         ResetPlayerWeapons(playerid);
  251.         if(GameStarted) for(new i; i < sizeof(EventWeapons); ++i) GivePlayerWeapon(playerid, EventWeapons[i], EVENT_AMMO);
  252.     }
  253.    
  254.     return 1;
  255. }
  256.  
  257. public OnPlayerDeath(playerid, killerid, reason)
  258. {
  259.     if(killerid != INVALID_PLAYER_ID && ShipTeam[playerid] != -1 && ShipTeam[killerid] != -1 && ShipTeam[playerid] != ShipTeam[killerid])
  260.     {
  261.         new Float: temp, Float: z;
  262.         GetPlayerPos(playerid, temp, temp, z);
  263.         if(z > 5.0) GivePoints(ShipTeam[killerid], 1);
  264.     }
  265.    
  266.     return 1;
  267. }
  268.  
  269. public OnDynamicObjectMoved(objectid)
  270. {
  271.     new team = -1;
  272.     if(objectid == ShipWarsInfo[SHIP_RED][ShipObject]) {
  273.         team = SHIP_RED;
  274.     }else if(objectid == ShipWarsInfo[SHIP_BLUE][ShipObject]) {
  275.         team = SHIP_BLUE;
  276.     }else{
  277.         team = -1;
  278.     }
  279.    
  280.     if(team == -1) return 1;
  281.     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);
  282.     GetDynamicObjectPos(objectid, x, y, z);
  283.     new Float: dist = floatsqroot(floatpower(fin_x-x, 2.0) + floatpower(fin_y-y, 2.0));
  284.     if(dist < 10.0)
  285.     {
  286.         if(ShipWarsInfo[SHIP_RED][ShipSpeed] == ShipWarsInfo[SHIP_BLUE][ShipSpeed])
  287.         {
  288.             if(ShipWarsInfo[SHIP_RED][TeamPoint] > ShipWarsInfo[SHIP_BLUE][TeamPoint]) {
  289.                 team = SHIP_RED;
  290.             }else if(ShipWarsInfo[SHIP_BLUE][TeamPoint] > ShipWarsInfo[SHIP_RED][TeamPoint]) {
  291.                 team = SHIP_BLUE;
  292.             }else if(ShipWarsInfo[SHIP_RED][TeamPoint] == ShipWarsInfo[SHIP_BLUE][TeamPoint]) {
  293.                 team = -1;
  294.             }
  295.         }
  296.        
  297.         new string[128];
  298.         if(team != -1) {
  299.             for(new i; i < GetMaxPlayers(); ++i)
  300.             {
  301.                 if(!IsPlayerConnected(i)) continue;
  302.                 if(ShipTeam[i] == team)
  303.                 {
  304.                     GivePlayerMoney(i, WINNER_MONEY);
  305.                     SetPlayerScore(i, GetPlayerScore(i) + WINNER_SCORE);
  306.                 }
  307.             }
  308.            
  309.             format(string, sizeof(string), "[SHIP WARS] Team %s has won the ship wars!", (team == _:SHIP_RED) ? ("Red") : ("Blue"));
  310.             SendClientMessageToAll((team == _:SHIP_RED) ? SHIP_COLOR_RED : SHIP_COLOR_BLUE, string);
  311.         }else{
  312.             SendClientMessageToAll(-1, "[SHIP WARS] This game has resulted in a draw.");
  313.         }
  314.        
  315.         ResetGame();
  316.     }
  317.    
  318.     return 1;
  319. }
  320.  
  321. forward StartGame(time, move);
  322. public StartGame(time, move)
  323. {
  324.     if(move) {
  325.         SendClientMessageToAll(-1, "[SHIP WARS] Game started.");
  326.         MoveDynamicObject(ShipWarsInfo[SHIP_RED][ShipObject], 402.896, floatsub(-2137.920, EVENT_DISTANCE), 17.415, ShipWarsInfo[SHIP_RED][ShipSpeed]);
  327.         MoveDynamicObject(ShipWarsInfo[SHIP_BLUE][ShipObject], 352.896, floatsub(-2137.920, EVENT_DISTANCE), 17.415, ShipWarsInfo[SHIP_BLUE][ShipSpeed]);
  328.     }else{
  329.         if(time > 1) {
  330.             time--;
  331.             new string[54];
  332.             format(string, sizeof(string), "~n~~w~starting in ~r~~h~%d ~n~~g~~h~get ready!", time);
  333.  
  334.             for(new i; i < GetMaxPlayers(); ++i)
  335.             {
  336.                 if(!IsPlayerConnected(i)) continue;
  337.                 if(ShipTeam[i] == -1) continue;
  338.                 PlayerPlaySound(i, 1056, 0.0, 0.0, 0.0);
  339.                 GameTextForPlayer(i, string, 1000, 3);
  340.             }
  341.  
  342.             ShipTimer = SetTimerEx("StartGame", 1000, false, "ii", time, 0);
  343.         }else if(time == 1) {
  344.             if(PlayersInGame < 2) {
  345.                 SendClientMessageToAll(-1, "[SHIP WARS] Game cancelled. (not enough players)");
  346.                 ResetGame();
  347.             }else{
  348.                 GameStarted = true;
  349.  
  350.                 for(new i; i < GetMaxPlayers(); ++i)
  351.                 {
  352.                     if(!IsPlayerConnected(i)) continue;
  353.                     if(ShipTeam[i] == -1) continue;
  354.                     PlayerPlaySound(i, 1057, 0.0, 0.0, 0.0);
  355.                     for(new x; x < sizeof(EventWeapons); ++x) GivePlayerWeapon(i, EventWeapons[x], EVENT_AMMO);
  356.                 }
  357.  
  358.                 SendClientMessageToAll(-1, "[SHIP WARS] Ships will start moving in 3 seconds.");
  359.                 ShipTimer = SetTimerEx("StartGame", 3000, false, "ii", 0, 1);
  360.             }
  361.         }
  362.     }
  363.    
  364.    
  365.     return 1;
  366. }
  367.  
  368. CMD:shipwars(playerid, params[])
  369. {
  370.     if(GameStarted) return SendClientMessage(playerid, 0xE74C3CFF, "[ERROR] {FFFFFF}You can't join ship wars right now.");
  371.     if(ShipTeam[playerid] != -1) return SendClientMessage(playerid, 0xE74C3CFF, "[ERROR] {FFFFFF}You're already in ship wars.");
  372.     if(PlayersInGame >= EVENT_LIMIT) return SendClientMessage(playerid, 0xE74C3CFF, "[ERROR] {FFFFFF}Ship wars is full.");
  373.     new team = (PlayersInGame % 2 == 0) ? SHIP_RED : SHIP_BLUE;
  374.     ShipTeam[playerid] = team;
  375.     SetPlayerVirtualWorld(playerid, EVENT_WORLD);
  376.     SetPlayerPos(playerid, (team == _:SHIP_RED) ? 402.896 : 352.896, -2109.0, 9.0);
  377.     SetPlayerTeam(playerid, team);
  378.     ResetPlayerWeapons(playerid);
  379.     PlayersInGame++;
  380.     new string[128], name[MAX_PLAYER_NAME];
  381.     GetPlayerName(playerid, name, MAX_PLAYER_NAME);
  382.  
  383.     if(PlayersInGame == 1) {
  384.         ShipTimer = SetTimerEx("StartGame", 1000, false, "ii", 20, 0);
  385.         format(string, sizeof(string), "[SHIP WARS] %s(%d) has started the ship wars, you can join in the next 20 seconds.", name, playerid);
  386.     }else{
  387.         format(string, sizeof(string), "[SHIP WARS] %s(%d) has joined. (Team %s) [%d/%d]", name, playerid, (team == _:SHIP_RED) ? ("Red") : ("Blue"), PlayersInGame, EVENT_LIMIT);
  388.     }
  389.    
  390.     SendClientMessageToAll(-1, string);
  391.     SendClientMessage(playerid, (team == _:SHIP_RED) ? SHIP_COLOR_RED : SHIP_COLOR_BLUE, "OBJECTIVE: Kill the enemy team to speed up your ship. First ship gets to end wins!");
  392.     SendClientMessage(playerid, (team == _:SHIP_RED) ? SHIP_COLOR_RED : SHIP_COLOR_BLUE, "You'll receive weapons when the countdown finishes.");
  393.     SendClientMessage(playerid, (team == _:SHIP_RED) ? SHIP_COLOR_RED : SHIP_COLOR_BLUE, "You can leave ship wars by using /leaveship.");
  394.     SetPlayerMapIcon(playerid, EVENT_ICONID, (team == _:SHIP_RED) ? 402.896 : 352.896, floatsub(-2137.920, EVENT_DISTANCE), 17.415, 53, 0, MAPICON_GLOBAL);
  395.  
  396.     shipWithTeamColor[playerid] = CreatePlayerTextDraw(playerid, 493.000000, 310.000000, "_");
  397.     PlayerTextDrawBackgroundColor(playerid, shipWithTeamColor[playerid], 0);
  398.     PlayerTextDrawFont(playerid, shipWithTeamColor[playerid], 5);
  399.     PlayerTextDrawLetterSize(playerid, shipWithTeamColor[playerid], 0.500000, 1.000000);
  400.     PlayerTextDrawColor(playerid, shipWithTeamColor[playerid], (team == _:SHIP_RED) ? SHIP_COLOR_RED : SHIP_COLOR_BLUE);
  401.     PlayerTextDrawSetOutline(playerid, shipWithTeamColor[playerid], 0);
  402.     PlayerTextDrawSetProportional(playerid, shipWithTeamColor[playerid], 1);
  403.     PlayerTextDrawSetShadow(playerid, shipWithTeamColor[playerid], 1);
  404.     PlayerTextDrawUseBox(playerid, shipWithTeamColor[playerid], 1);
  405.     PlayerTextDrawBoxColor(playerid, shipWithTeamColor[playerid], 0);
  406.     PlayerTextDrawTextSize(playerid, shipWithTeamColor[playerid], 130.000000, 130.000000);
  407.     PlayerTextDrawSetPreviewModel(playerid, shipWithTeamColor[playerid], 8493);
  408.     PlayerTextDrawSetPreviewRot(playerid, shipWithTeamColor[playerid], 0.000000, 0.000000, -60.000000, 0.574999);
  409.     PlayerTextDrawSetSelectable(playerid, shipWithTeamColor[playerid], 0);
  410.  
  411.     for(new i; i < sizeof(shipText); ++i) TextDrawShowForPlayer(playerid, shipText[i]);
  412.     PlayerTextDrawShow(playerid, shipWithTeamColor[playerid]);
  413.     return 1;
  414. }
  415.  
  416. CMD:leaveship(playerid, params[])
  417. {
  418.     if(ShipTeam[playerid] == -1) return SendClientMessage(playerid, 0xE74C3CFF, "[ERROR] {FFFFFF}You're not in ship wars.");
  419.     if(!GameStarted) return SendClientMessage(playerid, 0xE74C3CFF, "[ERROR] {FFFFFF}You can't leave ship wars in this stage.");
  420.     LeaveGame(playerid);
  421.     return 1;
  422. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement