Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Windows.Forms;
- using GTA;
- using GTA.Native;
- public class ClickableInstuctionalButtons : Script
- {
- private Scaleform scaleform = new Scaleform("instructional_buttons");
- private bool inputRequest;
- public ClickableInstuctionalButtons()
- {
- KeyUp += OnKeyUp;
- Interval = 5;
- }
- private void OnKeyUp(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.F7)
- {
- if (!inputRequest)
- {
- inputRequest = true;
- UpdateScaleform();
- Tick += InputRequestTick;
- }
- }
- }
- private void InputRequestTick(object sender, EventArgs e)
- {
- // enable mouse cursor so user can click on buttons
- Function.Call(Hash._SHOW_CURSOR_THIS_FRAME);
- Function.Call(Hash.DISABLE_ALL_CONTROL_ACTIONS, 0);
- // enable character/vehicle movement
- Function.Call(Hash.ENABLE_CONTROL_ACTION, 0, 30, 1);
- Function.Call(Hash.ENABLE_CONTROL_ACTION, 0, 31, 1);
- Function.Call(Hash.ENABLE_CONTROL_ACTION, 0, 59, 1);
- Function.Call(Hash.ENABLE_CONTROL_ACTION, 0, 60, 1);
- Function.Call(Hash.ENABLE_CONTROL_ACTION, 0, 71, 1);
- Function.Call(Hash.ENABLE_CONTROL_ACTION, 0, 72, 1);
- // enable pause menu
- Function.Call(Hash.ENABLE_CONTROL_ACTION, 2, 199, 1);
- Function.Call(Hash.ENABLE_CONTROL_ACTION, 2, 200, 1);
- // enable CursorAccept (left click) oherwise user can't click on buttons
- Function.Call(Hash.ENABLE_CONTROL_ACTION, 0, 237, 1);
- scaleform.Render2D();
- if (Game.IsControlJustPressed(0, GTA.Control.CursorAccept))
- {
- Function.Call(Hash._PUSH_SCALEFORM_MOVIE_FUNCTION, scaleform.Handle, "SET_INPUT_EVENT_SELECT");
- int handle = Function.Call<int>(Hash._POP_SCALEFORM_MOVIE_FUNCTION);
- /*
- * no need for the return value of Hash._0x2DE7EFA66B906036,
- * but have to do this so that the scaleform doesn't get broken
- * after multiple SET_INPUT_EVENT_SELECT commands !!
- * In the scripts it is used to get a value, but I haven't been able
- * to duplicate that, cuz Hash._0x768FF8961BA904D6 has never
- * returned true, so Hash._0x2DE7EFA66B906036 never even gets executed.
- */
- if (Function.Call<bool>(Hash._0x768FF8961BA904D6, handle)) Function.Call<int>(Hash._0x2DE7EFA66B906036, handle);
- }
- // user accepted/canceled with keyboard
- if (Game.IsControlJustPressed(0, GTA.Control.FrontendAccept))
- {
- Tick -= InputRequestTick;
- inputRequest = false;
- // do stuff on accept
- UI.ShowSubtitle("GTA.Control.FrontendAccept");
- }
- else if (Game.IsControlJustPressed(0, GTA.Control.FrontendCancel))
- {
- Tick -= InputRequestTick;
- inputRequest = false;
- // do stuff on cancel
- UI.ShowSubtitle("GTA.Control.FrontendCancel");
- }
- // user accepted/canceled by clicking on one of the Scaleform Buttons !!
- // (or the corresponding controls if you just try them all, cuz you won't know them)
- else if (Game.IsControlJustPressed(0, GTA.Control.PhoneUp))
- {
- Tick -= InputRequestTick;
- inputRequest = false;
- // do stuff on accept
- UI.ShowSubtitle("GTA.Control.PhoneUp");
- }
- else if (Game.IsControlJustPressed(0, GTA.Control.PhoneDown))
- {
- Tick -= InputRequestTick;
- inputRequest = false;
- // do stuff on cancel
- UI.ShowSubtitle("GTA.Control.PhoneDown");
- }
- }
- private void UpdateScaleform()
- {
- while (!scaleform.IsLoaded) Wait(5);
- scaleform.CallFunction("CLEAR_ALL");
- scaleform.CallFunction("TOGGLE_MOUSE_BUTTONS", false);
- SetInputDataSlot(0, "MO_YES", GTA.Control.FrontendAccept, GTA.Control.PhoneUp);
- SetInputDataSlot(1, "MO_NO", GTA.Control.FrontendCancel, GTA.Control.PhoneDown);
- scaleform.CallFunction("DRAW_INSTRUCTIONAL_BUTTONS", -1);
- }
- /*
- * You can even have the Scaleform return different control values
- * if you'd want that, using ScaleformButtonReturnValue !
- * but normaly you just want one control value for both PARAMETERs
- */
- private void SetInputDataSlot(int slot, string label, GTA.Control control, GTA.Control ScaleformButtonReturnValue)
- {
- Function.Call(Hash._PUSH_SCALEFORM_MOVIE_FUNCTION, scaleform.Handle, "SET_DATA_SLOT");
- Function.Call(Hash._PUSH_SCALEFORM_MOVIE_FUNCTION_PARAMETER_INT, slot);
- Function.Call(Hash._0xE83A3E3557A56640, Function.Call<string>(Hash._GET_CONTROL_ACTION_NAME, 2, (int)control, 1));
- Function.Call(Hash._BEGIN_TEXT_COMPONENT, label);
- Function.Call(Hash._END_TEXT_COMPONENT);
- if (Function.Call<bool>(Hash.IS_PC_VERSION))
- {
- Function.Call(Hash._PUSH_SCALEFORM_MOVIE_FUNCTION_PARAMETER_BOOL, true);
- Function.Call(Hash._PUSH_SCALEFORM_MOVIE_FUNCTION_PARAMETER_INT, (int)ScaleformButtonReturnValue);
- }
- Function.Call(Hash._POP_SCALEFORM_MOVIE_FUNCTION_VOID);
- }
- protected override void Dispose(bool disposenow)
- {
- if (disposenow)
- {
- scaleform.Unload();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement