Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [Command("capture")]
- public void CMD_ZoneCapture(Player player)
- {
- if (Fun.GetPlayerGang(player) == -1)
- {
- Fun.SendNotification(player, "You must be in gang to use this command");
- return;
- }
- if (Fun.GetPlayerLevelInGang(player) < 1)
- {
- Fun.SendNotification(player, "Insufficient authority to use this command");
- return;
- }
- foreach (GangZoneVar Zones in ZoneList)
- {
- if(NAPI.ColShape.IsPointWithinColshape(Zones.GZoneCol, player.Position))
- {
- if(Zones.GZoneOwner == Fun.GetPlayerGang(player))
- {
- Fun.SendNotification(player, "The territory is already captured by your gang!");
- return;
- }
- if(Zones.GZoneState == 2)
- {
- Fun.SendNotification(player, "The territory is locked!");
- return;
- }
- if (Zones.GZoneState == 1)
- {
- Fun.SendNotification(player, "The territory is already under attack!");
- return;
- }
- if (Zones.GZoneOwner != 0)
- {
- foreach(Player P in NAPI.Pools.GetAllPlayers())
- {
- if(Fun.GetPlayerGang(P) == Zones.GZoneOwner)
- {
- P.TriggerEvent("StartZoneFlash", Zones.GZoneID);
- Fun.SendNotification(P, $"~y~Gang Attack: {Gangs.GetGangName(Fun.GetPlayerGang(player))} ~w~attempting to capture your territory ~o~{Gangs.GetGangName(Zones.GZoneOwner)}");
- }
- if(Fun.GetPlayerGang(P) == Fun.GetPlayerGang(player))
- {
- Fun.SendNotification(P, $"Your Gang is attempting to capture territory ~o~{Gangs.GetGangName(Zones.GZoneOwner)}");
- }
- }
- Zones.GZoneAttackingGang = Fun.GetPlayerGang(player);
- }
- else
- {
- foreach (Player P in NAPI.Pools.GetAllPlayers())
- {
- if (Fun.GetPlayerGang(P) == Fun.GetPlayerGang(player))
- {
- P.TriggerEvent("StartZoneFlash", Zones.GZoneID);
- if(P != player)
- {
- Fun.SendNotification(P, $"Your Gang is attempting to capture territory ~o~{Gangs.GetGangName(Zones.GZoneOwner)}");
- }
- }
- }
- Zones.GZoneAttackingGang = -1;
- }
- Fun.SendNotification(player, $"Capturing Territory ~o~{Zones.GZoneName}");
- Zones.GZoneTime = 0;
- Zones.GZoneState = 1;
- ZoneCapturing(Zones);
- }
- }
- }
- public static void ZoneCapturing(GangZoneVar zone)
- {
- zone.GZoneTimer = new Timer(obj =>
- {
- NAPI.Task.Run(() =>
- {
- if(zone.GZoneTime < 180)
- {
- zone.GZoneTime++;
- }
- else
- {
- zone.GZoneTimer.Dispose();
- zone.GZoneTime = 0;
- ZoneCaptureFinished(zone);
- }
- });
- }, null, 1000, 1000);
- }
- public static void ZoneCaptureFinished(GangZoneVar zone)
- {
- zone.GZoneState = 2;
- if (zone.GZoneAttackingGang != -1)
- {
- int Zowners = 0;
- int ZAttackers = 0;
- foreach (Player p in NAPI.Pools.GetAllPlayers())
- {
- if (NAPI.ColShape.IsPointWithinColshape(zone.GZoneCol, p.Position))
- {
- if (zone.GZoneOwner != 0)
- {
- if (zone.GZoneOwner == Fun.GetPlayerGang(p))
- {
- Zowners++;
- }
- if (zone.GZoneAttackingGang == Fun.GetPlayerGang(p))
- {
- ZAttackers++;
- }
- }
- }
- }
- foreach (Player p in NAPI.Pools.GetAllPlayers())
- {
- if (Zowners > ZAttackers)
- {
- if (zone.GZoneOwner == Fun.GetPlayerGang(p))
- {
- Fun.SendNotification(p, $"Your gang has successfully defended the territory ~o~{zone.GZoneName}");
- }
- if (zone.GZoneAttackingGang == Fun.GetPlayerGang(p))
- {
- Fun.SendNotification(p, $"Your gang has failed to capture the territory ~o~{zone.GZoneName}");
- }
- }
- else if (ZAttackers > Zowners)
- {
- if (zone.GZoneOwner == Fun.GetPlayerGang(p))
- {
- Fun.SendNotification(p, $"Your gang has failed to defend the territory ~o~{zone.GZoneName}");
- }
- if (zone.GZoneAttackingGang == Fun.GetPlayerGang(p))
- {
- Fun.SendNotification(p, $"Your gang has successfully captured the territory ~o~{zone.GZoneName}");
- zone.GZoneOwner = Fun.GetPlayerGang(p);
- }
- }
- if (NAPI.ColShape.IsPointWithinColshape(zone.GZoneCol, p.Position))
- {
- p.TriggerEvent("ShowPlayerZoneInfo", zone.GZoneName, Gangs.GetGangName(Fun.GetPlayerGang(p)), zone.GZoneState);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement