//-----------------------------------------------------------------------
//
// Original script by HippieCommunist.
// Heavily refactored by MulleDK19.
//
//-----------------------------------------------------------------------
namespace Ticket
{
using System;
using System.Windows.Forms;
using GTA;
///
/// A script that makes police officers issue tickets to the player, when the player only has a wanted level of 1.
///
public class Ticket : Script
{
#region Private Fields
///
/// The speed of the player.
///
private float lastPlayerSpeed;
///
/// The player's wanted level.
///
private int wantedLevel;
///
/// Whether the player is currently surrendering.
///
private bool isSurrendering = false;
#endregion
#region Constructors
///
/// Initializes a new instance of the class.
///
public Ticket()
{
this.Tick += new EventHandler(this.Ticket_Tick);
Wait(0);
}
#endregion
#region Properties
///
/// Gets the last player speed.
///
public float LastPlayerSpeed
{
get { return this.lastPlayerSpeed; }
private set { this.lastPlayerSpeed = value; }
}
///
/// Gets the wanted level.
///
public int WantedLevel
{
get { return this.wantedLevel; }
private set { this.wantedLevel = value; }
}
///
/// Gets a value indicating whether the player is currently surrendering.
///
///
/// true if the player is currently surrendering is surrendering; otherwise, false.
///
public bool IsSurrendering
{
get { return this.isSurrendering; }
private set { this.isSurrendering = value; }
}
#endregion
#region Private Methods
///
/// Gets a random integer within the specified range.
///
/// The minimum value.
/// The maximum value.
/// A random number between and .
private int GetRandomInteger(int minimum, int maximum)
{
Random random = new Random();
return random.Next(minimum, maximum + 1);
}
///
/// Handles the script's Tick event.
///
/// The source of the event.
/// The instance containing the event data.
private void Ticket_Tick(object sender, EventArgs e)
{
Wait(0);
if (Player.WantedLevel == 1)
{
AnimationSet ambientAnimations = new AnimationSet("amb@newspaper_hold");
AnimationSet nikoGestures = new AnimationSet("gestures@niko");
AnimationFlags animationFlags = AnimationFlags.Unknown12 | AnimationFlags.Unknown11 | AnimationFlags.Unknown09;
int ticketAmount = this.GetRandomInteger(5000, 14000);
float playerVelocityX = Player.Character.Velocity.X;
float playerVelocityY = Player.Character.Velocity.Y;
playerVelocityX = playerVelocityX * playerVelocityX;
playerVelocityY = playerVelocityY * playerVelocityY;
if (Player.Character.isSittingInVehicle() && !Player.Character.isDead)
{
Vehicle playerVehicle = Player.Character.CurrentVehicle;
Wait(0);
if (playerVehicle.Exists())
{
this.LastPlayerSpeed = playerVehicle.Speed;
}
}
GTA.Ped[] pedArray = GTA.World.GetPeds(Player.Character.Position.Around(2.0f), 1.7f, 2);
foreach (GTA.Ped ped in pedArray)
{
if (this.IsSurrendering == true ||
playerVelocityX > 0.001F ||
playerVelocityY > 0.001F ||
this.LastPlayerSpeed > 2.0F ||
!ped.Exists() ||
(Player.Money < 1000) ||
GTA.Native.Function.Call("IS_CHAR_GETTING_UP", ped) ||
ped.isSittingInVehicle() ||
GTA.Native.Function.Call("IS_GROUP_MEMBER", ped, Player.Group) || (!ped.isAliveAndWell) ||
ped == Player.Character || ped.RelationshipGroup == RelationshipGroup.Player || ped.isRagdoll ||
(((uint)ped.Model.Hash != 0xF5148AB2) &&
((uint)ped.Model.Hash != 0xE9EC3678) &&
((uint)ped.Model.Hash != 0xFAAD5B99) &&
((uint)ped.Model.Hash != 0xE9EC3678) &&
((uint)ped.Model.Hash != 0xC41C88BE) &&
((uint)ped.Model.Hash != 0xC46CBC16)))
{
continue;
}
Group playerGroup;
playerGroup = Player.Group;
Wait(0);
GTA.Native.Function.Call("REQUEST_MODEL", "amb_clipboard");
ped.Task.AimAt(Player.Character.Position, 1500);
Game.DisplayText("LCPD: Freeze!");
GTA.Native.Function.Call("SWITCH_PED_TO_ANIMATED", Player.Character, 1);
Player.Character.Task.ClearAll();
Player.Character.FreezePosition = true;
GTA.Native.Function.Call("SET_CAMERA_CONTROLS_DISABLED_WITH_PLAYER_CONTROLS", 0);
Player.CanControlCharacter = false;
ped.Health += 50;
GTA.Native.Function.Call("CANCEL_OVERRIDE_RESTART");
Player.Character.Task.ClearAll();
Player.Character.FreezePosition = false;
GTA.Native.Function.Call("SET_MAX_WANTED_LEVEL", 0);
if (ped.isSittingInVehicle())
{
Wait(2500);
}
GTA.Object clipboard = World.CreateObject(Model.FromString("amb_clipboard"), Player.Character.Position.Around(9.0f));
Vector3 sx = Player.Character.GetOffsetPosition(new Vector3(0.0f, 0.5f, 0.0f));
GTA.Native.Function.Call("CLEAR_WANTED_LEVEL", Player);
Player.Character.Task.TurnTo(ped);
if (Player.Character.isSittingInVehicle())
{
Wait(1500);
}
GTA.Native.Function.Call("CLEAR_WANTED_LEVEL", Player);
GTA.Native.Function.Call("SET_POLICE_IGNORE_PLAYER", Player, 1);
Player.Character.Task.TurnTo(ped);
Wait(1000);
if (Player.Character.Weapons.CurrentType != 0)
{
Game.DisplayText("LCPD: Suspect is Armed, Confiscating Weapon");
ticketAmount += 3500;
Player.Character.Weapons.Current.Ammo -= Player.Character.Weapons.Current.Ammo;
}
GTA.Native.Function.Call("SET_CURRENT_CHAR_WEAPON", Player.Character, 0, 1);
GTA.Native.Function.Call("SET_CURRENT_CHAR_WEAPON", ped, 0, 1);
GTA.Native.Function.Call("SWITCH_PED_TO_ANIMATED", ped, 1);
ped.Task.ClearAll();
Player.Character.Task.TurnTo(ped);
ped.DuckWhenAimedAtByGroupMember = false;
ped.ChangeRelationship(RelationshipGroup.Player, Relationship.Companion);
playerGroup.AddMember(ped);
Player.Character.Task.TurnTo(ped);
Wait(700);
GTA.Native.Function.Call("SET_CURRENT_CHAR_WEAPON", ped, 0, 1);
GTA.Native.Function.Call("SWITCH_PED_TO_ANIMATED", Player.Character, 0);
GTA.Native.Function.Call("SET_CURRENT_CHAR_WEAPON", ped, 0, 1);
GTA.Native.Function.Call("SET_EVERYONE_IGNORE_PLAYER", Player, 1);
Wait(10);
GTA.Native.Function.Call("SET_CURRENT_CHAR_WEAPON", ped, 0, 1);
GTA.Native.Function.Call("SWITCH_PED_TO_ANIMATED", ped, 1);
int waitTime = Convert.ToInt32(Math.Round((ped.Position.DistanceTo(Player.Character.Position) * 70.0f), 0));
Wait(waitTime);
GTA.Native.Function.Call("SWITCH_PED_TO_ANIMATED", ped, 1);
GTA.Native.Function.Call("CLEAR_WANTED_LEVEL", Player);
Player.Character.Task.TurnTo(ped);
ped.Task.TurnTo(Player.Character);
if (clipboard != null && clipboard.Exists())
{
GTA.Native.Function.Call("ATTACH_OBJECT_TO_PED", clipboard, ped, 1232, -0.025f, 0.085f, -0.021f, 0.0f, 0.0f, -0.5f, 0);
}
Player.Character.Task.PlayAnimation(nikoGestures, "how", 6.4F);
ped.Task.PlayAnimation(ambientAnimations, "walk_hold", 6.4F, animationFlags);
Wait(500);
Player.Character.Task.ClearAll();
ped.Task.TurnTo(Player.Character);
Wait(3500);
ped.SayAmbientSpeech("INTIMIDATE");
playerGroup.RemoveMember(ped);
ped.Task.ClearAll();
if (clipboard != null && clipboard.Exists())
{
clipboard.Delete();
}
Player.CanControlCharacter = true;
GTA.Native.Function.Call("SET_CAMERA_CONTROLS_DISABLED_WITH_PLAYER_CONTROLS", 1);
GTA.Native.Function.Call("SET_POLICE_IGNORE_PLAYER", Player, 0);
GTA.Native.Function.Call("SET_MAX_WANTED_LEVEL", 6);
GTA.Native.Function.Call("SET_EVERYONE_IGNORE_PLAYER", Player, 0);
if (Player.Money > ticketAmount)
{
Player.Money -= ticketAmount;
}
else
{
ticketAmount = Player.Money;
}
ped.Money += ticketAmount;
Player.Money -= ticketAmount;
Game.DisplayText("LCPD: your were fined with: " + ticketAmount + "$");
ped.RelationshipGroup = RelationshipGroup.Cop;
GTA.Native.Function.Call("CANCEL_OVERRIDE_RESTART");
Player.Character.FreezePosition = false;
this.IsSurrendering = false;
if (ped.Exists())
{
GTA.Native.Function.Call("SET_CHAR_AS_MISSION_CHAR", ped, 0);
if (ped.isInGroup)
{
playerGroup.RemoveMember(ped);
}
ped.NoLongerNeeded();
}
}
if (this.IsSurrendering && !GTA.Native.Function.Call("IS_CHAR_PLAYING_ANIM", Player.Character, "ped", "handsup"))
{
new AnimationSet("ped");
Wait(0);
if ((isKeyPressed(Settings.GetValueKey("Key", Keys.F8)) && !GTA.Native.Function.Call("PLAYER_HAS_GREYED_OUT_STARS", Player)) && !GTA.Native.Function.Call("IS_CHAR_PLAYING_ANIM", Player.Character, "ped", "handsup"))
{
Player.Character.Task.PlayAnimation(nikoGestures, "handsup", 15.4F);
}
Wait(600);
if (!GTA.Native.Function.Call("IS_CHAR_PLAYING_ANIM", Player.Character, "ped", "handsup"))
{
Player.WantedLevel = this.WantedLevel;
this.IsSurrendering = false;
}
}
}
else if ((Player.WantedLevel >= 1) && Player.Character.isAlive && !Player.Character.isRagdoll)
{
if (isKeyPressed(Settings.GetValueKey("Key", Keys.F8)) && !GTA.Native.Function.Call("IS_PLAYER_BEING_ARRESTED", Player) && !GTA.Native.Function.Call("PLAYER_HAS_GREYED_OUT_STARS", Player))
{
this.IsSurrendering = true;
this.WantedLevel = Player.WantedLevel;
AnimationSet animz = new AnimationSet("ped");
if (!GTA.Native.Function.Call("IS_CHAR_PLAYING_ANIM", Player.Character, "ped", "handsup"))
{
Player.Character.Task.PlayAnimation(animz, "handsup", 15.4F);
}
Player.WantedLevel = 1;
Player.Character.Weapons.Current.Ammo = 0;
Player.Character.DropCurrentWeapon();
GTA.Native.Function.Call("SET_CURRENT_CHAR_WEAPON", Player.Character, 0, 1);
Wait(100);
if (GTA.Native.Function.Call("IS_CHAR_PLAYING_ANIM", Player.Character, "ped", "handsup"))
{
Wait(0);
}
else
{
Wait(0);
Player.WantedLevel = this.WantedLevel;
this.IsSurrendering = false;
}
}
}
}
#endregion
}
}