Abel_Software

GTA V - Native UI Template

Dec 27th, 2018
2,308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.47 KB | None | 0 0
  1. // Native UI Menu Template 3.0 - Abel Software
  2. // You must download and use Scripthook V Dot Net Reference and NativeUI Reference (LINKS AT BOTTOM OF THE TEMPLATE)
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7. using System.Linq;
  8. using System.Text;
  9. using GTA;
  10. using GTA.Native;
  11. using NativeUI;
  12.  
  13. public class NativeUITemplate : Script
  14. {
  15.     private Ped playerPed = Game.Player.Character;
  16.     private Player player = Game.Player;
  17.     private MenuPool _menuPool;
  18.  
  19.     //Here we will add the code to use a .INI file for your menu open key
  20.     ScriptSettings config;
  21.     Keys OpenMenu;
  22.  
  23.     //Now, we will add your sub menu, which in this case, will be player menu to change your player model.
  24.     public void PlayerModelMenu(UIMenu menu)
  25.     {
  26.         var playermodelmenu = _menuPool.AddSubMenu(menu, "Player Model Menu");
  27.         for (int i = 0; i < 1; i++) ;
  28.  
  29.         //We will change our player model to the male LSPD officer
  30.         var malecop = new UIMenuItem("Male LSPD Officer", "");
  31.         playermodelmenu.AddItem(malecop);
  32.         playermodelmenu.OnItemSelect += (sender, item, index) =>
  33.         {
  34.             if (item == malecop)
  35.             {
  36.                 Game.Player.ChangeModel("S_M_Y_COP_01");
  37.             }
  38.         };
  39.     }
  40.  
  41.     //Now, we will add your sub menu, which in this case, will be vehicle menu to spawn a car
  42.     public void VehicleMenu(UIMenu menu)
  43.     {
  44.         var vehiclemenu = _menuPool.AddSubMenu(menu, "Vehicle Spawning");
  45.         for (int i = 0; i < 1; i++) ;
  46.  
  47.         //For this example, we will be spawning the Adder
  48.         var adder = new UIMenuItem("Adder", "");
  49.         vehiclemenu.AddItem(adder);
  50.         vehiclemenu.OnItemSelect += (sender, item, index) =>
  51.         {
  52.             if (item == adder)
  53.             {
  54.                 Vehicle car = World.CreateVehicle("ADDER", Game.Player.Character.Position);
  55.                 Game.Player.Character.SetIntoVehicle(car, VehicleSeat.Driver);
  56.             }
  57.         };
  58.     }
  59.  
  60.     //Now, we will add your sub menu, which in this case, will be weapon menu to equip a weapon
  61.     public void WeaponMenu(UIMenu menu)
  62.     {
  63.         var weapons = _menuPool.AddSubMenu(menu, "Weapon Menu");
  64.         for (int i = 0; i < 1; i++) ;
  65.  
  66.         //For this example, we will equipping a flashlight, combat pistol, and pump shotgun
  67.         var newweapons = new UIMenuItem("Issue Weapons", "");
  68.         weapons.AddItem(newweapons);
  69.         weapons.OnItemSelect += (sender, item, index) =>
  70.         {
  71.             if (item == newweapons)
  72.             {
  73.                 Game.Player.Character.Weapons.Give((WeaponHash)Function.Call<int>(Hash.GET_HASH_KEY, "WEAPON_FLASHLIGHT"), 1, true, true); //Weapon Hash, Weapon Equipped, Ammo Loaded
  74.                 Game.Player.Character.Weapons.Give((WeaponHash)Function.Call<int>(Hash.GET_HASH_KEY, "WEAPON_COMBATPISTOL"), 9999, false, true);
  75.                 Game.Player.Character.Weapons.Give((WeaponHash)Function.Call<int>(Hash.GET_HASH_KEY, "WEAPON_PUMPSHOTGUN"), 9999, false, true);
  76.                 UI.Notify("~g~You have been issued weapons!"); //This notification will appear with green text above the radar
  77.                 UI.ShowSubtitle("~g~You have been issued weapons!"); //This notification will appear at the bottom of the screen with green text
  78.             }
  79.         };
  80.     }
  81.  
  82.     //Now, we will add an item that is not a sub menu item, but an individual item on the main menu screen (not inside a sub-menu)
  83.     public void ClearWantedLevel(UIMenu menu)
  84.     {
  85.         var wantedlevel = new UIMenuItem("Clear Wanted Level", "Clear your current wanted level.");
  86.         wantedlevel.SetRightBadge(UIMenuItem.BadgeStyle.Star);
  87.         menu.AddItem(wantedlevel);
  88.         menu.OnItemSelect += (sender, item, index) =>
  89.         {
  90.             if (item == wantedlevel)
  91.             {
  92.                 Game.Player.WantedLevel = 0;
  93.             }
  94.         };
  95.     }
  96.  
  97.     //Now we will add all of our sub menus into our main menu, and set the general information of the entire menu
  98.     public NativeUITemplate()
  99.     {
  100.         _menuPool = new MenuPool();
  101.         var mainMenu = new UIMenu("Native UI Template", "~b~Template by Abel Gaming! ~r~V 3.0");
  102.         _menuPool.Add(mainMenu);
  103.         PlayerModelMenu(mainMenu); //Here we add the Player Model Sub Menu
  104.         VehicleMenu(mainMenu); //Here we add the Vehicle Spawning Sub Menu
  105.         WeaponMenu(mainMenu); //Here we add the Weapon Sub Menu
  106.         ClearWantedLevel(mainMenu); //Added the item to the main menu screen
  107.         _menuPool.RefreshIndex();
  108.  
  109.         //We will now call from the .INI file for our controls
  110.         config = ScriptSettings.Load("scripts\\settings.ini");
  111.         OpenMenu = config.GetValue<Keys>("Options", "OpenMenu", Keys.F7); //The F7 key will be set my default, but the user can change the key
  112.  
  113.         //This code will run with every ms tick
  114.         Tick += (o, e) => _menuPool.ProcessMenus();
  115.  
  116.         //This code will open the menu
  117.         KeyDown += (o, e) =>
  118.         {
  119.             if (e.KeyCode == OpenMenu && !_menuPool.IsAnyMenuOpen()) // Our menu on/off switch
  120.                 mainMenu.Visible = !mainMenu.Visible;
  121.         };
  122.     }
  123. }
  124. //Useful Links
  125. //All Vehicles - https://pastebin.com/uTxZnhaN
  126. //All Player Models - https://pastebin.com/i5c1zA0W
  127. //All Weapons - https://pastebin.com/M3kD9pnJ
  128. //Native UI - https://gtaforums.com/topic/809284-net-nativeui/
  129. //GTA V ScriptHook V Dot Net - https://www.gta5-mods.com/tools/scripthookv-net
Advertisement
Add Comment
Please, Sign In to add comment