Advertisement
Eddlm

AutoTurbo sourcecode

Jan 29th, 2018
519
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.75 KB | None | 0 0
  1. using GTA;
  2. using GTA.Native;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Windows.Forms;
  7.  
  8.  
  9.  
  10. public class AutoTurbo : Script
  11. {
  12.     string ScriptName = "AutoTurbo";
  13.     string ScriptVer = "1.0";
  14.     int GametimeRef = 0;
  15.     bool Debug = false;
  16.     bool AllCars = false;
  17.     public AutoTurbo()
  18.     {
  19.         Tick += OnTick;
  20.  
  21.  
  22.         LoadSettings(false);
  23.     }
  24.  
  25.     void OnTick(object sender, EventArgs e)
  26.     {
  27.         if(WasCheatStringJustEntered("reload autoturbo"))
  28.         {
  29.             Models.Clear();
  30.             LoadSettings(true);
  31.         }
  32.         if (GametimeRef < Game.GameTime)
  33.         {
  34.             GametimeRef = Game.GameTime + 1000;
  35.  
  36.             if (AllCars)
  37.             {
  38.                 foreach(Vehicle v in World.GetAllVehicles())
  39.                 {
  40.                     if (Models.Contains(v.Model))
  41.                     {
  42.                         if (!v.IsToggleModOn(VehicleToggleMod.Turbo))
  43.                         {
  44.                             v.ToggleMod(VehicleToggleMod.Turbo, true);
  45.                             if (Debug) UI.Notify("~b~[AutoTurbo]" + v.FriendlyName + " Turbo has been enabled");
  46.                         }
  47.                     }
  48.                 }
  49.             }
  50.             else
  51.             {
  52.                 if (CanWeUse(Game.Player.Character.CurrentVehicle))
  53.                 {
  54.                     Vehicle v = Game.Player.Character.CurrentVehicle;
  55.                     if (Models.Contains(v.Model))
  56.                     {
  57.                         if (!v.IsToggleModOn(VehicleToggleMod.Turbo))
  58.                         {
  59.                             v.ToggleMod(VehicleToggleMod.Turbo, true);
  60.                             if (Debug) UI.Notify("~b~[AutoTurbo]" + v.FriendlyName + " Turbo has been enabled");
  61.                         }
  62.                     }
  63.                 }
  64.             }
  65.         }
  66.     }
  67.     public static bool WasCheatStringJustEntered(string cheat)
  68.     {
  69.         return Function.Call<bool>(Hash._0x557E43C447E700A8, Game.GenerateHash(cheat));
  70.     }
  71.  
  72.     protected override void Dispose(bool dispose)
  73.     {
  74.         base.Dispose(dispose);
  75.     }
  76.  
  77.  
  78.     List<Model> Models = new List<Model>();
  79.  
  80.     /// TOOLS ///
  81.     void LoadSettings(bool debug)
  82.     {
  83.         if (File.Exists(@"scripts\\AutoTurbo.ini"))
  84.         {
  85.             if(debug) UI.Notify("Loading AutoTurbo models:");
  86.             ScriptSettings config = ScriptSettings.Load(@"scripts\SCRIPTNAME.ini");
  87.  
  88.             foreach (string value in config.GetAllValues("GENERAL_SETTINGS", "model"))
  89.             {
  90.                 Models.Add(value);
  91.  
  92.                 if (debug) UI.Notify(value+ " loaded");
  93.             }
  94.             AllCars = config.GetValue<bool>("GENERAL_SETTINGS", "AllCars", false);
  95.             Debug = config.GetValue<bool>("GENERAL_SETTINGS", "Debug", false);
  96.  
  97.         }
  98.         else
  99.         {
  100.             WarnPlayer(ScriptName + " " + ScriptVer, "SCRIPT RESET", "~r~AutoTurbo can't find AutoTurbo.ini. All settings default.");
  101.         }
  102.     }
  103.  
  104.     void WarnPlayer(string script_name, string title, string message)
  105.     {
  106.         Function.Call(Hash._SET_NOTIFICATION_TEXT_ENTRY, "STRING");
  107.         Function.Call(Hash._ADD_TEXT_COMPONENT_STRING, message);
  108.         Function.Call(Hash._SET_NOTIFICATION_MESSAGE, "CHAR_SOCIAL_CLUB", "CHAR_SOCIAL_CLUB", true, 0, title, "~b~" + script_name);
  109.     }
  110.  
  111.     bool CanWeUse(Entity entity)
  112.     {
  113.         return entity != null && entity.Exists();
  114.     }
  115.  
  116.     void DisplayHelpTextThisFrame(string text)
  117.     {
  118.         Function.Call(Hash._SET_TEXT_COMPONENT_FORMAT, "STRING");
  119.         Function.Call(Hash._ADD_TEXT_COMPONENT_STRING, text);
  120.         Function.Call(Hash._DISPLAY_HELP_TEXT_FROM_STRING_LABEL, 0, false, true, -1);
  121.     }
  122.  
  123.  
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement