Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
628
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.20 KB | None | 0 0
  1.     internal class ArrestPed
  2.     {
  3.         internal Ped Ped { get; set; }
  4.         internal bool IsArrested { get; set; }
  5.         private bool _notified;
  6.         private ProcessHost _procHost = new ProcessHost();
  7.         private ProcessHost _procHost2 = new ProcessHost();
  8.         private List<Animations> _cop_mp_arresting = new List<Animations>
  9.                     {
  10.                         new Animations("mp_arresting", "arrest_on_floor_front_left_a", 8f),
  11.                         new Animations("mp_arresting", "arrest_on_floor_front_right_a", 8f)
  12.                     };
  13.  
  14.         private List<Animations> _perp_mp_arresting = new List<Animations>
  15.                     {
  16.                         new Animations("mp_arresting", "arrest_on_floor_front_left_b", 8f),
  17.                         new Animations("mp_arresting", "arrest_on_floor_front_right_b", 8f)
  18.                     };
  19.  
  20.         private Object _cuffs;
  21.  
  22.         internal ArrestPed(Ped p)
  23.         {
  24.             Ped = p;
  25.             Logger.AddLog("ArrestPed");
  26.             if (!Ped) return;
  27.  
  28.             _procHost.Start();
  29.             _procHost[StartArrest] = true;
  30.         }
  31.  
  32.         internal void LetPedGo()
  33.         {
  34.             if (!Ped) return;
  35.  
  36.             _procHost2.AddProcess(StartUncuff);
  37.             _procHost2.AddProcess(Uncuff);
  38.             _procHost2.Start();
  39.         }
  40.  
  41.         private void StartUncuff()
  42.         {
  43.             if (Game.LocalPlayer.Character.Position.DistanceTo(Ped.RearPosition) > 0.75f) return;
  44.             _procHost2.SwapProcesses(StartUncuff, Uncuff);
  45.         }
  46.  
  47.         private void Uncuff()
  48.         {
  49.             Game.LocalPlayer.Character.Position = Ped.RearPosition;
  50.             Game.LocalPlayer.Character.Heading = Ped.Heading;
  51.             if (_cuffs) _cuffs.Delete();
  52.             Game.LocalPlayer.Character.Tasks.PlayAnimation("mp_arresting", "a_uncuff", 4f, AnimationFlags.None);
  53.             Ped.Tasks.PlayAnimation("mp_arresting", "b_uncuff", 4f, AnimationFlags.None);
  54.             this.IsArrested = false;
  55.             ArrestHandler.ArrestList.Remove(this);
  56.         }
  57.  
  58.         private void StartArrest()
  59.         {
  60.             Logger.AddLog($"Starting arrest; Ped exists: {Ped}");
  61.             if (!Ped) return;
  62.  
  63.             Ped.BlockPermanentEvents = true;
  64.             Ped.Tasks.ClearImmediately();
  65.             Ped.KeepTasks = true;
  66.             GameFiber.Sleep(0200);
  67.             Logger.AddLog("Arresting ped");
  68.             if (Ped.IsWeaponReadyToShoot)
  69.             {
  70.                 // Has firearm
  71.                 var length =
  72.                     Ped.Tasks.PlayAnimation("random@arrests", "idle_2_hands_up_2h", 8f, AnimationFlags.StayInEndFrame)
  73.                         .Length;
  74.                 if (Ped.Tasks.PlayAnimation("random@arrests", "idle_2_hands_up_2h", 8f, AnimationFlags.StayInEndFrame)
  75.                         .CurrentTime > length / 2 && Ped.IsWeaponReadyToShoot)
  76.                     NativeFunction.Natives.SET_PED_DROPS_WEAPON(Ped);
  77.             }
  78.             else
  79.             {
  80.                 Logger.AddLog("Ped doesn't have weapon");
  81.                 Ped.Tasks.PlayAnimation("random@arrests", "idle_2_hands_up", 8f, AnimationFlags.StayInEndFrame).WaitForCompletion(1500);
  82.                 Logger.AddLog("Ped animation complete");
  83.             }
  84.             _procHost[WaitForKeyPress] = true;
  85.             _procHost[StartArrest] = false;
  86.         }
  87.  
  88.         private void WaitForKeyPress()
  89.         {
  90.             if (!_notified)
  91.             {
  92.                 _notified = true;
  93.                 Game.DisplayHelp("Hold ~y~E~w~ to arrest the suspect", false);
  94.             }
  95.  
  96.             if (!Game.IsKeyDown(Keys.E) && Game.LocalPlayer.Character.DistanceTo(Ped.RearPosition) > 0.7f) return;
  97.             _procHost[UndergoArrest] = true;
  98.             _procHost[WaitForKeyPress] = false;
  99.         }
  100.  
  101.         private void UndergoArrest()
  102.         {
  103.             if (!Game.IsKeyDownRightNow(Keys.E) || Game.LocalPlayer.Character.Position.DistanceTo(Ped.RearPosition) > 0.7f)
  104.             {
  105.                 _procHost[WaitForKeyPress] = true;
  106.                 _procHost[UndergoArrest] = false;
  107.                 return;
  108.             }
  109.  
  110.             // Checking positioning -- if true == player is to left
  111.             if (Game.LocalPlayer.Character.DistanceTo(Ped.LeftPosition) <
  112.                 Game.LocalPlayer.Character.DistanceTo(Ped.RightPosition))
  113.             {
  114.                 Ped.Tasks.PlayAnimation(_perp_mp_arresting[0].ScenarioName, _perp_mp_arresting[0].Animation,
  115.                     _perp_mp_arresting[0].BlendInSpeed, AnimationFlags.None);
  116.                 Game.LocalPlayer.Character.Position = Ped.GetOffsetPosition(new Vector3(-0.5f, -0.84f, 0f));
  117.                 Game.LocalPlayer.Character.Heading = Ped.Heading;
  118.                 Game.LocalPlayer.Character.Tasks.PlayAnimation(_cop_mp_arresting[0].ScenarioName,
  119.                     _cop_mp_arresting[0].Animation,
  120.                     _cop_mp_arresting[0].BlendInSpeed, AnimationFlags.None);
  121.             }
  122.             else
  123.             {
  124.                 Ped.Tasks.PlayAnimation(_perp_mp_arresting[1].ScenarioName, _perp_mp_arresting[1].Animation,
  125.                     _perp_mp_arresting[1].BlendInSpeed, AnimationFlags.None);
  126.                 Game.LocalPlayer.Character.Position = Ped.GetOffsetPosition(new Vector3(0.47f, -0.86f, 0f));
  127.                 Game.LocalPlayer.Character.Heading = Ped.Heading;
  128.                 Game.LocalPlayer.Character.Tasks.PlayAnimation(_cop_mp_arresting[1].ScenarioName,
  129.                     _cop_mp_arresting[1].Animation,
  130.                     _cop_mp_arresting[1].BlendInSpeed, AnimationFlags.None).WaitForCompletion();
  131.             }
  132.  
  133.             Ped.Tasks.PlayAnimation("mp_arresting", "idle", 8f,
  134.                 AnimationFlags.Loop | AnimationFlags.UpperBodyOnly);
  135.             NativeFunction.Natives.SET_ENABLE_HANDCUFFS(Ped, true);
  136.             _cuffs = new Object(new Model("prop_cs_cuffs_01"), Ped.Position);
  137.             _cuffs.AttachTo(Ped, 60309, Vector3.Zero, Rotator.Zero);
  138.             Ped.Tasks.FollowToOffsetFromEntity(Game.LocalPlayer.Character, new Vector3(2f, 2f, 0f));
  139.             this.IsArrested = true;
  140.             ArrestHandler.ArrestList.Add(this);
  141.             _procHost[UndergoArrest] = false;
  142.         }
  143.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement