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.Windows.Forms;
- enum WeatherType
- {
- EXTRA_SUNNY = -1750463879,
- CLEAR = 916995460,
- NEUTRAL = -1530260698,
- SMOG = 282916021,
- FOGGY = -1368164796,
- OVERCAST = -1148613331,
- CLOUDS = 821931868,
- CLEARING = 1840358669,
- RAIN = 1420204096,
- THUNDER = -1233681761,
- SNOW = -273223690,
- BLIZZARD = 669657108,
- LIGHT_SNOW = 603685163,
- X_MAS = -1429616491
- };
- enum VehicleClass
- {
- COMPACT=0,
- SEDAN,
- SUV,
- COUPE,
- MUSCLE,
- SPORTCLASSIC,
- SPORT,
- SUPER,
- MOTORCYCLE,
- OFFROAD,
- INDUSTRIAL,
- UTILITY,
- VAN_OR_PICKUP,
- BICYCLE,
- BOAT,
- HELICOPTER,
- AIRPLANE,
- SERVICE,
- EMERGENCY,
- MILITARY,
- COMMERTIAL,
- }
- public class HollywoodRollover : Script
- {
- bool AffectPlayer = true;
- bool AffectNPCs = true;
- bool Debug = false;
- bool CanRollover = true;
- int ReferenceTime=Game.GameTime;
- int NPCBaseProb = 0;
- int PlayerBaseProb =0;
- int ExplosiveRolloverProb=0;
- int RolloverCooldownTime = Game.GameTime;
- public HollywoodRollover()
- {
- Tick += OnTick;
- KeyDown += OnKeyDown;
- KeyUp += OnKeyUp;
- LoadSettings();
- }
- void HandleRoll()
- {
- if (AffectPlayer)
- {
- if (CanWeUse(GetLastVehicle(Game.Player.Character)) && GetLastVehicle(Game.Player.Character).IsOnAllWheels && Math.Abs(Function.Call<Vector3>(Hash.GET_ENTITY_SPEED_VECTOR, GetLastVehicle(Game.Player.Character), true).X) > 15f && Math.Abs(Function.Call<Vector3>(Hash.GET_ENTITY_SPEED_VECTOR, GetLastVehicle(Game.Player.Character), true).Y) < 15f)
- {
- if (Debug)
- {
- DisplayHelpTextThisFrame(GetRolloverProb(GetLastVehicle(Game.Player.Character)).ToString() + "% prob rollover, " + (ExplosiveRolloverProb + (1000f - (int)GetLastVehicle(Game.Player.Character).BodyHealth) / 10) + "% prob explosive");
- }
- if (GetRolloverProb(GetLastVehicle(Game.Player.Character)) > RandomInt(30,100))
- {
- RolloverCooldownTime = Game.GameTime;
- CanRollover = false;
- float force = Function.Call<Vector3>(Hash.GET_ENTITY_SPEED_VECTOR, GetLastVehicle(Game.Player.Character), true).X;
- Function.Call(Hash.APPLY_FORCE_TO_ENTITY, GetLastVehicle(Game.Player.Character), 3, 0f, 0f, 3f, 0f, 0f, 0f, 0, true, true, true, true, true);
- Script.Wait(20);
- Function.Call(Hash.APPLY_FORCE_TO_ENTITY, GetLastVehicle(Game.Player.Character), 3, (force / 5), 0f, 0f, 0f, 0f, 30f, 0, true, true, true, true, true);
- Function.Call(Hash.APPLY_FORCE_TO_ENTITY, GetLastVehicle(Game.Player.Character), 3, (force / 5) * -1, 0f, 0f, 0f, 0f, -30f, 0, true, true, true, true, true);
- if (ExplosiveRolloverProb > 0 && (ExplosiveRolloverProb + (1000f - GetLastVehicle(Game.Player.Character).BodyHealth) / 10) > RandomInt(50, 100))
- {
- Function.Call<int>(GTA.Native.Hash.SET_VEHICLE_OUT_OF_CONTROL, GetLastVehicle(Game.Player.Character),false,true);
- Script.Wait(40);
- Function.Call(Hash.APPLY_FORCE_TO_ENTITY, GetLastVehicle(Game.Player.Character), 3, 0f, 0f, 2f, 0f, 0f, 0f, 0, false, true, true, true, true);
- }
- }
- }
- }
- if (AffectNPCs)
- {
- foreach(Vehicle veh in World.GetNearbyVehicles(Game.Player.Character, 30f))
- {
- if(veh.Handle != GetLastVehicle(Game.Player.Character).Handle)
- {
- if (veh.IsOnAllWheels && Function.Call<Vector3>(Hash.GET_ENTITY_ROTATION_VELOCITY, veh).Z < 1f && Math.Abs(Function.Call<Vector3>(Hash.GET_ENTITY_SPEED_VECTOR, veh, true).X) > 10f && Math.Abs(Function.Call<Vector3>(Hash.GET_ENTITY_SPEED_VECTOR,veh, true).Y) < 14f)
- {
- if (Debug)
- {
- DisplayHelpTextThisFrame(GetRolloverProb(veh).ToString() + "% prob rollover, " + (ExplosiveRolloverProb + (1000f - (int)veh.BodyHealth) / 10) + "% prob explosive");
- }
- if (GetRolloverProb(veh) > RandomInt(30, 100))
- {
- RolloverCooldownTime = Game.GameTime;
- CanRollover = false;
- float force = Function.Call<Vector3>(Hash.GET_ENTITY_SPEED_VECTOR, veh, true).X;
- Function.Call(Hash.APPLY_FORCE_TO_ENTITY, veh, 3, 0f, 0f, 3f, 0f, 0f, 0f, 0, true, true, true, true, true);
- Script.Wait(40);
- Function.Call(Hash.APPLY_FORCE_TO_ENTITY, veh, 3, (force / 5), 0f, 0f, 0f, 0f, 30f, 0, true, true, true, true, true);
- Function.Call(Hash.APPLY_FORCE_TO_ENTITY, veh, 3, (force / 5) * -1, 0f, 0f, 0f, 0f, -30f, 0, true, true, true, true, true);
- if (ExplosiveRolloverProb >0 && (ExplosiveRolloverProb + (1000f - veh.BodyHealth) / 10) > RandomInt(50, 100))
- {
- Function.Call<int>(GTA.Native.Hash.SET_VEHICLE_OUT_OF_CONTROL, veh, true, true);
- Script.Wait(40);
- Function.Call(Hash.APPLY_FORCE_TO_ENTITY, veh, 3, (force / 5), 0f, 0f, 0f, 0f, 30f, 0, true, true, true, true, true);
- }
- }
- }
- }
- }
- }
- }
- void OnTick(object sender, EventArgs e)
- {
- if (Game.GameTime > ReferenceTime + 500)
- {
- ReferenceTime = Game.GameTime;
- if(CanRollover) HandleRoll();
- }
- if(Game.GameTime > RolloverCooldownTime + 5000 && !CanRollover)
- {
- CanRollover = true;
- }
- }
- void OnKeyDown(object sender, KeyEventArgs e)
- {
- }
- void OnKeyUp(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter)
- {
- LoadSettings();
- }
- }
- bool CanWeUse(Entity entity)
- {
- return entity != null && entity.Exists();
- }
- int RandomInt(int min, int max)
- {
- max++;
- return Function.Call<int>(GTA.Native.Hash.GET_RANDOM_INT_IN_RANGE, min, max);
- }
- Vehicle GetLastVehicle(Ped RecieveOrder)
- {
- Vehicle vehicle = null;
- if (GTA.Native.Function.Call<Vehicle>(GTA.Native.Hash.GET_VEHICLE_PED_IS_IN, RecieveOrder, true) != null)
- {
- vehicle = GTA.Native.Function.Call<Vehicle>(GTA.Native.Hash.GET_VEHICLE_PED_IS_IN, RecieveOrder, true);
- if (vehicle.IsAlive)
- {
- return vehicle;
- }
- }
- else
- {
- if (GTA.Native.Function.Call<Vehicle>(GTA.Native.Hash.GET_VEHICLE_PED_IS_IN, RecieveOrder, false) != null)
- {
- vehicle = GTA.Native.Function.Call<Vehicle>(GTA.Native.Hash.GET_VEHICLE_PED_IS_IN, RecieveOrder, false);
- if (vehicle.IsAlive)
- {
- return vehicle;
- }
- }
- }
- return vehicle;
- }
- void LoadSettings()
- {
- ScriptSettings config = ScriptSettings.Load(@"scripts\HollywoodRollover.ini");
- AffectNPCs = config.GetValue<bool>("SETTINGS", "AffectNPCs", true);
- AffectPlayer = config.GetValue<bool>("SETTINGS", "AffectPlayer", true);
- PlayerBaseProb = config.GetValue<int>("SETTINGS", "PlayerBaseProb", 0);
- NPCBaseProb = config.GetValue<int>("SETTINGS", "NPCBaseProb", 0);
- ExplosiveRolloverProb = config.GetValue<int>("SETTINGS", "ExplosiveRolloverProb", 0);
- Debug = config.GetValue<bool>("SETTINGS", "Debug", true);
- }
- bool IsRaining()
- {
- int weather = Function.Call<int>(GTA.Native.Hash._0x564B884A05EC45A3); //get current weather hash
- switch (weather)
- {
- case (int)WeatherType.BLIZZARD:
- {
- return true;
- }
- case (int)WeatherType.CLEARING:
- {
- return true;
- }
- case (int)WeatherType.FOGGY:
- {
- return true;
- }
- case (int)WeatherType.RAIN:
- {
- return true;
- }
- case (int)WeatherType.NEUTRAL:
- {
- return true;
- }
- case (int)WeatherType.THUNDER:
- {
- return true;
- }
- case (int)WeatherType.LIGHT_SNOW:
- {
- return true;
- }
- case (int)WeatherType.SNOW:
- {
- return true;
- }
- case (int)WeatherType.X_MAS:
- {
- return true;
- }
- }
- return false;
- }
- int GetRolloverProb(Vehicle veh)
- {
- int prob = 0;
- if (veh.Handle == GetLastVehicle(Game.Player.Character).Handle)
- {
- prob = PlayerBaseProb;
- }
- else
- {
- prob = NPCBaseProb;
- }
- Vector3 min;
- Vector3 max;
- veh.Model.GetDimensions(out min, out max);
- prob += (int)((((max - min).X) * -3));
- prob += (int)((((max - min).Y) * 3));
- prob += (int)((((max - min).Z) * 3));
- prob += (int)(1000f - veh.BodyHealth) / 10;
- prob += (int)(veh.HeightAboveGround*3);
- if (Function.Call<bool>(Hash.IS_POINT_ON_ROAD, veh.Position.X, veh.Position.Y, veh.Position.Z, veh) == false)
- {
- prob += 20;
- }
- if (IsRaining()) prob = prob / 2;
- if (prob > 100) prob = 100;
- return prob;
- }
- void DisplayHelpTextThisFrame(string text)
- {
- Function.Call(Hash._SET_TEXT_COMPONENT_FORMAT, "STRING");
- Function.Call(Hash._ADD_TEXT_COMPONENT_STRING, text);
- Function.Call(Hash._0x238FFE5C7B0498A6, 0, 0, 1, -1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement