Advertisement
schwim

Assassination2.cs

May 19th, 2018
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.61 KB | None | 0 0
  1. using CitizenFX.Core;
  2. using CitizenFX.Core.Native;
  3. using CitizenFX.Core.UI;
  4. using Freeroam.Utils;
  5. using System;
  6. using System.Threading.Tasks;
  7.  
  8. namespace Freeroam.Missions
  9. {
  10.     internal class Target
  11.     {
  12.         public Ped targetPed;
  13.         public Ped[] bodyguards;
  14.  
  15.         public Target(Ped targetPed, Ped[] bodyguards)
  16.         {
  17.             this.targetPed = targetPed;
  18.             this.bodyguards = bodyguards;
  19.         }
  20.     }
  21.  
  22.     class Assassination2 : IMission
  23.     {
  24.         private static Vector3[] targetSpawns = new Vector3[]
  25.         {
  26.             new Vector3(-1502f, 137f, 55f)
  27.         };
  28.  
  29.         private Target[] targets = new Target[1];
  30.         private bool enableTick = false;
  31.  
  32.         public async void Start()
  33.         {
  34.             Random random = new Random();
  35.             for (int i = 0; i < targets.Length; i++)
  36.             {
  37.                 Ped targetPed = await Util.CreatePed(PedHash.Business01AMY, targetSpawns[i]);
  38.                 targetPed.Task.StartScenario("WORLD_HUMAN_AA_SMOKE", targetPed.Position);
  39.                 Ped[] bodyguards = await SpawnBodyguards(targetPed, random.Next(10, 15));
  40.  
  41.                 Function.Call(Hash.FLASH_MINIMAP_DISPLAY);
  42.  
  43.                 Blip blip = targetPed.AttachBlip();
  44.                 blip.Sprite = BlipSprite.Enemy;
  45.                 blip.Color = BlipColor.Red;
  46.                 blip.Name = Strings.MISSIONS_ASSASSINATION2_BLIP;
  47.                 blip.Scale = 0.8f;
  48.  
  49.                 targets[i] = new Target(targetPed, bodyguards);
  50.             }
  51.  
  52.             Util.DisplayHelpText(Strings.MISSIONS_ASSASSINATION2_INFO);
  53.             Screen.ShowSubtitle(Strings.MISSIONS_ASSASSINATION2_START, 15000);
  54.             enableTick = true;
  55.         }
  56.  
  57.         public void Stop(bool success)
  58.         {
  59.             if (!success)
  60.             {
  61.                 foreach (Target target in targets)
  62.                 {
  63.                     if (target != null)
  64.                     {
  65.                         DespawnTargetSquad(target);
  66.                     }
  67.                 }
  68.             }
  69.             else
  70.             {
  71.                 Screen.ShowNotification(Strings.MISSIONS_ASSASSINATION2_ALLTARGETSKILLED);
  72.                 BaseScript.TriggerEvent(Events.MONEY_ADD, 5000);
  73.                 BaseScript.TriggerEvent(Events.XP_ADD, 30);
  74.             }
  75.         }
  76.  
  77.         public async Task Tick()
  78.         {
  79.             if (enableTick)
  80.             {
  81.                 Ped playerPed = Game.PlayerPed;
  82.  
  83.                 if (playerPed.IsDead)
  84.                 {
  85.                     BaseScript.TriggerEvent(Events.MISSION_STOP, false);
  86.                     enableTick = false;
  87.                 }
  88.                 else
  89.                 {
  90.                     int livingTargets = 0;
  91.                     for (int i = targets.Length - 1; i > -1; i--)
  92.                     {
  93.                         if (targets[i] != null)
  94.                         {
  95.                             if (!targets[i].targetPed.IsDead) livingTargets++;
  96.                             else
  97.                             {
  98.                                 Screen.ShowNotification(Strings.MISSIONS_ASSASSINATION2_TARGETKILLED);
  99.  
  100.                                 Entity killer = targets[i].targetPed.GetKiller();
  101.  
  102.                                 if (killer == playerPed)
  103.                                 {
  104.                                     if (Game.Player.WantedLevel < 3) Game.Player.WantedLevel = 3;
  105.                                 }
  106.  
  107.                                 DespawnTargetSquad(targets[i]);
  108.                                 targets[i] = null;
  109.                             }
  110.                         }
  111.                     }
  112.  
  113.                     if (livingTargets == 0) BaseScript.TriggerEvent(Events.MISSION_STOP, true);
  114.                 }
  115.             }
  116.  
  117.             await Task.FromResult(0);
  118.         }
  119.  
  120.         private async Task<Ped[]> SpawnBodyguards(Ped targetPed, int amount)
  121.         {
  122.             PedGroup group = new PedGroup();
  123.             group.Add(targetPed, true);
  124.             group.FormationType = FormationType.Default;
  125.             group.SeparationRange = 1f;
  126.  
  127.             RelationshipGroup relationship = World.AddRelationshipGroup("_ASSASSIN_TARGETS");
  128.             relationship.SetRelationshipBetweenGroups(new RelationshipGroup(Util.GetHashKey("COP")), Relationship.Respect, true);
  129.             relationship.SetRelationshipBetweenGroups(new RelationshipGroup(Util.GetHashKey("SECURITY_GUARD")), Relationship.Respect, true);
  130.             targetPed.RelationshipGroup = relationship;
  131.  
  132.             Random random = new Random();
  133.             Ped[] bodyguards = new Ped[amount];
  134.             for (int i = 0; i < amount; i++)
  135.             {
  136.                 float x = Util.GetRandomFloat(random, -2, 2);
  137.                 float y = Util.GetRandomFloat(random, -2, 2);
  138.                 Vector3 spawnPos = targetPed.GetOffsetPosition(new Vector3(x, y, 0f));
  139.                 Ped bodyguard = await Util.CreatePed(PedHash.FibOffice01SMM, spawnPos);
  140.                 bodyguard.Armor = 300;
  141.                 bodyguard.Weapons.Give(WeaponHash.CarbineRifle, int.MaxValue, true, true);
  142.  
  143.                 bodyguard.RelationshipGroup = new RelationshipGroup(Util.GetHashKey("SECURITY_GUARD"));
  144.                 group.Add(bodyguard, false);
  145.  
  146.                 bodyguards[i] = bodyguard;
  147.             }
  148.  
  149.             return bodyguards;
  150.         }
  151.  
  152.         private void DespawnTargetSquad(Target target)
  153.         {
  154.             target.targetPed.AttachedBlip.Delete();
  155.             target.targetPed.MarkAsNoLongerNeeded();
  156.             foreach (Ped bodyguard in target.bodyguards) bodyguard.MarkAsNoLongerNeeded();
  157.         }
  158.     }
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement