SHARE
TWEET

KERS for all vehicles sourcecode

Eddlm Aug 5th, 2017 76 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.IO;
  6. using System.Windows.Forms;
  7.  
  8.  
  9.  
  10. public class KERS : Script
  11. {
  12.     string ScriptName = "KERS for all cars";
  13.     string ScriptVer = "1.0";
  14.     float KERSEnergy;
  15.     int GameTimeRef = Game.GameTime;
  16.     bool BoostActive=false;
  17.     bool KERSNotified = false;
  18.     public KERS()
  19.     {
  20.         Tick += OnTick;
  21.  
  22.     }
  23.     public static float ForwardSpeed(Entity ent)
  24.     {
  25.         return Function.Call<Vector3>(Hash.GET_ENTITY_SPEED_VECTOR, ent, true).Y;
  26.     }
  27.     void OnTick(object sender, EventArgs e)
  28.     {
  29.         if (CanWeUse(Game.Player.Character.CurrentVehicle))
  30.         {            
  31.             Vehicle veh = Game.Player.Character.CurrentVehicle;
  32.             if (BoostActive)
  33.             {
  34.                 veh.EngineTorqueMultiplier = 4;
  35.                 if (KERSEnergy>0)
  36.                 {
  37.                     KERSEnergy--;
  38.                 }
  39.                 else
  40.                 {
  41.                     DisplayHelpTextThisFrame("~b~KERS~w~ discharged.");
  42.                     BoostActive = false;
  43.                 }
  44.             }          
  45.             if (veh.GetMod(VehicleMod.Engine) > 2)
  46.             {
  47.                 if (!KERSNotified)
  48.                 {
  49.                     DisplayHelpTextThisFrame("~b~KERS~w~ is available for this vehicle.");
  50.                     KERSNotified = true;
  51.                 }
  52.  
  53.                 if (Game.IsControlPressed(2,GTA.Control.VehicleBrake) && !Game.IsControlPressed(2,GTA.Control.VehicleAccelerate) && veh.IsOnAllWheels && ForwardSpeed(veh)>5)
  54.                 {
  55.                     if(KERSEnergy<100) KERSEnergy++;
  56.                 }
  57.                 if(Game.IsControlJustReleased(2,GTA.Control.VehicleBrake))
  58.                 {
  59.                     if(KERSEnergy<100) DisplayHelpTextThisFrame("~b~KERS~w~ charged [" + Math.Round(KERSEnergy, 0).ToString() + "%].");
  60.                     else DisplayHelpTextThisFrame("~b~KERS~w~ charged [~g~" + Math.Round(KERSEnergy, 0).ToString() + "%~w~].~n~Press ~INPUT_CONTEXT~ to release it.");
  61.                    
  62.                 }
  63.                 if (KERSEnergy>0 && Game.IsControlJustPressed(2, GTA.Control.VehicleHorn))
  64.                 {
  65.                     DisplayHelpTextThisFrame("~b~KERS~w~ injected.");
  66.                     BoostActive = true;
  67.                 }
  68.             }
  69.         }
  70.         else
  71.         {
  72.             if (KERSNotified) KERSNotified = false;
  73.             if (KERSEnergy!=0) KERSEnergy = 0;
  74.             if (BoostActive) BoostActive = false;
  75.         }
  76.     }  
  77.     bool CanWeUse(Entity entity)
  78.     {
  79.         return entity != null && entity.Exists();
  80.     }
  81.  
  82.     void DisplayHelpTextThisFrame(string text)
  83.     {
  84.         Function.Call(Hash._SET_TEXT_COMPONENT_FORMAT, "STRING");
  85.         Function.Call(Hash._ADD_TEXT_COMPONENT_STRING, text);
  86.         Function.Call(Hash._DISPLAY_HELP_TEXT_FROM_STRING_LABEL, 0, false, true, -1);
  87.     }
  88. }
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