Guest User

Menu Example

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