Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- internal class ArrestPed
- {
- internal Ped Ped { get; set; }
- internal bool IsArrested { get; set; }
- private bool _notified;
- private ProcessHost _procHost = new ProcessHost();
- private ProcessHost _procHost2 = new ProcessHost();
- private List<Animations> _cop_mp_arresting = new List<Animations>
- {
- new Animations("mp_arresting", "arrest_on_floor_front_left_a", 8f),
- new Animations("mp_arresting", "arrest_on_floor_front_right_a", 8f)
- };
- private List<Animations> _perp_mp_arresting = new List<Animations>
- {
- new Animations("mp_arresting", "arrest_on_floor_front_left_b", 8f),
- new Animations("mp_arresting", "arrest_on_floor_front_right_b", 8f)
- };
- private Object _cuffs;
- internal ArrestPed(Ped p)
- {
- Ped = p;
- Logger.AddLog("ArrestPed");
- if (!Ped) return;
- _procHost.Start();
- _procHost[StartArrest] = true;
- }
- internal void LetPedGo()
- {
- if (!Ped) return;
- _procHost2.AddProcess(StartUncuff);
- _procHost2.AddProcess(Uncuff);
- _procHost2.Start();
- }
- private void StartUncuff()
- {
- if (Game.LocalPlayer.Character.Position.DistanceTo(Ped.RearPosition) > 0.75f) return;
- _procHost2.SwapProcesses(StartUncuff, Uncuff);
- }
- private void Uncuff()
- {
- Game.LocalPlayer.Character.Position = Ped.RearPosition;
- Game.LocalPlayer.Character.Heading = Ped.Heading;
- if (_cuffs) _cuffs.Delete();
- Game.LocalPlayer.Character.Tasks.PlayAnimation("mp_arresting", "a_uncuff", 4f, AnimationFlags.None);
- Ped.Tasks.PlayAnimation("mp_arresting", "b_uncuff", 4f, AnimationFlags.None);
- this.IsArrested = false;
- ArrestHandler.ArrestList.Remove(this);
- }
- private void StartArrest()
- {
- Logger.AddLog($"Starting arrest; Ped exists: {Ped}");
- if (!Ped) return;
- Ped.BlockPermanentEvents = true;
- Ped.Tasks.ClearImmediately();
- Ped.KeepTasks = true;
- GameFiber.Sleep(0200);
- Logger.AddLog("Arresting ped");
- if (Ped.IsWeaponReadyToShoot)
- {
- // Has firearm
- var length =
- Ped.Tasks.PlayAnimation("random@arrests", "idle_2_hands_up_2h", 8f, AnimationFlags.StayInEndFrame)
- .Length;
- if (Ped.Tasks.PlayAnimation("random@arrests", "idle_2_hands_up_2h", 8f, AnimationFlags.StayInEndFrame)
- .CurrentTime > length / 2 && Ped.IsWeaponReadyToShoot)
- NativeFunction.Natives.SET_PED_DROPS_WEAPON(Ped);
- }
- else
- {
- Logger.AddLog("Ped doesn't have weapon");
- Ped.Tasks.PlayAnimation("random@arrests", "idle_2_hands_up", 8f, AnimationFlags.StayInEndFrame).WaitForCompletion(1500);
- Logger.AddLog("Ped animation complete");
- }
- _procHost[WaitForKeyPress] = true;
- _procHost[StartArrest] = false;
- }
- private void WaitForKeyPress()
- {
- if (!_notified)
- {
- _notified = true;
- Game.DisplayHelp("Hold ~y~E~w~ to arrest the suspect", false);
- }
- if (!Game.IsKeyDown(Keys.E) && Game.LocalPlayer.Character.DistanceTo(Ped.RearPosition) > 0.7f) return;
- _procHost[UndergoArrest] = true;
- _procHost[WaitForKeyPress] = false;
- }
- private void UndergoArrest()
- {
- if (!Game.IsKeyDownRightNow(Keys.E) || Game.LocalPlayer.Character.Position.DistanceTo(Ped.RearPosition) > 0.7f)
- {
- _procHost[WaitForKeyPress] = true;
- _procHost[UndergoArrest] = false;
- return;
- }
- // Checking positioning -- if true == player is to left
- if (Game.LocalPlayer.Character.DistanceTo(Ped.LeftPosition) <
- Game.LocalPlayer.Character.DistanceTo(Ped.RightPosition))
- {
- Ped.Tasks.PlayAnimation(_perp_mp_arresting[0].ScenarioName, _perp_mp_arresting[0].Animation,
- _perp_mp_arresting[0].BlendInSpeed, AnimationFlags.None);
- Game.LocalPlayer.Character.Position = Ped.GetOffsetPosition(new Vector3(-0.5f, -0.84f, 0f));
- Game.LocalPlayer.Character.Heading = Ped.Heading;
- Game.LocalPlayer.Character.Tasks.PlayAnimation(_cop_mp_arresting[0].ScenarioName,
- _cop_mp_arresting[0].Animation,
- _cop_mp_arresting[0].BlendInSpeed, AnimationFlags.None);
- }
- else
- {
- Ped.Tasks.PlayAnimation(_perp_mp_arresting[1].ScenarioName, _perp_mp_arresting[1].Animation,
- _perp_mp_arresting[1].BlendInSpeed, AnimationFlags.None);
- Game.LocalPlayer.Character.Position = Ped.GetOffsetPosition(new Vector3(0.47f, -0.86f, 0f));
- Game.LocalPlayer.Character.Heading = Ped.Heading;
- Game.LocalPlayer.Character.Tasks.PlayAnimation(_cop_mp_arresting[1].ScenarioName,
- _cop_mp_arresting[1].Animation,
- _cop_mp_arresting[1].BlendInSpeed, AnimationFlags.None).WaitForCompletion();
- }
- Ped.Tasks.PlayAnimation("mp_arresting", "idle", 8f,
- AnimationFlags.Loop | AnimationFlags.UpperBodyOnly);
- NativeFunction.Natives.SET_ENABLE_HANDCUFFS(Ped, true);
- _cuffs = new Object(new Model("prop_cs_cuffs_01"), Ped.Position);
- _cuffs.AttachTo(Ped, 60309, Vector3.Zero, Rotator.Zero);
- Ped.Tasks.FollowToOffsetFromEntity(Game.LocalPlayer.Character, new Vector3(2f, 2f, 0f));
- this.IsArrested = true;
- ArrestHandler.ArrestList.Add(this);
- _procHost[UndergoArrest] = false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement