Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using GTA;
- using GTA.Math;
- using GTA.Native;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Windows.Forms;
- public class AutomaticSlowMo : Script
- {
- //Script
- string ScriptName = "AutomaticSlowMo";
- string ScriptVer = "1.0";
- //Settings
- bool RagdollSlowmo=true;
- bool CarAccidentSlowmo = true;
- bool ExplosionSlowmo = true;
- public static List<Vehicle> Vehicles = new List<Vehicle>();
- //Timers
- int GameTimeRef=Game.GameTime;
- int ExtraTime = 500;
- int SlowmoStopTime = Game.GameTime;
- int NextSlowmoCheck = Game.GameTime;
- //Slowmo
- float SlowmoChangeRate = 0.05f;
- float SlowMoRate = 1.0f;
- public AutomaticSlowMo()
- {
- Tick += OnTick;
- }
- void OnTick(object sender, EventArgs e)
- {
- Game.TimeScale = SlowMoRate;
- //Slowmo ratio
- if (SlowmoStopTime > Game.GameTime)
- {
- if (SlowMoRate > 0.2) SlowMoRate -= SlowmoChangeRate;
- }
- else
- {
- if (SlowMoRate < 1) SlowMoRate += (SlowmoChangeRate/5);
- }
- //Heavyweapons special check
- if ((Game.Player.Character.Weapons.Current.Hash == WeaponHash.Minigun) && Game.Player.Character.IsShooting) SlowmoStopTime = Game.GameTime + 100;
- if (Game.GameTime > GameTimeRef + ExtraTime)
- {
- GameTimeRef = Game.GameTime;
- HandleVehicleList();
- if(NextSlowmoCheck < Game.GameTime) HandleEvents();
- }
- //debug info
- //if(NextSlowmoCheck>Game.GameTime || SlowmoStopTime>Game.GameTime) DisplayHelpTextThisFrame("Time left: "+ (SlowmoStopTime - Game.GameTime).ToString()+"~n~Next check: "+ (NextSlowmoCheck - Game.GameTime).ToString());
- }
- void HandleVehicleList()
- {
- foreach(Vehicle veh in World.GetNearbyVehicles(Game.Player.Character.Position, 20f))
- {
- if (!Vehicles.Contains(veh) && Vehicles.Count<10)
- {
- Vehicles.Add(veh);
- }
- }
- for (int i = 0; i < Vehicles.Count - 1; i++)
- {
- if (!CanWeUse(Vehicles[i]))
- {
- Vehicles.Remove(Vehicles[i]);
- }
- }
- }
- void HandleEvents()
- {
- Vector3 pos = Game.Player.Character.Position;
- //Incoming RPGs
- 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))
- {
- SlowmoStopTime = Game.GameTime + 500;
- }
- //Explosion
- if (Function.Call<bool>(Hash.IS_EXPLOSION_IN_SPHERE, -1, pos.X, pos.Y, pos.Z, 100f))
- {
- SlowMoRate = 0.3f;
- SlowmoStopTime = Game.GameTime + 500;
- NextSlowmoCheck = Game.GameTime + 5000;
- }
- //Being ragdolled
- if (Game.Player.Character.IsRagdoll)
- {
- SlowMoRate = 0.3f;
- SlowmoStopTime = Game.GameTime + 500;
- NextSlowmoCheck = Game.GameTime + 5000;
- }
- //Vehicle Accident
- foreach (Vehicle veh in Vehicles)
- {
- if (CanWeUse(veh) && !veh.IsOnAllWheels && veh.HeightAboveGround > 2f && veh.IsOnScreen)
- {
- if (veh.Speed > 20f || Function.Call<Vector3>(Hash.GET_ENTITY_ROTATION_VELOCITY, veh).Length() > 2f)
- {
- SlowmoStopTime = Game.GameTime + 500;
- NextSlowmoCheck = Game.GameTime + 10000;
- }
- }
- }
- }
- bool CanWeUse(Entity entity)
- {
- return entity != null && entity.Exists();
- }
- void DisplayHelpTextThisFrame(string text)
- {
- Function.Call(Hash._SET_TEXT_COMPONENT_FORMAT, "STRING");
- Function.Call(Hash._ADD_TEXT_COMPONENT_STRING, text);
- Function.Call(Hash._DISPLAY_HELP_TEXT_FROM_STRING_LABEL, 0, false, true, -1);
- }
- //Not implemented yet
- void LoadSettings()
- {
- if (File.Exists(@"scripts\\seatbelt.ini"))
- {
- ScriptSettings config = ScriptSettings.Load(@"scripts\seatbelt.ini");
- //UseManualSeatbelt = config.GetValue<bool>("SETTINGS", "UseManualSeatbelt", true);
- }
- else
- {
- WarnPlayer(ScriptName + " " + ScriptVer, "CONFIG NOT FOUND", "A configuration file for ~y~" + ScriptName + "~w~ hasn't been found.");
- }
- }
- void WarnPlayer(string script_name, string title, string message)
- {
- Function.Call(Hash._SET_NOTIFICATION_TEXT_ENTRY, "STRING");
- Function.Call(Hash._ADD_TEXT_COMPONENT_STRING, message);
- Function.Call(Hash._SET_NOTIFICATION_MESSAGE, "CHAR_SOCIAL_CLUB", "CHAR_SOCIAL_CLUB", true, 0, title, "~b~" + script_name);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement