Advertisement
tjackisen

GTA IV C# Smoking Spliff

Mar 30th, 2013
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.47 KB | None | 0 0
  1.     public class Class1 : Script
  2.     {
  3.  
  4.         bool bSmoking = false;
  5.         GTA.Object spliff;
  6.         GTA.Timer timer = new GTA.Timer(); // the timer will always show the elapsed gametime since the last Start()
  7.  
  8.         AnimationSet anims = new AnimationSet("amb@smoking_spliff");
  9.         AnimationFlags animflags = AnimationFlags.Unknown12 | AnimationFlags.Unknown11 | AnimationFlags.Unknown09;
  10.  
  11.         public Class1()
  12.         {
  13.             Interval = 1000;
  14.             this.KeyDown += new GTA.KeyEventHandler(this.AnimationExample_KeyDown);
  15.             this.Tick += new EventHandler(this.AnimationExample_Tick);
  16.         }
  17.  
  18.         private void AnimationExample_KeyDown(object sender, GTA.KeyEventArgs e)
  19.         {
  20.             if (e.Key != Keys.J) return;
  21.             if (bSmoking)
  22.                 StopSmoking();
  23.             else
  24.                 StartSmoking();
  25.         }
  26.  
  27.         private void StartSmoking()
  28.         {
  29.             if (bSmoking) return;
  30.             bSmoking = true;
  31.  
  32.             Player.Character.Weapons.Unarmed.Select();
  33.             Player.Character.Animation.Play(anims, "create_spliff", 8.0F, animflags);
  34.             Wait(1600);
  35.  
  36.             spliff = World.CreateObject(0xD130ADEF, Player.Character.Position);
  37.             spliff.AttachToPed(Player.Character, Bone.RightHand, new Vector3(0.14F, 0.03F, 0.04F), new Vector3(2.21F, -0.12F, 0.0F));
  38.  
  39.             Player.Character.Animation.WaitUntilFinished(anims, "create_spliff");
  40.             timer.Start();
  41.         }
  42.  
  43.         private void StopSmoking()
  44.         {
  45.             if (!bSmoking) return;
  46.             bSmoking = false;
  47.             if (spliff == null) return;
  48.  
  49.             spliff.Detach();
  50.             spliff.NoLongerNeeded();
  51.         }
  52.  
  53.         private void AnimationExample_Tick(object sender, EventArgs e)
  54.         {
  55.             if (bSmoking)
  56.             {
  57.                 if (Player.Character.Weapons.CurrentType != Weapon.Unarmed)
  58.                 {
  59.                     StopSmoking();
  60.                 }
  61.                 else if ((timer.ElapsedTime > 10000) && (Player.Character.isIdle))
  62.                 {
  63.                     if (Player.Character.isInVehicle())
  64.                         Player.Character.Task.PlayAnimation(anims, "partial_smoke_car", 8.0F, animflags);
  65.                     else
  66.                         Player.Character.Task.PlayAnimation(anims, "partial_smoke", 8.0F, animflags);
  67.                     timer.Start();
  68.                 }
  69.             }
  70.         }
  71.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement