Advertisement
C_far

Tower | FFG

Aug 14th, 2018
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 15.16 KB | None | 0 0
  1. /*
  2.  
  3.     888888888888  ,ad8888ba,   I8,        8        ,8I  88888888888  88888888ba  
  4.          88      d8"'    `"8b  `8b       d8b       d8'  88           88      "8b  
  5.          88     d8'        `8b  "8,     ,8"8,     ,8"   88           88      ,8P  
  6.          88     88          88   Y8     8P Y8     8P    88aaaaa      88aaaaaa8P'  
  7.          88     88          88   `8b   d8' `8b   d8'    88"""""      88""""88'    
  8.          88     Y8,        ,8P    `8a a8'   `8a a8'     88           88    `8b    
  9.          88      Y8a.    .a8P      `8a8'     `8a8'      88           88     `8b  
  10.          88       `"Y8888Y"'        `8'       `8'       88888888888  88      `8b  
  11.  
  12. */
  13.  
  14. #include "YSI\y_hooks"
  15.  
  16. //-----------------------------
  17. //-------------------------------------------------
  18. //-----------------------------
  19.  
  20. stock static GAMEID;
  21.  
  22. //-----------------------------
  23.  
  24. static
  25.     bool:finish[MAX_LINKS_PER_GAME char],
  26.  
  27.     object_towers[MAX_LINKS_PER_GAME][2],
  28.    
  29.     Text3D:text3d_health_towers[MAX_LINKS_PER_GAME][2],
  30.     int_health_towers[MAX_LINKS_PER_GAME][2],
  31.    
  32.     timer_bomb[MAX_LINKS_PER_GAME],
  33.     object_bomb[MAX_LINKS_PER_GAME],
  34.     Text3D:text3d_bomb[MAX_LINKS_PER_GAME];
  35.    
  36. static const Float:pos_towers[2][3] =
  37. {
  38.     {-972.296020, 1022.695556, 1345.796508},
  39.     {-1133.212890, 1096.327270, 1345.796508}
  40. };
  41.    
  42. //-----------------------------
  43. //-------------------------------------------------
  44. //-----------------------------
  45.  
  46. enum e_PLAYERS_TOWER
  47. {
  48.     pTowKills,
  49.     pTowDeaths,
  50.  
  51.     pTowDamagesTower,
  52.     pTowBombsExp,
  53.    
  54.     bool:pTowHasBomb
  55. }
  56.  
  57. static
  58.     P_TOW[MAX_PLAYERS][e_PLAYERS_TOWER];
  59.  
  60. //-----------------------------
  61. //-------------------------------------------------
  62. //-----------------------------
  63.  
  64. static GivePlayerPoints(playerid, points, bool:won)
  65. {
  66.     new
  67.         clone[e_PLAYERS_TOWER];
  68.        
  69.     clone = P_TOW[playerid];
  70.  
  71.     static
  72.         query[512];
  73.        
  74.     mysql_format(mysql, query, sizeof(query), "\
  75.     UPDATE TowerGameStats SET \
  76.     Points = Points + %d,\
  77.     Games = Games + 1,\
  78.     GamesWon = GamesWon + %d,\
  79.     GamesLost = GamesLost + %d,\
  80.     GameTime = GameTime + %d,\
  81.     Kills = Kills + %d,\
  82.     Deaths = Deaths + %d,\
  83.     DamagesTower = DamagesTower + %d,\
  84.     BombsExplosed = BombsExplosed + %d \
  85.     WHERE ID = %d",
  86.    
  87.     points,
  88.    
  89.     _:won,
  90.     _:!won,
  91.    
  92.     GetGameTimeByLinkID(PLAYERS[playerid][pLink]),
  93.    
  94.     clone[pTowKills],
  95.     clone[pTowDeaths],
  96.    
  97.     clone[pTowDamagesTower],
  98.     clone[pTowBombsExp],
  99.    
  100.     PLAYERS[playerid][pIDSql]);
  101.    
  102.     //mysql_tquery(mysql, query);
  103.  
  104.     Scm(playerid, Color.GOLD, "Tu remportes "GRAY"%d "GOLD"points !", points);     
  105.     Scm(playerid, Color.AQUA, "Tu remportes "GRAY"%d "AQUA"dollars !", GivePlayerDollars(playerid, points));
  106.    
  107.     return true;
  108. }
  109.  
  110. //-----------------------------
  111.  
  112. static DropBomb(playerid, linkid)
  113. {
  114.     foreach(new i : LinkPlayer[linkid])
  115.     {
  116.         GTFP(i, "~b~La bombe est au sol.", 3000, 4);
  117.     }
  118.    
  119.     P_TOW[playerid][pTowHasBomb] = false;
  120.    
  121.     new
  122.         cell = GetCellLink(LINKS[linkid][lGame], linkid),
  123.         Float:x,
  124.         Float:y,
  125.         Float:z;
  126.        
  127.     GetPlayerPos(playerid, x, y, z);
  128.    
  129.     object_bomb[cell] = CreateDynamicObject(2891, x, y, z - 1.0, 0.000000, 0.000000, 0.000000, LINKS[linkid][lWorldID], 10, -1, 400.0, 0.0);
  130.     text3d_bomb[cell] = CreateDynamic3DTextLabel("Pour prendre la bombe\nAppuie sur N et clique sur la bombe.", Color.AQUA, x, y, z - 1.0, 250.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, LINKS[linkid][lWorldID], 10, -1, 10.0);
  131.    
  132.     RemovePlayerAttachedObject(playerid, 0);
  133.    
  134.     return true;
  135. }
  136.  
  137. //-----------------------------
  138. //-------------------------------------------------
  139. //-----------------------------
  140.  
  141. static OnTowerTakeDamage(linkid, cell, teamid_tower);
  142. static Timer_Bomb(linkid, cell);
  143.  
  144. //-----------------------------
  145. //-------------------------------------------------
  146. //-----------------------------
  147.  
  148. GameMode::Init()
  149. {
  150.     new
  151.         links[][2] =
  152.         {
  153.             {2, 2}, // 4 players
  154.             {2, 4}, // 8 players
  155.             {2, 6}, // 12 players
  156.             {2, 8} // 16 players
  157.         };
  158.  
  159.     GAMEID = CreateGame("Tower", links, 11461);
  160.    
  161.     //-----------------------------
  162.    
  163.     new
  164.         clone[e_GAMES];
  165.        
  166.     clone = GAMES[GAMEID];
  167.    
  168.     for(new l = 0; l < clone[gaNbrLinks]; l++)
  169.     {
  170.         new
  171.             worldid = LINKS[ clone[gaLinks][l] ][lWorldID];
  172.    
  173.         object_towers[l][0] = CreateDynamicObject(11461, pos_towers[0][0], pos_towers[0][1], pos_towers[0][2] - 14.0, 0.000000, 0.000000, 12.500000, worldid, 10, -1, 200.0, 0.0);
  174.         text3d_health_towers[l][0] = CreateDynamic3DTextLabel("", -1, pos_towers[0][0], pos_towers[0][1], pos_towers[0][2], 250.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, worldid, 10, -1, 100.0);
  175.        
  176.         object_towers[l][1] = CreateDynamicObject(11461, pos_towers[1][0], pos_towers[1][1], pos_towers[1][2] - 14.0, 0.000000, 0.000000, 12.500000, worldid, 10, -1, 200.0, 0.0);
  177.         text3d_health_towers[l][1] = CreateDynamic3DTextLabel("", -1, pos_towers[1][0], pos_towers[1][1], pos_towers[1][2], 250.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, worldid, 10, -1, 100.0);
  178.        
  179.         #include "tower_map.pwn"
  180.     }
  181. }
  182.  
  183. //-----------------------------
  184. //-------------------------------------------------
  185. //-----------------------------
  186.  
  187. GAME::This->Start(gameid, linkid)
  188. {
  189.     new
  190.         cell = GetCellLink(gameid, linkid);
  191.    
  192.     UpdateDynamic3DTextLabelText(text3d_health_towers[cell][0], GetTeamColorString(0), "1000/1000");
  193.     int_health_towers[cell][0] = 1000;
  194.    
  195.     UpdateDynamic3DTextLabelText(text3d_health_towers[cell][1], GetTeamColorString(1), "1000/1000");
  196.     int_health_towers[cell][1] = 1000;
  197.  
  198.     //-----------------------------
  199.    
  200.     timer_bomb[cell] = SetTimerEx("Timer_Bomb", 120000, false, "dd", linkid, cell);
  201.    
  202.     finish{cell} = false;
  203.    
  204.     return true;
  205. }
  206.  
  207. //-----------------------------
  208.  
  209. GAME::This->Finish(gameid, linkid)
  210. {
  211.     new
  212.         cell = GetCellLink(gameid, linkid);
  213.  
  214.     KillTimer(timer_bomb[cell]);
  215.  
  216.     return true;
  217. }
  218.  
  219. //-----------------------------
  220.  
  221. GAME::Player->Join(gameid, linkid, playerid)
  222. {
  223.     RemoveBuildingForPlayer(playerid, 3935, -1097.7422, 1037.8750, 1343.0781, 0.25);
  224.     RemoveBuildingForPlayer(playerid, 3936, -974.5547, 1059.4609, 1344.7734, 0.25);
  225.     RemoveBuildingForPlayer(playerid, 3937, -1130.9219, 1059.4609, 1345.4688, 0.25);
  226.  
  227.     //-----------------------------
  228.    
  229.     static
  230.         query[128];
  231.        
  232.     mysql_format(mysql, query, sizeof(query), "INSERT INTO TowerGameStats (ID) VALUES (%d) ON DUPLICATE KEY UPDATE ID = %d", PLAYERS[playerid][pIDSql], PLAYERS[playerid][pIDSql]);
  233.     //mysql_tquery(mysql, query);
  234.    
  235.     //-----------------------------
  236.    
  237.     SetPlayerColor(playerid, RemoveColorAlpha(TEAMS[ PLAYERS[playerid][pTeamDG] ][tColor]));
  238.    
  239.     return true;
  240. }
  241.  
  242. //-----------------------------
  243.  
  244. GAME::Player->Quit(gameid, linkid, playerid, teamid)
  245. {  
  246.     if(GetNumberPlayersInTeam(linkid, teamid) == 0)
  247.     {
  248.         new
  249.             cell = GetCellLink(gameid, linkid),
  250.             team_enemy = _:!teamid,
  251.             points_bonus = floatround(float(GetGameTimeByLinkID(linkid)) * 0.03125);
  252.            
  253.         ScmToLink(linkid, Color.WHITE, "L'équipe {%x}%s "WHITE"gagne la partie !", TEAMS[team_enemy][tColor] >>> 8, TEAMS[team_enemy][tName]);
  254.  
  255.         foreach(new i : LinkPlayer[linkid])
  256.         {              
  257.             if(team_enemy == PLAYERS[i][pTeamDG])
  258.             {
  259.                 new
  260.                     points = 0;
  261.            
  262.                 points += P_TOW[i][pTowDamagesTower] / 50;
  263.                 points += P_TOW[i][pTowBombsExp] * 5;
  264.                 points += floatround(float(P_TOW[i][pTowKills]) * 1.5);
  265.                 points += points_bonus;
  266.                
  267.                 GivePlayerPoints(i, points, true);
  268.             }
  269.         }
  270.        
  271.         EndGame(linkid);
  272.         finish{cell} = true;
  273.     }
  274.    
  275.     static const
  276.         eBlank[e_PLAYERS_TOWER];
  277.        
  278.     P_TOW[playerid] = eBlank;
  279.    
  280.     return true;
  281. }
  282.  
  283. //-----------------------------
  284.  
  285. GAME::Player->Spawn(gameid, linkid, playerid)
  286. {
  287.     static const
  288.         Float:spawns[][][] =
  289.         {
  290.             {
  291.                 {-976.590820, 1092.075683, 1344.968994, 167.189147},
  292.                 {-974.331054, 1091.783691, 1344.977539, 182.229415},
  293.                 {-972.614746, 1090.735961, 1344.990112, 87.915122},
  294.                 {-972.616577, 1088.796875, 1344.991577, 85.408508},
  295.                 {-974.064819, 1087.205200, 1344.982788, 353.287658},
  296.                 {-976.501831, 1087.189941, 1344.965942, 359.554565}
  297.             },
  298.            
  299.             {
  300.                 {-1130.423461, 1026.689697, 1345.723999, 2.107750},
  301.                 {-1133.388183, 1026.707275, 1345.739990, 358.011108},
  302.                 {-1134.376220, 1028.029052, 1345.745239, 272.493530},
  303.                 {-1134.375854, 1030.457885, 1345.745239, 263.406768},
  304.                 {-1133.348754, 1031.585083, 1345.734863, 169.719161},
  305.                 {-1130.280639, 1031.601318, 1345.718872, 183.819366}
  306.             }
  307.         };
  308.    
  309.     new
  310.         teamid = PLAYERS[playerid][pTeamDG],
  311.         rand = random(sizeof(spawns[]));
  312.        
  313.     SetPlayerInterior(playerid, 10);
  314.    
  315.     SetPlayerPos(playerid, spawns[teamid][rand][0], spawns[teamid][rand][1], spawns[teamid][rand][2]);
  316.     SetPlayerFacingAngle(playerid, spawns[teamid][rand][3]);
  317.  
  318.     //-----------------------------
  319.    
  320.     GivePlayerWeapon(playerid, 24, cellmax);
  321.     GivePlayerWeapon(playerid, 27, cellmax);
  322.     GivePlayerWeapon(playerid, 29, cellmax);
  323.    
  324.     //-----------------------------
  325.    
  326.     SetPlayerSkin(playerid, teamid ? 287 : 285);
  327.    
  328.     SetPlayerHealth(playerid, 100.0);
  329.    
  330.     return true;
  331. }
  332.  
  333. //-----------------------------
  334.  
  335. GAME::Player->KillPlayer(gameid, linkid, playerid, deathid)
  336. {
  337.     P_TOW[playerid][pTowKills]++;
  338.  
  339.     return true;
  340. }
  341.  
  342. //-----------------------------
  343.  
  344. GAME::Player->Death(gameid, linkid, playerid)
  345. {
  346.     P_TOW[playerid][pTowDeaths]++;
  347.    
  348.     if(P_TOW[playerid][pTowHasBomb])
  349.         DropBomb(playerid, linkid);
  350.  
  351.     return true;
  352. }
  353.  
  354. //-----------------------------
  355.  
  356. GAME::Player->ShotObject(gameid, linkid, playerid, weaponid, objectid)
  357. {
  358.     new
  359.         cell = GetCellLink(gameid, linkid),
  360.         teamid_enemy = !PLAYERS[playerid][pTeamDG],
  361.         tower_object = object_towers[cell][teamid_enemy];
  362.  
  363.     if(tower_object == objectid)
  364.     {
  365.         static
  366.             Float:x,
  367.             Float:y,
  368.             Float:z;
  369.            
  370.         GetDynamicObjectPos(tower_object, x, y, z);
  371.        
  372.         if(!IsPlayerInRangeOfPoint(playerid, 20.0, x, y, z))
  373.             return GTFP(playerid, "~r~Tu es trop loin de la tourelle.", 1000, 4);
  374.  
  375.         switch(weaponid)
  376.         {
  377.             case WEAPON_DEAGLE: int_health_towers[cell][teamid_enemy] -= 10, P_TOW[playerid][pTowDamagesTower] += 10;
  378.             case WEAPON_SHOTGSPA: int_health_towers[cell][teamid_enemy] -= 4, P_TOW[playerid][pTowDamagesTower] += 4;
  379.             default: int_health_towers[cell][teamid_enemy]--, P_TOW[playerid][pTowDamagesTower]++;
  380.         }
  381.        
  382.         OnTowerTakeDamage(linkid, cell, teamid_enemy);
  383.     }
  384.    
  385.     return true;
  386. }
  387.  
  388. //-----------------------------
  389.  
  390. GAME::Player->KeyChange(gameid, linkid, playerid, newkeys, oldkeys)
  391. {
  392.     if(HOLDING(KEY_NO))
  393.     {
  394.         if(P_TOW[playerid][pTowHasBomb])
  395.         {
  396.             DropBomb(playerid, linkid);
  397.         }
  398.        
  399.         else
  400.         {
  401.             new
  402.                 cell = GetCellLink(gameid, linkid),
  403.                 Float:x,
  404.                 Float:y,
  405.                 Float:z;
  406.        
  407.             GetDynamicObjectPos(object_bomb[cell], x, y, z);
  408.        
  409.             if(GetPlayerDistanceFromPoint(playerid, x, y, z) > 5.0)
  410.                 return GameTextForPlayer(playerid, "~r~Tu es trop loin de la bombe.", 1000, 4);
  411.            
  412.             P_TOW[playerid][pTowHasBomb] = true;
  413.             SetPlayerAttachedObject(playerid, 0, 2891, 1, 0.127000, -0.053999, -0.011000, 92.000007, 0.000000, 90.199974);
  414.            
  415.             DestroyDynamicObject(object_bomb[cell]);
  416.             DestroyDynamic3DTextLabel(text3d_bomb[cell]);
  417.            
  418.             GTFP(playerid, "~g~Tu viens de ramasser la bombe~n~~b~Fais-toi sauter avec la tourelle adverse.", 1000, 4);
  419.             Scm(playerid, Color.GRAY, "Pour te faire sauter avec la bombe, appuyez sur la touche H.");
  420.         }
  421.        
  422.         return true;
  423.     }
  424.    
  425.     if(HOLDING(KEY_CTRL_BACK))
  426.     {
  427.         if(P_TOW[playerid][pTowHasBomb])
  428.         {
  429.             new
  430.                 cell = GetCellLink(gameid, linkid),
  431.                 teamid_enemy = !PLAYERS[playerid][pTeamDG];
  432.        
  433.             if(!IsPlayerInRangeOfPoint(playerid, 5.0, pos_towers[teamid_enemy][0], pos_towers[teamid_enemy][1], pos_towers[teamid_enemy][2]))
  434.                 return GameTextForPlayer(playerid, "~r~Tu es trop loin de la tourelle.", 1000, 4);
  435.        
  436.             P_TOW[playerid][pTowBombsExp]++;
  437.             P_TOW[playerid][pTowHasBomb] = false;
  438.            
  439.             RemovePlayerAttachedObject(playerid, 0);
  440.            
  441.             new
  442.                 Float:x,
  443.                 Float:y,
  444.                 Float:z;
  445.                
  446.             GetPlayerPos(playerid, x, y, z);
  447.             SetPlayerHealth(playerid, 0.0);
  448.             CreateExplosion(x, y, z, 6, 15.0);
  449.            
  450.             int_health_towers[cell][teamid_enemy] -= 200;
  451.            
  452.             foreach(new i : LinkPlayer[linkid])
  453.             {
  454.                 GTFP(i, "~g~La bombe apparaitra~n~~y~dans 2 minutes.", 5000, 4);
  455.                
  456.                 if(teamid_enemy == PLAYERS[playerid][pTeamDG])
  457.                     Scm(i, Color.RED, "La bombe vient d'endommager votre tourelle.");
  458.                    
  459.                 else
  460.                     Scm(i, Color.GREEN, "La bombe vient d'endommager la tourelle adverse.");
  461.             }
  462.  
  463.             timer_bomb[cell] = SetTimerEx("Timer_Bomb", 120000, false, "dd", linkid, cell);
  464.            
  465.             OnTowerTakeDamage(linkid, cell, teamid_enemy);
  466.         }
  467.    
  468.         return true;
  469.     }
  470.  
  471.     return true;
  472. }
  473.  
  474. //-----------------------------
  475. //-------------------------------------------------
  476. //-----------------------------
  477.  
  478. public OnTowerTakeDamage(linkid, cell, teamid_tower)
  479. {
  480.     if(int_health_towers[cell][teamid_tower] < 0)
  481.         int_health_towers[cell][teamid_tower] = 0;
  482.  
  483.     static
  484.         string[10];
  485.  
  486.     format(string, sizeof(string), "%d/1000", int_health_towers[cell][teamid_tower]);
  487.     UpdateDynamic3DTextLabelText(text3d_health_towers[cell][teamid_tower], COLOR_RED, string);
  488.  
  489.     //-----------------------------
  490.    
  491.     if(int_health_towers[cell][teamid_tower] <= 0)
  492.     {
  493.         new
  494.             teamid = _:!teamid_tower,
  495.             points_bonus = floatround(float(GetGameTimeByLinkID(linkid)) * 0.03125);
  496.            
  497.         ScmToLink(linkid, Color.WHITE, "L'équipe {%x}%s "WHITE"gagne la partie !", GetTeamColorString(teamid), TEAMS[teamid][tName]);
  498.  
  499.         foreach(new i : LinkPlayer[linkid])
  500.         {              
  501.             if(teamid == PLAYERS[i][pTeamDG])
  502.             {
  503.                 new
  504.                     points = 0;
  505.            
  506.                 points += P_TOW[i][pTowDamagesTower] / 50;
  507.                 points += P_TOW[i][pTowBombsExp] * 5;
  508.                 points += floatround(float(P_TOW[i][pTowKills]) * 1.5);
  509.                 points += points_bonus;
  510.                
  511.                 GivePlayerPoints(i, points, true);
  512.             }
  513.            
  514.             else
  515.             {
  516.                 new
  517.                     points = 0;
  518.            
  519.                 points += P_TOW[i][pTowDamagesTower] / 100;
  520.                 points += P_TOW[i][pTowBombsExp] * 5;
  521.                 points += P_TOW[i][pTowKills];
  522.                 points += points_bonus;
  523.                
  524.                 GivePlayerPoints(i, points, false);
  525.             }
  526.         }
  527.        
  528.         EndGame(linkid);
  529.         finish{cell} = true;
  530.     }
  531. }
  532.  
  533. //-----------------------------
  534.  
  535. public Timer_Bomb(linkid, cell)
  536. {
  537.     if(finish{cell})
  538.         return true;
  539.  
  540.     foreach(new i : LinkPlayer[linkid])
  541.     {  
  542.         GTFP(i, "~g~La bombe est apparue au~n~~g~milieu de la map.", 5000, 4);
  543.     }
  544.    
  545.     object_bomb[cell] = CreateDynamicObject(2891, -1054.687622, 1063.608764, 1343.958740, 0.000000, 0.000000, 0.000000, LINKS[linkid][lWorldID], 10, -1, 400.0, 0.0);  
  546.     text3d_bomb[cell] = CreateDynamic3DTextLabel("Pour prendre la bombe :\nAppuie sur N !", Color.AQUA, -1054.687622, 1063.608764, 1343.958740, 250.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, LINKS[linkid][lWorldID], 10, -1, 10.0);
  547.  
  548.     return true;
  549. }
  550.  
  551. /*
  552.  
  553.     888888888888  ,ad8888ba,   I8,        8        ,8I  88888888888  88888888ba  
  554.          88      d8"'    `"8b  `8b       d8b       d8'  88           88      "8b  
  555.          88     d8'        `8b  "8,     ,8"8,     ,8"   88           88      ,8P  
  556.          88     88          88   Y8     8P Y8     8P    88aaaaa      88aaaaaa8P'  
  557.          88     88          88   `8b   d8' `8b   d8'    88"""""      88""""88'    
  558.          88     Y8,        ,8P    `8a a8'   `8a a8'     88           88    `8b    
  559.          88      Y8a.    .a8P      `8a8'     `8a8'      88           88     `8b  
  560.          88       `"Y8888Y"'        `8'       `8'       88888888888  88      `8b  
  561.  
  562. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement