SHARE
TWEET

Automatic Slowmo

Eddlm Aug 14th, 2016 437 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using GTA;
  2. using GTA.Math;
  3. using GTA.Native;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.IO;
  7. using System.Windows.Forms;
  8.  
  9.  
  10.  
  11. public class AutomaticSlowMo : Script
  12. {
  13.  
  14.     //Script
  15.     string ScriptName = "AutomaticSlowMo";
  16.     string ScriptVer = "1.0";
  17.  
  18.     //Settings
  19.     bool RagdollSlowmo=true;
  20.     bool CarAccidentSlowmo = true;
  21.     bool ExplosionSlowmo = true;
  22.  
  23.  
  24.     public static List<Vehicle> Vehicles = new List<Vehicle>();
  25.  
  26.     //Timers
  27.     int GameTimeRef=Game.GameTime;
  28.     int ExtraTime = 500;
  29.     int SlowmoStopTime = Game.GameTime;
  30.     int NextSlowmoCheck = Game.GameTime;
  31.  
  32.     //Slowmo
  33.     float SlowmoChangeRate = 0.05f;
  34.     float SlowMoRate = 1.0f;
  35.  
  36.     public AutomaticSlowMo()
  37.     {
  38.         Tick += OnTick;
  39.     }
  40.  
  41.     void OnTick(object sender, EventArgs e)
  42.     {
  43.         Game.TimeScale = SlowMoRate;
  44.  
  45.         //Slowmo ratio
  46.         if (SlowmoStopTime > Game.GameTime)
  47.         {
  48.             if (SlowMoRate > 0.2) SlowMoRate -= SlowmoChangeRate;
  49.         }
  50.         else
  51.         {
  52.             if (SlowMoRate < 1) SlowMoRate += (SlowmoChangeRate/5);
  53.         }
  54.  
  55.         //Heavyweapons special check
  56.         if ((Game.Player.Character.Weapons.Current.Hash == WeaponHash.Minigun) && Game.Player.Character.IsShooting) SlowmoStopTime = Game.GameTime + 100;
  57.  
  58.  
  59.         if (Game.GameTime > GameTimeRef + ExtraTime)
  60.         {
  61.             GameTimeRef = Game.GameTime;
  62.  
  63.  
  64.             HandleVehicleList();
  65.             if(NextSlowmoCheck < Game.GameTime) HandleEvents();
  66.         }
  67.  
  68.         //debug info
  69.         //if(NextSlowmoCheck>Game.GameTime || SlowmoStopTime>Game.GameTime) DisplayHelpTextThisFrame("Time left: "+ (SlowmoStopTime - Game.GameTime).ToString()+"~n~Next check: "+ (NextSlowmoCheck - Game.GameTime).ToString());
  70.     }
  71.  
  72.     void HandleVehicleList()
  73.     {
  74.         foreach(Vehicle veh in World.GetNearbyVehicles(Game.Player.Character.Position, 20f))
  75.         {
  76.             if (!Vehicles.Contains(veh) && Vehicles.Count<10)
  77.             {
  78.                 Vehicles.Add(veh);
  79.             }
  80.         }
  81.         for (int i = 0; i < Vehicles.Count - 1; i++)
  82.         {
  83.             if (!CanWeUse(Vehicles[i]))
  84.             {
  85.                 Vehicles.Remove(Vehicles[i]);
  86.             }
  87.         }
  88.     }
  89.  
  90.     void HandleEvents()
  91.     {
  92.         Vector3 pos = Game.Player.Character.Position;
  93.  
  94.  
  95.         //Incoming RPGs
  96.         if (Function.Call<bool>(Hash.IS_PROJECTILE_IN_AREA, pos.X - 50, pos.Y - 50, pos.Z - 50, pos.X+50,pos.Y+50, pos.Z+50, false))
  97.         {
  98.             SlowmoStopTime = Game.GameTime + 500;
  99.         }
  100.  
  101.         //Explosion
  102.         if (Function.Call<bool>(Hash.IS_EXPLOSION_IN_SPHERE, -1, pos.X, pos.Y, pos.Z, 100f))
  103.         {
  104.             SlowMoRate = 0.3f;
  105.             SlowmoStopTime = Game.GameTime + 500;
  106.             NextSlowmoCheck = Game.GameTime + 5000;
  107.         }
  108.  
  109.         //Being ragdolled
  110.         if (Game.Player.Character.IsRagdoll)
  111.         {
  112.             SlowMoRate = 0.3f;
  113.             SlowmoStopTime = Game.GameTime + 500;
  114.             NextSlowmoCheck = Game.GameTime + 5000;
  115.         }
  116.  
  117.         //Vehicle Accident
  118.         foreach (Vehicle veh in Vehicles)
  119.         {
  120.             if (CanWeUse(veh) && !veh.IsOnAllWheels && veh.HeightAboveGround > 2f && veh.IsOnScreen)
  121.             {
  122.                 if (veh.Speed > 20f || Function.Call<Vector3>(Hash.GET_ENTITY_ROTATION_VELOCITY, veh).Length() > 2f)
  123.                 {
  124.                     SlowmoStopTime = Game.GameTime + 500;
  125.                     NextSlowmoCheck = Game.GameTime + 10000;
  126.                 }
  127.             }
  128.         }
  129.     }
  130.  
  131.  
  132.  
  133.     bool CanWeUse(Entity entity)
  134.     {
  135.         return entity != null && entity.Exists();
  136.     }
  137.  
  138.     void DisplayHelpTextThisFrame(string text)
  139.     {
  140.         Function.Call(Hash._SET_TEXT_COMPONENT_FORMAT, "STRING");
  141.         Function.Call(Hash._ADD_TEXT_COMPONENT_STRING, text);
  142.         Function.Call(Hash._DISPLAY_HELP_TEXT_FROM_STRING_LABEL, 0, false, true, -1);
  143.     }
  144.  
  145.     //Not implemented yet
  146.     void LoadSettings()
  147.     {
  148.         if (File.Exists(@"scripts\\seatbelt.ini"))
  149.         {
  150.             ScriptSettings config = ScriptSettings.Load(@"scripts\seatbelt.ini");
  151.             //UseManualSeatbelt = config.GetValue<bool>("SETTINGS", "UseManualSeatbelt", true);
  152.         }
  153.         else
  154.         {
  155.             WarnPlayer(ScriptName + " " + ScriptVer, "CONFIG NOT FOUND", "A configuration file for ~y~" + ScriptName + "~w~ hasn't been found.");
  156.         }
  157.     }
  158.     void WarnPlayer(string script_name, string title, string message)
  159.     {
  160.         Function.Call(Hash._SET_NOTIFICATION_TEXT_ENTRY, "STRING");
  161.         Function.Call(Hash._ADD_TEXT_COMPONENT_STRING, message);
  162.         Function.Call(Hash._SET_NOTIFICATION_MESSAGE, "CHAR_SOCIAL_CLUB", "CHAR_SOCIAL_CLUB", true, 0, title, "~b~" + script_name);
  163.     }
  164.  
  165. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top