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;
- using System.Xml;
- public class KERS : Script
- {
- string ScriptName = "KERS for all cars";
- string ScriptVer = "1.0";
- float KERSEnergy;
- int GameTimeRef = Game.GameTime;
- bool BoostActive=false;
- List<Model> Cars = new List<Model>();
- bool KERSNotified = false;
- public KERS()
- {
- Tick += OnTick;
- string ConfigFile = @"scripts\\Kersconfig.xml";
- XmlDocument document = new XmlDocument();
- document.Load(ConfigFile);
- int pat = 0;
- while (document == null && pat < 500)
- {
- document.Load(ConfigFile);
- Script.Wait(0);
- }
- if (document == null)
- {
- UI.Notify("~o~KERS couldn't find the xml file.");
- return;
- }
- XmlElement root = document.DocumentElement;
- foreach (XmlElement e in root.SelectNodes("//model"))
- {
- Model car = e.InnerText;
- if(car.IsValid && car.IsVehicle)
- {
- Cars.Add(car);
- //UI.Notify("[KERS] Added "+car.ToString());
- }
- }
- }
- public static float ForwardSpeed(Entity ent)
- {
- return Function.Call<Vector3>(Hash.GET_ENTITY_SPEED_VECTOR, ent, true).Y;
- }
- void OnTick(object sender, EventArgs e)
- {
- if (GameTimeRef < Game.GameTime)
- {
- GameTimeRef = Game.GameTime + 100;
- if (BoostActive)
- {
- if (KERSEnergy > 0)
- {
- KERSEnergy--;
- KERSEnergy--;
- }
- else
- {
- DisplayHelpTextThisFrame("~b~KERS~w~ discharged.");
- BoostActive = false;
- }
- }
- }
- if (CanWeUse(Game.Player.Character.CurrentVehicle))
- {
- Vehicle veh = Game.Player.Character.CurrentVehicle;
- if (BoostActive)
- {
- veh.EngineTorqueMultiplier = 4;
- }
- if (Cars.Contains(veh.Model))
- {
- if (!KERSNotified)
- {
- DisplayHelpTextThisFrame("~b~KERS~w~ is available for this vehicle.");
- KERSNotified = true;
- }
- if (Game.IsControlPressed(2,GTA.Control.VehicleBrake) && !Game.IsControlPressed(2,GTA.Control.VehicleAccelerate) && veh.IsOnAllWheels && ForwardSpeed(veh)>5)
- {
- if (KERSEnergy < 100) KERSEnergy += 0.2f;
- }
- if(Game.IsControlJustReleased(2,GTA.Control.VehicleBrake))
- {
- if(KERSEnergy<100) DisplayHelpTextThisFrame("~b~KERS~w~ charged [" + Math.Round(KERSEnergy, 0).ToString() + "%].");
- else DisplayHelpTextThisFrame("~b~KERS~w~ charged [~g~" + Math.Round(KERSEnergy, 0).ToString() + "%~w~].~n~Press ~INPUT_CONTEXT~ to release it.");
- }
- if (KERSEnergy>0 && Game.IsControlJustPressed(2, GTA.Control.VehicleHorn))
- {
- DisplayHelpTextThisFrame("~b~KERS~w~ injected.");
- BoostActive = true;
- }
- }
- }
- else
- {
- if (KERSNotified) KERSNotified = false;
- if (KERSEnergy!=0) KERSEnergy = 0;
- if (BoostActive) BoostActive = false;
- }
- }
- 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);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement