Advertisement
Guest User

Menu

a guest
Feb 11th, 2021
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.63 KB | None | 0 0
  1. using GTA;
  2. using GTA.Math;
  3. using GTA.Native;
  4. using System;
  5. using System.Windows.Forms;
  6. using NativeUI;
  7. using System.Collections.Generic;
  8.  
  9. namespace Menu_for_bguard
  10. {
  11.     public class Menu_for_bguard : Script
  12.     {
  13.         public List<Blip> guardBlipOnce = new List<Blip>();
  14.         public List<Ped> guardSpawnOnce = new List<Ped>();
  15.         bool isTickActive;
  16.         Ped player = Game.Player.Character;
  17.         Ped pedGuard;
  18.         MenuPool modMenuPool;
  19.         UIMenu mainMenu;
  20.         ScriptSettings config;
  21.         Keys OpenMenu;
  22.  
  23.         public Menu_for_bguard()
  24.         {
  25.             this.Aborted += SingleBlipSpawn;
  26.             this.Aborted += SingleGuardSpawn;
  27.             Tick += onTick;
  28.             KeyDown += onKeyDown;
  29.             modMenuPool = new MenuPool();
  30.             mainMenu = new UIMenu("Guard Menu","Mod by Kieran_S");
  31.             modMenuPool.Add(mainMenu);
  32.             SetupGuardMenu(mainMenu);
  33.             SetupPedMenu(mainMenu);            
  34.             modMenuPool.RefreshIndex();
  35.             config = ScriptSettings.Load("scripts//guardmenu.ini");
  36.             OpenMenu = config.GetValue<Keys>("Options", "OpenMenu", OpenMenu);          
  37.         }
  38.         public void SetupPedMenu(UIMenu menu)
  39.         {
  40.             var setupPedMenu = modMenuPool.AddSubMenu(menu, "Guard Model Menu");
  41.             for (int i = 0; i < 1; i++) ;
  42.  
  43.             var MPros01 = new UIMenuItem("MPros01", "");
  44.             setupPedMenu.AddItem(MPros01);
  45.  
  46.             setupPedMenu.OnItemSelect += (sender, item, index) =>
  47.             {
  48.                 if (item == MPros01)
  49.                 {
  50.                     Function.Call(Hash.CHANGE_PLAYER_PED, player, pedGuard, false, false);
  51.                 }
  52.             };
  53.         }
  54.         public void SetupGuardMenu(UIMenu menu)
  55.         {
  56.             var guardSpawnMenu = modMenuPool.AddSubMenu(mainMenu, "Guard Spawn Menu");
  57.             for (int i = 0; i < 1; i++) ;
  58.  
  59.             var spawnGuardButton = new UIMenuItem("Spawn Guard");
  60.             guardSpawnMenu.AddItem(spawnGuardButton);
  61.  
  62.             var deleteGuardButton = new UIMenuItem("Delete Guard");
  63.             guardSpawnMenu.AddItem(deleteGuardButton);
  64.  
  65.             guardSpawnMenu.OnItemSelect += (sender, item, index) =>
  66.             {
  67.                 if (item == spawnGuardButton)
  68.                 {
  69.                     //turns on ontick
  70.                     isTickActive = true;
  71.  
  72.                     //spawn guard
  73.                     pedGuard = World.CreatePed(PedHash.MPros01, player.Position + (player.ForwardVector * 2.5f));
  74.                     guardSpawnOnce.Add(pedGuard);
  75.                     pedGuard.Task.LookAt(player);
  76.  
  77.                     //add guns to guard
  78.                     pedGuard.Weapons.Give(WeaponHash.AssaultRifle, 9999, false, false);
  79.                     pedGuard.Weapons.Give(WeaponHash.PumpShotgun, 9999, false, false);
  80.                     pedGuard.Weapons.Give(WeaponHash.Pistol, 9999, false, false);
  81.  
  82.                     //add guard to pedgroup
  83.                     player.CurrentPedGroup.Add(pedGuard, false);
  84.  
  85.                     //add blip to guard
  86.                     pedGuard.AddBlip();
  87.                     pedGuard.CurrentBlip.Sprite = BlipSprite.Standard;
  88.                     pedGuard.CurrentBlip.Color = BlipColor.Blue;
  89.                     pedGuard.CurrentBlip.Scale = 0.65f;
  90.                     pedGuard.CurrentBlip.Name = "Guard";
  91.                     pedGuard.CurrentBlip.IsShortRange = true;
  92.  
  93.                     //subtitle
  94.                     GTA.UI.Notify("You bodyguard has ~g~arrived");
  95.                 }
  96.                 if (item == deleteGuardButton)
  97.                 {
  98.                     pedGuard.Delete();
  99.                 }
  100.             };
  101.         }
  102.         private void onTick(object sender, EventArgs e)
  103.         {
  104.             if (modMenuPool != null && modMenuPool.IsAnyMenuOpen() == true)
  105.             { modMenuPool.ProcessMenus(); }
  106.  
  107.             startOfLoop:
  108.             if (isTickActive)
  109.             {
  110.                 //make sure script is not overloaded
  111.                 Wait(1000);
  112.  
  113.                 //delete guard if player goes to far and alert player
  114.                 if (!player.IsInRangeOf(pedGuard.Position, 500f)) pedGuard.Delete();
  115.                 if (!pedGuard.Exists()) UI.Notify("The guard was ~r~deleted");
  116.                 if (!pedGuard.Exists()) Wait(5000);
  117.                 Function.Call(Hash._REMOVE_NOTIFICATION);
  118.                 if (!pedGuard.Exists()) isTickActive = false;
  119.  
  120.                 //
  121.  
  122.                 //loop script to before isTickActive
  123.                 goto startOfLoop;
  124.             }
  125.         }
  126.         private void onKeyDown(object sender, KeyEventArgs e)
  127.         {
  128.             if (e.KeyCode == OpenMenu && !modMenuPool.IsAnyMenuOpen())
  129.                 mainMenu.Visible = !mainMenu.Visible;
  130.         }
  131.         public void DisplayHelpTextThisFrame(string text) // thanks to jedijosh
  132.         {
  133.             Function.Call(Hash._SET_TEXT_COMPONENT_FORMAT, "STRING");
  134.             Function.Call(Hash._ADD_TEXT_COMPONENT_STRING, text);
  135.             Function.Call(Hash._0x238FFE5C7B0498A6, 0, 0, 1, -1);
  136.         }
  137.         public void SingleBlipSpawn(object sender, EventArgs e) // make guard blip not dupe
  138.         {
  139.             foreach (Blip existingblip in guardBlipOnce)
  140.             {
  141.                 if (existingblip.Exists()) existingblip.Remove();
  142.             }
  143.         }
  144.         public void SingleGuardSpawn(object sender, EventArgs e) // make guard not dupe
  145.         {
  146.             foreach (Ped existingguard in guardSpawnOnce)
  147.             {
  148.                 if (existingguard.Exists()) existingguard.Delete();
  149.             }
  150.         }
  151.     }
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement