Abel_Software

GTA IV C# Modding: Mod Menu Example

Nov 28th, 2015
656
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.83 KB | None | 0 0
  1. //In this script, I will show you a template for a mod menu! Feel free to use how you want!
  2.  
  3. namespace MenuExample
  4. {
  5.     using GTA;
  6.     using GTA.Native;
  7.     using System;
  8.     using System.Drawing;
  9.     using System.Windows.Forms;
  10.  
  11.     public class Main : Script
  12.     {
  13.         private bool isMenuOn;
  14.         private Keys menuDownKey;
  15.         private int menuSelection;
  16.         private Keys menuUpKey;
  17.         private Keys selectionKey;
  18.         private float spacing = (((float) Game.Resolution.Height) / 5f);
  19.         private Keys toggleMenuKey;
  20.         private float x = (Game.Resolution.Width * 0.1f);
  21.         private float y = (Game.Resolution.Height * 0.1f);
  22.  
  23.         public Main()
  24.         {
  25.             this.toggleMenuKey = base.Settings.GetValueKey("TOGGLE_MENU_KEY", Keys.F1);
  26.             this.selectionKey = base.Settings.GetValueKey("SELECTION_KEY", Keys.Enter);
  27.             this.menuUpKey = base.Settings.GetValueKey("MENU_UP__KEY", Keys.PageUp);
  28.             this.menuDownKey = base.Settings.GetValueKey("MENU_DOWN_KEY", Keys.Next);
  29.             base.BindKey(this.toggleMenuKey, false, false, false, new KeyPressDelegate(this.ToggleMenu));
  30.         }
  31.  
  32.         private void Crush()
  33.         {
  34.             Function.Call("PRINT_STRING_WITH_LITERAL_STRING_NOW", new Parameter[] { "STRING", "Oh My Heart!", 0xbb8, 1 });
  35.             base.Player.Character.Task.HandsUp(0xbb8);
  36.             base.Wait(0xbb8);
  37.             base.Player.Character.Die();
  38.         }
  39.  
  40.         private void Destroy()
  41.         {
  42.             Function.Call("PRINT_STRING_WITH_LITERAL_STRING_NOW", new Parameter[] { "STRING", "no rocket for you but there is a helicopter", 0xbb8, 1 });
  43.             World.CreateVehicle("MAVERICK", base.Player.Character.Position.Around(10f));
  44.         }
  45.  
  46.         private void Kill()
  47.         {
  48.             Function.Call("PRINT_STRING_WITH_LITERAL_STRING_NOW", new Parameter[] { "STRING", "What i've Eaten?", 0xbb8, 1 });
  49.             base.Player.Character.MakeProofTo(false, false, true, true, false);
  50.             World.AddExplosion(base.Player.Character.Position, ExplosionType.Default, 9999f);
  51.             if (base.Player.Character.HeightAboveGround == 0f)
  52.             {
  53.                 base.Player.Character.MakeProofTo(false, false, false, false, false);
  54.             }
  55.         }
  56.  
  57.         private void Menu_KeyDown(object sender, GTA.KeyEventArgs e)
  58.         {
  59.             if (e.Key == this.menuUpKey)
  60.             {
  61.                 this.menuSelection--;
  62.                 this.menuSelection = (this.menuSelection < 0) ? 2 : this.menuSelection;
  63.             }
  64.             if (e.Key == this.menuDownKey)
  65.             {
  66.                 this.menuSelection++;
  67.                 this.menuSelection = (this.menuSelection > 2) ? 0 : this.menuSelection;
  68.             }
  69.             if (e.Key == this.selectionKey)
  70.             {
  71.                 switch (this.menuSelection)
  72.                 {
  73.                     case 0:
  74.                         this.Crush();
  75.                         break;
  76.  
  77.                     case 1:
  78.                         this.Kill();
  79.                         break;
  80.  
  81.                     case 2:
  82.                         this.Destroy();
  83.                         break;
  84.  
  85.                     case 3:
  86.                         this.Spawn_Turismo();
  87.                         break;
  88.                 }
  89.             }
  90.         }
  91.  
  92.         private void Menu_PerFrameDrawing(object sender, GraphicsEventArgs e)
  93.         {
  94.             e.Graphics.DrawText("Critic Arrest", this.x, this.y, (this.menuSelection == 0) ? Color.Red : Color.White);
  95.             e.Graphics.DrawText("Mega Fart", this.x, (float) (this.y + this.spacing), (this.menuSelection == 1) ? Color.Red : Color.White);
  96.             e.Graphics.DrawText("Rocket", this.x, (float) (this.y + (this.spacing * 2f)), (this.menuSelection == 2) ? Color.Red : Color.White);
  97.             e.Graphics.DrawText("Turismo", this.x, (float) (this.y + (this.spacing * 3f)), (this.menuSelection == 3) ? Color.Red : Color.White);
  98.         }
  99.  
  100.         private void Spawn_Turismo()
  101.         {
  102.             Function.Call("PRINT_STRING_WITH_LITERAL_STRING_NOW", new Parameter[] { "STRING", "My Boy,here it is", 0xbb8, 1 });
  103.             World.CreateVehicle("TURISMO", base.Player.Character.Position.Around(10f));
  104.         }
  105.  
  106.         private void ToggleMenu()
  107.         {
  108.             this.isMenuOn = !this.isMenuOn;
  109.             if (this.isMenuOn)
  110.             {
  111.                 base.PerFrameDrawing += new GraphicsEventHandler(this.Menu_PerFrameDrawing);
  112.                 base.KeyDown += new GTA.KeyEventHandler(this.Menu_KeyDown);
  113.             }
  114.             else
  115.             {
  116.                 base.PerFrameDrawing -= new GraphicsEventHandler(this.Menu_PerFrameDrawing);
  117.                 base.KeyDown -= new GTA.KeyEventHandler(this.Menu_KeyDown);
  118.             }
  119.         }
  120.     }
  121. }
  122.  
  123. //See my profile for more!
Advertisement
Add Comment
Please, Sign In to add comment