SHARE
TWEET

gta natives SET_INPUT_EVENT_SELECT example

Larph May 6th, 2018 503 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Windows.Forms;
  3. using GTA;
  4. using GTA.Native;
  5.  
  6.  
  7. public class ClickableInstuctionalButtons : Script
  8. {
  9.     private Scaleform scaleform = new Scaleform("instructional_buttons");
  10.     private bool inputRequest;
  11.  
  12.  
  13.     public ClickableInstuctionalButtons()
  14.     {
  15.         KeyUp += OnKeyUp;
  16.         Interval = 5;
  17.     }
  18.  
  19.     private void OnKeyUp(object sender, KeyEventArgs e)
  20.     {
  21.         if (e.KeyCode == Keys.F7)
  22.         {
  23.             if (!inputRequest)
  24.             {
  25.                 inputRequest = true;
  26.                 UpdateScaleform();
  27.                 Tick += InputRequestTick;
  28.             }
  29.         }
  30.     }
  31.  
  32.     private void InputRequestTick(object sender, EventArgs e)
  33.     {
  34.         // enable mouse cursor so user can click on buttons
  35.         Function.Call(Hash._SHOW_CURSOR_THIS_FRAME);
  36.         Function.Call(Hash.DISABLE_ALL_CONTROL_ACTIONS, 0);
  37.         // enable character/vehicle movement
  38.         Function.Call(Hash.ENABLE_CONTROL_ACTION, 0, 30, 1);
  39.         Function.Call(Hash.ENABLE_CONTROL_ACTION, 0, 31, 1);
  40.         Function.Call(Hash.ENABLE_CONTROL_ACTION, 0, 59, 1);
  41.         Function.Call(Hash.ENABLE_CONTROL_ACTION, 0, 60, 1);
  42.         Function.Call(Hash.ENABLE_CONTROL_ACTION, 0, 71, 1);
  43.         Function.Call(Hash.ENABLE_CONTROL_ACTION, 0, 72, 1);
  44.         // enable pause menu
  45.         Function.Call(Hash.ENABLE_CONTROL_ACTION, 2, 199, 1);
  46.         Function.Call(Hash.ENABLE_CONTROL_ACTION, 2, 200, 1);
  47.         // enable CursorAccept (left click) oherwise user can't click on buttons
  48.         Function.Call(Hash.ENABLE_CONTROL_ACTION, 0, 237, 1);
  49.  
  50.         scaleform.Render2D();
  51.  
  52.         if (Game.IsControlJustPressed(0, GTA.Control.CursorAccept))
  53.         {
  54.             Function.Call(Hash._PUSH_SCALEFORM_MOVIE_FUNCTION, scaleform.Handle, "SET_INPUT_EVENT_SELECT");
  55.             int handle = Function.Call<int>(Hash._POP_SCALEFORM_MOVIE_FUNCTION);
  56.             /*
  57.              * no need for the return value of Hash._0x2DE7EFA66B906036,
  58.              * but have to do this so that the scaleform doesn't get broken
  59.              * after multiple SET_INPUT_EVENT_SELECT commands !!
  60.              * In the scripts it is used to get a value, but I haven't been able
  61.              * to duplicate that, cuz Hash._0x768FF8961BA904D6 has never
  62.              * returned true, so Hash._0x2DE7EFA66B906036 never even gets executed.
  63.              */
  64.             if (Function.Call<bool>(Hash._0x768FF8961BA904D6, handle)) Function.Call<int>(Hash._0x2DE7EFA66B906036, handle);
  65.         }
  66.  
  67.         // user accepted/canceled with keyboard
  68.         if (Game.IsControlJustPressed(0, GTA.Control.FrontendAccept))
  69.         {
  70.             Tick -= InputRequestTick;
  71.             inputRequest = false;
  72.             // do stuff on accept
  73.             UI.ShowSubtitle("GTA.Control.FrontendAccept");
  74.         }
  75.         else if (Game.IsControlJustPressed(0, GTA.Control.FrontendCancel))
  76.         {
  77.             Tick -= InputRequestTick;
  78.             inputRequest = false;
  79.             // do stuff on cancel
  80.             UI.ShowSubtitle("GTA.Control.FrontendCancel");
  81.         }
  82.         // user accepted/canceled by clicking on one of the Scaleform Buttons !!
  83.         // (or the corresponding controls if you just try them all, cuz you won't know them)
  84.         else if (Game.IsControlJustPressed(0, GTA.Control.PhoneUp))
  85.         {
  86.             Tick -= InputRequestTick;
  87.             inputRequest = false;
  88.             // do stuff on accept
  89.             UI.ShowSubtitle("GTA.Control.PhoneUp");
  90.         }
  91.         else if (Game.IsControlJustPressed(0, GTA.Control.PhoneDown))
  92.         {
  93.             Tick -= InputRequestTick;
  94.             inputRequest = false;
  95.             // do stuff on cancel
  96.             UI.ShowSubtitle("GTA.Control.PhoneDown");
  97.         }
  98.     }
  99.  
  100.     private void UpdateScaleform()
  101.     {
  102.         while (!scaleform.IsLoaded) Wait(5);
  103.         scaleform.CallFunction("CLEAR_ALL");
  104.         scaleform.CallFunction("TOGGLE_MOUSE_BUTTONS", false);
  105.         SetInputDataSlot(0, "MO_YES", GTA.Control.FrontendAccept, GTA.Control.PhoneUp);
  106.         SetInputDataSlot(1, "MO_NO", GTA.Control.FrontendCancel, GTA.Control.PhoneDown);
  107.         scaleform.CallFunction("DRAW_INSTRUCTIONAL_BUTTONS", -1);
  108.     }
  109.  
  110.     /*
  111.      * You can even have the Scaleform return different control values
  112.      * if you'd want that, using ScaleformButtonReturnValue !
  113.      * but normaly you just want one control value for both PARAMETERs
  114.      */
  115.     private void SetInputDataSlot(int slot, string label, GTA.Control control, GTA.Control ScaleformButtonReturnValue)
  116.     {
  117.         Function.Call(Hash._PUSH_SCALEFORM_MOVIE_FUNCTION, scaleform.Handle, "SET_DATA_SLOT");
  118.         Function.Call(Hash._PUSH_SCALEFORM_MOVIE_FUNCTION_PARAMETER_INT, slot);
  119.         Function.Call(Hash._0xE83A3E3557A56640, Function.Call<string>(Hash._GET_CONTROL_ACTION_NAME, 2, (int)control, 1));
  120.         Function.Call(Hash._BEGIN_TEXT_COMPONENT, label);
  121.         Function.Call(Hash._END_TEXT_COMPONENT);
  122.         if (Function.Call<bool>(Hash.IS_PC_VERSION))
  123.         {
  124.             Function.Call(Hash._PUSH_SCALEFORM_MOVIE_FUNCTION_PARAMETER_BOOL, true);
  125.             Function.Call(Hash._PUSH_SCALEFORM_MOVIE_FUNCTION_PARAMETER_INT, (int)ScaleformButtonReturnValue);
  126.         }
  127.         Function.Call(Hash._POP_SCALEFORM_MOVIE_FUNCTION_VOID);
  128.     }
  129.  
  130.     protected override void Dispose(bool disposenow)
  131.     {
  132.         if (disposenow)
  133.         {
  134.             scaleform.Unload();
  135.         }
  136.     }
  137. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top