Advertisement
MulleDK19

Refactoring of HippieCommunist's Ticket script

Jul 10th, 2011
470
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 14.37 KB | None | 0 0
  1. //-----------------------------------------------------------------------
  2. // <copyright file="Ticket.cs" company="HippieCommunist">
  3. //     Original script by HippieCommunist.
  4. //     Heavily refactored by MulleDK19.
  5. // </copyright>
  6. //-----------------------------------------------------------------------
  7.  
  8. namespace Ticket
  9. {
  10.     using System;
  11.     using System.Windows.Forms;
  12.     using GTA;
  13.  
  14.     /// <summary>
  15.     /// A script that makes police officers issue tickets to the player, when the player only has a wanted level of 1.
  16.     /// </summary>
  17.     public class Ticket : Script
  18.     {
  19.         #region Private Fields
  20.         /// <summary>
  21.         /// The speed of the player.
  22.         /// </summary>
  23.         private float lastPlayerSpeed;
  24.  
  25.         /// <summary>
  26.         /// The player's wanted level.
  27.         /// </summary>
  28.         private int wantedLevel;
  29.  
  30.         /// <summary>
  31.         /// Whether the player is currently surrendering.
  32.         /// </summary>
  33.         private bool isSurrendering = false;
  34.         #endregion
  35.  
  36.         #region Constructors
  37.         /// <summary>
  38.         /// Initializes a new instance of the <see cref="Ticket"/> class.
  39.         /// </summary>
  40.         public Ticket()
  41.         {
  42.             this.Tick += new EventHandler(this.Ticket_Tick);
  43.             Wait(0);
  44.         }
  45.         #endregion
  46.  
  47.         #region Properties
  48.         /// <summary>
  49.         /// Gets the last player speed.
  50.         /// </summary>
  51.         public float LastPlayerSpeed
  52.         {
  53.             get { return this.lastPlayerSpeed; }
  54.             private set { this.lastPlayerSpeed = value; }
  55.         }
  56.  
  57.         /// <summary>
  58.         /// Gets the wanted level.
  59.         /// </summary>
  60.         public int WantedLevel
  61.         {
  62.             get { return this.wantedLevel; }
  63.             private set { this.wantedLevel = value; }
  64.         }
  65.  
  66.         /// <summary>
  67.         /// Gets a value indicating whether the player is currently surrendering.
  68.         /// </summary>
  69.         /// <value>
  70.         ///     <c>true</c> if the player is currently surrendering is surrendering; otherwise, <c>false</c>.
  71.         /// </value>
  72.         public bool IsSurrendering
  73.         {
  74.             get { return this.isSurrendering; }
  75.             private set { this.isSurrendering = value; }
  76.         }
  77.         #endregion
  78.  
  79.         #region Private Methods
  80.         /// <summary>
  81.         /// Gets a random integer within the specified range.
  82.         /// </summary>
  83.         /// <param name="minimum">The minimum value.</param>
  84.         /// <param name="maximum">The maximum value.</param>
  85.         /// <returns>A random number between <paramref name="minimum"/> and <paramref name="maximum"/>.</returns>
  86.         private int GetRandomInteger(int minimum, int maximum)
  87.         {
  88.             Random random = new Random();
  89.             return random.Next(minimum, maximum + 1);
  90.         }
  91.  
  92.         /// <summary>
  93.         /// Handles the script's Tick event.
  94.         /// </summary>
  95.         /// <param name="sender">The source of the event.</param>
  96.         /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
  97.         private void Ticket_Tick(object sender, EventArgs e)
  98.         {
  99.             Wait(0);
  100.  
  101.             if (Player.WantedLevel == 1)
  102.             {
  103.                 AnimationSet ambientAnimations = new AnimationSet("amb@newspaper_hold");
  104.                 AnimationSet nikoGestures = new AnimationSet("gestures@niko");
  105.                 AnimationFlags animationFlags = AnimationFlags.Unknown12 | AnimationFlags.Unknown11 | AnimationFlags.Unknown09;
  106.  
  107.                 int ticketAmount = this.GetRandomInteger(5000, 14000);
  108.                 float playerVelocityX = Player.Character.Velocity.X;
  109.                 float playerVelocityY = Player.Character.Velocity.Y;
  110.                 playerVelocityX = playerVelocityX * playerVelocityX;
  111.                 playerVelocityY = playerVelocityY * playerVelocityY;
  112.                 if (Player.Character.isSittingInVehicle() && !Player.Character.isDead)
  113.                 {
  114.                     Vehicle playerVehicle = Player.Character.CurrentVehicle;
  115.                     Wait(0);
  116.                     if (playerVehicle.Exists())
  117.                     {
  118.                         this.LastPlayerSpeed = playerVehicle.Speed;
  119.                     }
  120.                 }
  121.  
  122.                 GTA.Ped[] pedArray = GTA.World.GetPeds(Player.Character.Position.Around(2.0f), 1.7f, 2);
  123.  
  124.                 foreach (GTA.Ped ped in pedArray)
  125.                 {
  126.                     if (this.IsSurrendering == true ||
  127.                         playerVelocityX > 0.001F ||
  128.                         playerVelocityY > 0.001F ||
  129.                         this.LastPlayerSpeed > 2.0F ||
  130.                         !ped.Exists() ||
  131.                         (Player.Money < 1000) ||
  132.                         GTA.Native.Function.Call<bool>("IS_CHAR_GETTING_UP", ped) ||
  133.                         ped.isSittingInVehicle() ||
  134.                         GTA.Native.Function.Call<bool>("IS_GROUP_MEMBER", ped, Player.Group) || (!ped.isAliveAndWell) ||
  135.                         ped == Player.Character || ped.RelationshipGroup == RelationshipGroup.Player || ped.isRagdoll ||
  136.                         (((uint)ped.Model.Hash != 0xF5148AB2) &&
  137.                         ((uint)ped.Model.Hash != 0xE9EC3678) &&
  138.                         ((uint)ped.Model.Hash != 0xFAAD5B99) &&
  139.                         ((uint)ped.Model.Hash != 0xE9EC3678) &&
  140.                         ((uint)ped.Model.Hash != 0xC41C88BE) &&
  141.                         ((uint)ped.Model.Hash != 0xC46CBC16)))
  142.                     {
  143.                         continue;
  144.                     }
  145.  
  146.                     Group playerGroup;
  147.                     playerGroup = Player.Group;
  148.                     Wait(0);
  149.  
  150.                     GTA.Native.Function.Call("REQUEST_MODEL", "amb_clipboard");
  151.                     ped.Task.AimAt(Player.Character.Position, 1500);
  152.                     Game.DisplayText("LCPD: Freeze!");
  153.  
  154.                     GTA.Native.Function.Call("SWITCH_PED_TO_ANIMATED", Player.Character, 1);
  155.  
  156.                     Player.Character.Task.ClearAll();
  157.                     Player.Character.FreezePosition = true;
  158.                     GTA.Native.Function.Call("SET_CAMERA_CONTROLS_DISABLED_WITH_PLAYER_CONTROLS", 0);
  159.                     Player.CanControlCharacter = false;
  160.                     ped.Health += 50;
  161.                     GTA.Native.Function.Call("CANCEL_OVERRIDE_RESTART");
  162.                     Player.Character.Task.ClearAll();
  163.                     Player.Character.FreezePosition = false;
  164.  
  165.                     GTA.Native.Function.Call("SET_MAX_WANTED_LEVEL", 0);
  166.  
  167.                     if (ped.isSittingInVehicle())
  168.                     {
  169.                         Wait(2500);
  170.                     }
  171.  
  172.                     GTA.Object clipboard = World.CreateObject(Model.FromString("amb_clipboard"), Player.Character.Position.Around(9.0f));
  173.  
  174.                     Vector3 sx = Player.Character.GetOffsetPosition(new Vector3(0.0f, 0.5f, 0.0f));
  175.                     GTA.Native.Function.Call("CLEAR_WANTED_LEVEL", Player);
  176.                     Player.Character.Task.TurnTo(ped);
  177.  
  178.                     if (Player.Character.isSittingInVehicle())
  179.                     {
  180.                         Wait(1500);
  181.                     }
  182.  
  183.                     GTA.Native.Function.Call("CLEAR_WANTED_LEVEL", Player);
  184.                     GTA.Native.Function.Call("SET_POLICE_IGNORE_PLAYER", Player, 1);
  185.                     Player.Character.Task.TurnTo(ped);
  186.                     Wait(1000);
  187.  
  188.                     if (Player.Character.Weapons.CurrentType != 0)
  189.                     {
  190.                         Game.DisplayText("LCPD: Suspect is Armed, Confiscating Weapon");
  191.                         ticketAmount += 3500;
  192.                         Player.Character.Weapons.Current.Ammo -= Player.Character.Weapons.Current.Ammo;
  193.                     }
  194.  
  195.                     GTA.Native.Function.Call("SET_CURRENT_CHAR_WEAPON", Player.Character, 0, 1);
  196.                     GTA.Native.Function.Call("SET_CURRENT_CHAR_WEAPON", ped, 0, 1);
  197.                     GTA.Native.Function.Call("SWITCH_PED_TO_ANIMATED", ped, 1);
  198.                     ped.Task.ClearAll();
  199.                     Player.Character.Task.TurnTo(ped);
  200.                     ped.DuckWhenAimedAtByGroupMember = false;
  201.                     ped.ChangeRelationship(RelationshipGroup.Player, Relationship.Companion);
  202.                     playerGroup.AddMember(ped);
  203.  
  204.                     Player.Character.Task.TurnTo(ped);
  205.                     Wait(700);
  206.                     GTA.Native.Function.Call("SET_CURRENT_CHAR_WEAPON", ped, 0, 1);
  207.                     GTA.Native.Function.Call("SWITCH_PED_TO_ANIMATED", Player.Character, 0);
  208.                     GTA.Native.Function.Call("SET_CURRENT_CHAR_WEAPON", ped, 0, 1);
  209.                     GTA.Native.Function.Call("SET_EVERYONE_IGNORE_PLAYER", Player, 1);
  210.                     Wait(10);
  211.                     GTA.Native.Function.Call("SET_CURRENT_CHAR_WEAPON", ped, 0, 1);
  212.                     GTA.Native.Function.Call("SWITCH_PED_TO_ANIMATED", ped, 1);
  213.  
  214.                     int waitTime = Convert.ToInt32(Math.Round((ped.Position.DistanceTo(Player.Character.Position) * 70.0f), 0));
  215.                     Wait(waitTime);
  216.                     GTA.Native.Function.Call("SWITCH_PED_TO_ANIMATED", ped, 1);
  217.                     GTA.Native.Function.Call("CLEAR_WANTED_LEVEL", Player);
  218.                     Player.Character.Task.TurnTo(ped);
  219.                     ped.Task.TurnTo(Player.Character);
  220.  
  221.                     if (clipboard != null && clipboard.Exists())
  222.                     {
  223.                         GTA.Native.Function.Call("ATTACH_OBJECT_TO_PED", clipboard, ped, 1232, -0.025f, 0.085f, -0.021f, 0.0f, 0.0f, -0.5f, 0);
  224.                     }
  225.  
  226.                     Player.Character.Task.PlayAnimation(nikoGestures, "how", 6.4F);
  227.                     ped.Task.PlayAnimation(ambientAnimations, "walk_hold", 6.4F, animationFlags);
  228.                     Wait(500);
  229.                     Player.Character.Task.ClearAll();
  230.                     ped.Task.TurnTo(Player.Character);
  231.  
  232.                     Wait(3500);
  233.                     ped.SayAmbientSpeech("INTIMIDATE");
  234.                     playerGroup.RemoveMember(ped);
  235.                     ped.Task.ClearAll();
  236.  
  237.                     if (clipboard != null && clipboard.Exists())
  238.                     {
  239.                         clipboard.Delete();
  240.                     }
  241.  
  242.                     Player.CanControlCharacter = true;
  243.                     GTA.Native.Function.Call("SET_CAMERA_CONTROLS_DISABLED_WITH_PLAYER_CONTROLS", 1);
  244.                     GTA.Native.Function.Call("SET_POLICE_IGNORE_PLAYER", Player, 0);
  245.                     GTA.Native.Function.Call("SET_MAX_WANTED_LEVEL", 6);
  246.                     GTA.Native.Function.Call("SET_EVERYONE_IGNORE_PLAYER", Player, 0);
  247.  
  248.                     if (Player.Money > ticketAmount)
  249.                     {
  250.                         Player.Money -= ticketAmount;
  251.                     }
  252.                     else
  253.                     {
  254.                         ticketAmount = Player.Money;
  255.                     }
  256.  
  257.                     ped.Money += ticketAmount;
  258.                     Player.Money -= ticketAmount;
  259.                     Game.DisplayText("LCPD: your were fined with: " + ticketAmount + "$");
  260.                     ped.RelationshipGroup = RelationshipGroup.Cop;
  261.  
  262.                     GTA.Native.Function.Call("CANCEL_OVERRIDE_RESTART");
  263.                     Player.Character.FreezePosition = false;
  264.                     this.IsSurrendering = false;
  265.  
  266.                     if (ped.Exists())
  267.                     {
  268.                         GTA.Native.Function.Call("SET_CHAR_AS_MISSION_CHAR", ped, 0);
  269.                         if (ped.isInGroup)
  270.                         {
  271.                             playerGroup.RemoveMember(ped);
  272.                         }
  273.  
  274.                         ped.NoLongerNeeded();
  275.                     }
  276.                 }
  277.  
  278.                 if (this.IsSurrendering && !GTA.Native.Function.Call<bool>("IS_CHAR_PLAYING_ANIM", Player.Character, "ped", "handsup"))
  279.                 {
  280.                     new AnimationSet("ped");
  281.  
  282.                     Wait(0);
  283.                     if ((isKeyPressed(Settings.GetValueKey("Key", Keys.F8)) && !GTA.Native.Function.Call<bool>("PLAYER_HAS_GREYED_OUT_STARS", Player)) && !GTA.Native.Function.Call<bool>("IS_CHAR_PLAYING_ANIM", Player.Character, "ped", "handsup"))
  284.                     {
  285.                         Player.Character.Task.PlayAnimation(nikoGestures, "handsup", 15.4F);
  286.                     }
  287.  
  288.                     Wait(600);
  289.                     if (!GTA.Native.Function.Call<bool>("IS_CHAR_PLAYING_ANIM", Player.Character, "ped", "handsup"))
  290.                     {
  291.                         Player.WantedLevel = this.WantedLevel;
  292.                         this.IsSurrendering = false;
  293.                     }
  294.                 }
  295.             }
  296.             else if ((Player.WantedLevel >= 1) && Player.Character.isAlive && !Player.Character.isRagdoll)
  297.             {
  298.                 if (isKeyPressed(Settings.GetValueKey("Key", Keys.F8)) && !GTA.Native.Function.Call<bool>("IS_PLAYER_BEING_ARRESTED", Player) && !GTA.Native.Function.Call<bool>("PLAYER_HAS_GREYED_OUT_STARS", Player))
  299.                 {
  300.                     this.IsSurrendering = true;
  301.                     this.WantedLevel = Player.WantedLevel;
  302.                     AnimationSet animz = new AnimationSet("ped");
  303.                     if (!GTA.Native.Function.Call<bool>("IS_CHAR_PLAYING_ANIM", Player.Character, "ped", "handsup"))
  304.                     {
  305.                         Player.Character.Task.PlayAnimation(animz, "handsup", 15.4F);
  306.                     }
  307.  
  308.                     Player.WantedLevel = 1;
  309.                     Player.Character.Weapons.Current.Ammo = 0;
  310.                     Player.Character.DropCurrentWeapon();
  311.                     GTA.Native.Function.Call("SET_CURRENT_CHAR_WEAPON", Player.Character, 0, 1);
  312.                     Wait(100);
  313.                     if (GTA.Native.Function.Call<bool>("IS_CHAR_PLAYING_ANIM", Player.Character, "ped", "handsup"))
  314.                     {
  315.                         Wait(0);
  316.                     }
  317.                     else
  318.                     {
  319.                         Wait(0);
  320.                         Player.WantedLevel = this.WantedLevel;
  321.                         this.IsSurrendering = false;
  322.                     }
  323.                 }
  324.             }
  325.         }
  326.         #endregion
  327.     }
  328. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement