Advertisement
shourya90

Untitled

Mar 2nd, 2021
657
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.69 KB | None | 0 0
  1. [Command("capture")]
  2.         public void CMD_ZoneCapture(Player player)
  3.         {
  4.             if (Fun.GetPlayerGang(player) == -1)
  5.             {
  6.                 Fun.SendNotification(player, "You must be in gang to use this command");
  7.                 return;
  8.             }
  9.             if (Fun.GetPlayerLevelInGang(player) < 1)
  10.             {
  11.                 Fun.SendNotification(player, "Insufficient authority to use this command");
  12.                 return;
  13.             }
  14.             foreach (GangZoneVar Zones in ZoneList)
  15.             {
  16.                 if(NAPI.ColShape.IsPointWithinColshape(Zones.GZoneCol, player.Position))
  17.                 {
  18.                     if(Zones.GZoneOwner == Fun.GetPlayerGang(player))
  19.                     {
  20.                         Fun.SendNotification(player, "The territory is already captured by your gang!");
  21.                         return;
  22.                     }
  23.                     if(Zones.GZoneState == 2)
  24.                     {
  25.                         Fun.SendNotification(player, "The territory is locked!");
  26.                         return;
  27.                     }
  28.                     if (Zones.GZoneState == 1)
  29.                     {
  30.                         Fun.SendNotification(player, "The territory is already under attack!");
  31.                         return;
  32.                     }
  33.                     if (Zones.GZoneOwner != 0)
  34.                     {
  35.                         foreach(Player P in NAPI.Pools.GetAllPlayers())
  36.                         {
  37.                             if(Fun.GetPlayerGang(P) == Zones.GZoneOwner)
  38.                             {
  39.                                 P.TriggerEvent("StartZoneFlash", Zones.GZoneID);
  40.                                
  41.                                 Fun.SendNotification(P, $"~y~Gang Attack: {Gangs.GetGangName(Fun.GetPlayerGang(player))} ~w~attempting to capture your territory ~o~{Gangs.GetGangName(Zones.GZoneOwner)}");
  42.                             }
  43.                             if(Fun.GetPlayerGang(P) == Fun.GetPlayerGang(player))
  44.                             {
  45.                                 Fun.SendNotification(P, $"Your Gang is attempting to capture territory ~o~{Gangs.GetGangName(Zones.GZoneOwner)}");
  46.                             }
  47.                         }
  48.                         Zones.GZoneAttackingGang = Fun.GetPlayerGang(player);
  49.                     }
  50.                     else
  51.                     {
  52.                         foreach (Player P in NAPI.Pools.GetAllPlayers())
  53.                         {
  54.                             if (Fun.GetPlayerGang(P) == Fun.GetPlayerGang(player))
  55.                             {
  56.                                 P.TriggerEvent("StartZoneFlash", Zones.GZoneID);
  57.                                 if(P != player)
  58.                                 {
  59.                                     Fun.SendNotification(P, $"Your Gang is attempting to capture territory ~o~{Gangs.GetGangName(Zones.GZoneOwner)}");
  60.                                 }
  61.                                
  62.                             }
  63.                         }
  64.                         Zones.GZoneAttackingGang = -1;
  65.                     }
  66.                     Fun.SendNotification(player, $"Capturing Territory ~o~{Zones.GZoneName}");
  67.                     Zones.GZoneTime = 0;
  68.                     Zones.GZoneState = 1;
  69.                     ZoneCapturing(Zones);
  70.                 }
  71.             }
  72.         }
  73.         public static void ZoneCapturing(GangZoneVar zone)
  74.         {
  75.            
  76.             zone.GZoneTimer = new Timer(obj =>
  77.             {
  78.                 NAPI.Task.Run(() =>
  79.                 {
  80.                     if(zone.GZoneTime < 180)
  81.                     {
  82.                         zone.GZoneTime++;
  83.                     }
  84.                     else
  85.                     {
  86.                         zone.GZoneTimer.Dispose();
  87.                         zone.GZoneTime = 0;
  88.                         ZoneCaptureFinished(zone);
  89.                     }
  90.                 });
  91.  
  92.             }, null, 1000, 1000);
  93.         }
  94.         public static void ZoneCaptureFinished(GangZoneVar zone)
  95.         {
  96.             zone.GZoneState = 2;
  97.             if (zone.GZoneAttackingGang != -1)
  98.             {
  99.                 int Zowners = 0;
  100.                 int ZAttackers = 0;
  101.                 foreach (Player p in NAPI.Pools.GetAllPlayers())
  102.                 {
  103.                     if (NAPI.ColShape.IsPointWithinColshape(zone.GZoneCol, p.Position))
  104.                     {
  105.                         if (zone.GZoneOwner != 0)
  106.                         {
  107.                             if (zone.GZoneOwner == Fun.GetPlayerGang(p))
  108.                             {
  109.                                 Zowners++;
  110.                                
  111.                             }
  112.                             if (zone.GZoneAttackingGang == Fun.GetPlayerGang(p))
  113.                             {
  114.                                 ZAttackers++;
  115.                             }
  116.                         }
  117.                     }
  118.  
  119.                 }
  120.                 foreach (Player p in NAPI.Pools.GetAllPlayers())
  121.                 {
  122.                     if (Zowners > ZAttackers)
  123.                     {
  124.                        
  125.  
  126.                         if (zone.GZoneOwner == Fun.GetPlayerGang(p))
  127.                         {
  128.                             Fun.SendNotification(p, $"Your gang has successfully defended the territory ~o~{zone.GZoneName}");
  129.                         }
  130.                         if (zone.GZoneAttackingGang == Fun.GetPlayerGang(p))
  131.                         {
  132.                             Fun.SendNotification(p, $"Your gang has failed to capture the territory ~o~{zone.GZoneName}");
  133.                         }
  134.  
  135.                        
  136.                     }
  137.                     else if (ZAttackers > Zowners)
  138.                     {
  139.                         if (zone.GZoneOwner == Fun.GetPlayerGang(p))
  140.                         {
  141.                             Fun.SendNotification(p, $"Your gang has failed to defend the territory ~o~{zone.GZoneName}");
  142.                         }
  143.                         if (zone.GZoneAttackingGang == Fun.GetPlayerGang(p))
  144.                         {
  145.                             Fun.SendNotification(p, $"Your gang has successfully captured the territory ~o~{zone.GZoneName}");
  146.                             zone.GZoneOwner = Fun.GetPlayerGang(p);
  147.                         }
  148.                     }
  149.                     if (NAPI.ColShape.IsPointWithinColshape(zone.GZoneCol, p.Position))
  150.                     {
  151.                         p.TriggerEvent("ShowPlayerZoneInfo", zone.GZoneName, Gangs.GetGangName(Fun.GetPlayerGang(p)), zone.GZoneState);
  152.                     }
  153.                 }
  154.                        
  155.             }
  156.            
  157.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement