Advertisement
LostProphet

StopSticks

Apr 21st, 2012
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.03 KB | None | 0 0
  1. using System;
  2. using System.Windows.Forms;
  3. using GTA;
  4. using GTA.Native;
  5.  
  6. public class StopSticks : Script
  7. {
  8.     private Keys spawnStick, startStopSticks, startStopSticks1;
  9.     private GTA.Object stick = null;
  10.     private Vehicle closestVehicle = null;
  11.     private Blip stickIcon;
  12.     private bool isActive;
  13.  
  14.     public StopSticks()
  15.     {
  16.         this.KeyDown += new GTA.KeyEventHandler(this.Stick_KeyDown); // BY YOUR POWERS COMBINED,
  17.         this.Tick += new EventHandler(this.LookforCars); // I AM CAPTAIN PLANET.
  18.         this.Interval = 300;
  19.  
  20.         this.spawnStick = Settings.GetValueKey("spawnStick", Keys.M);
  21.         this.startStopSticks = Settings.GetValueKey("startStopSticks", Keys.NumPad0);
  22.         this.startStopSticks1 = Settings.GetValueKey("startStopSticks1", Keys.Z);
  23.     }
  24.  
  25.     private void Stick_KeyDown(object sender, GTA.KeyEventArgs e)
  26.     {
  27.         if (e.Key == Keys.NumPad0 && Game.isKeyPressed(Keys.X))
  28.         {
  29.             this.isActive = !this.isActive; // Toggle state.
  30.  
  31.             Game.DisplayText("StopStickMod state: " + this.isActive, 5000);
  32.         }
  33.  
  34.         if (!this.isActive)
  35.             return; // Mod not active, return.
  36.  
  37.         if (e.Key == this.spawnStick && this.isActive)
  38.         {
  39.             if (!Game.Exists(this.stick) && !Player.Character.isInVehicle())
  40.             {
  41.                 this.stick = World.CreateObject("cj_car_wash_barrier", Player.Character.GetOffsetPosition(new Vector3(0, 4, 0)).ToGround()); // Hey let's spawn stuff.
  42.                 this.stick.Collision = true; // So it hits the ground.
  43.  
  44.                 Game.Console.Print("Stick spawned!");
  45.  
  46.                 this.stickIcon = Blip.AddBlip(this.stick);
  47.                 this.stickIcon.Icon = BlipIcon.Misc_CopCar;
  48.                 this.stickIcon.Color = BlipColor.DarkRed;
  49.             }
  50.             else if (Game.Exists(this.stick)) // See if it exists...
  51.             {
  52.                 this.stick.Delete();
  53.                 this.stickIcon.Delete();
  54.             }
  55.         }
  56.     }
  57.  
  58.     private void LookforCars(object sender, EventArgs e)
  59.     {
  60.         if (Game.Exists(this.stick))
  61.         {
  62.             this.closestVehicle = World.GetClosestVehicle(this.stick.Position, 5.0f); // Check for cars.
  63.             //Game.DisplayText("STARTING EVENT." + CarNearStick(2),  5000);
  64.             //if (CarNearStick(1.5f);
  65.  
  66.             if (Game.Exists(this.closestVehicle))
  67.             {
  68.                 if (this.CarNearStick(1.5f))
  69.                 {
  70.                     this.closestVehicle.BurstTire(VehicleWheel.FrontLeft);
  71.                     this.closestVehicle.BurstTire(VehicleWheel.FrontRight);
  72.  
  73.                     this.Wait(1000);
  74.  
  75.                     this.closestVehicle.BurstTire(VehicleWheel.RearLeft);
  76.                     this.closestVehicle.BurstTire(VehicleWheel.RearRight);
  77.                 }
  78.             }
  79.         }
  80.     }
  81.  
  82.     private bool CarNearStick(float range)
  83.     {
  84.         return Game.Exists(this.closestVehicle) && this.stick.Position.DistanceTo(this.closestVehicle.Position) < range;
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement