SAC 28 Posted December 26, 2021 Share Posted December 26, 2021 Hi, Can anyone please teach me, or point me to some relevant reading materials, how to script a controller with a prompt? Thx Quote My Fallout 4 and Skyrim mods: SAC - LoversLab Link to comment Share on other sites More sharing options...
crossed99 43 Posted December 27, 2021 Share Posted December 27, 2021 Maybe it's me, but I don't really understand. What are you trying to do? Quote Link to comment Share on other sites More sharing options...
SAC 28 Posted December 27, 2021 Author Share Posted December 27, 2021 3 minutes ago, crossed99 said: Maybe it's me, but I don't really understand. What are you trying to do? Display a prompt when certain conditions are met, then execute a script when the relevant key is pressed. Similar to when you are near a body and you get a prompt "E to loot" Quote My Fallout 4 and Skyrim mods: SAC - LoversLab Link to comment Share on other sites More sharing options...
crossed99 43 Posted December 27, 2021 Share Posted December 27, 2021 (edited) void registerPrompt(int& prompt, const char* input, const char* name, bool toggle, bool addToGroup, Entity entity) { prompt = HUD::_UIPROMPT_REGISTER_BEGIN(); HUD::_UIPROMPT_SET_CONTROL_ACTION(prompt, MISC::GET_HASH_KEY(input)); HUD::_UIPROMPT_SET_TEXT(prompt, MISC::VAR_STRING(10, "LITERAL_STRING", name)); HUD::_UIPROMPT_SET_HOLD_MODE(prompt, 1); if (addToGroup) { int group = HUD::_UIPROMPT_GET_GROUP_ID_FOR_TARGET_ENTITY(entity); HUD::_UIPROMPT_SET_GROUP(prompt, group, 0); } HUD::_UIPROMPT_REGISTER_END(prompt); togglePrompt(prompt, toggle); } void togglePrompt(int prompt, bool enable) { HUD::_UIPROMPT_SET_VISIBLE(prompt, enable); HUD::_UIPROMPT_SET_ENABLED(prompt, enable); } I do it like this, you can use it like: static int myPrompt{}; registerPrompt(myPrompt, "INPUT_SPRINT", "My Prompts Name", false, true, *example ped*); Ped target; PLAYER::GET_PLAYER_INTERACTION_TARGET_ENTITY(PLAYER::PLAYER_ID(), &target, 1, 1); if (target == *example ped*) // if you're targeting your example ped you reistered the prompt on togglePromt(myPrompt, true); else togglePromt(myPrompt, false); Adding it to a ped or other entity is optional. Depending on what you do there are better ways to do the toggling.. Btw I have a few of my mods source code shared on their pages, you can find stuff like this in them. edit: I edited the input, it was supposed to be "INPUT_SPRINT" Edited December 27, 2021 by crossed99 1 1 Quote Link to comment Share on other sites More sharing options...
KMM 0 Posted February 10, 2022 Share Posted February 10, 2022 How would you do this with Rage Plugin Hook? I'm trying to learn how to create prompts. Quote Link to comment Share on other sites More sharing options...
LMS 673 Posted February 10, 2022 Share Posted February 10, 2022 Very similar, I don't think the prompt is exposed as managed classes. You would hence manually call the natives shown above via Game.CallNative. Quote Link to comment Share on other sites More sharing options...
KMM 0 Posted February 11, 2022 Share Posted February 11, 2022 (edited) Hi, I'm trying the following code but cannot get a prompt to appear. For testing purposes, I have the script setup to assign a prompt to the player free aiming entity target, after hitting the "G" key, so that the next time the entity is targeted the prompt should appear. namespace RDR2Mod { using System; using System.Windows.Forms; using Rage; internal static class RDR2Mod { // These variables are shared between all functions! static int prompt; static Entity target; public static void Start() { // Announce us to the world :) Game.DisplayHelp("RDR2Mod Loaded."); } public static void Process() { if (Game.CallNative<bool>((ulong)natives.PLAYER.IS_PLAYER_TARGETTING_ANYTHING, Game.LocalPlayer)) { if (Rage.Game.LocalPlayer.Target == target) { togglePrompt(prompt, true); } } else { if (Game.LocalPlayer.IsFreeAimingAtAnyEntity) { if (TempApi.WasKeyJustPressed(Keys.G)) { target = Rage.Game.LocalPlayer.FreeAimingTarget; registerPrompt(prompt, "INPUT_SPRINT", "TEST", false, true, target); } } } } public static void End() { // You would free any resources here when the plugin is being unloaded. } public static void registerPrompt(int prompt, string input, string name, bool toggle, bool addToGroup, Entity entity) { prompt = Rage.Game.CallNative<int>((ulong)natives.HUD._UIPROMPT_REGISTER_BEGIN); Rage.Game.CallNative((ulong)natives.HUD._UIPROMPT_SET_CONTROL_ACTION, prompt, natives.INPUTS.INPUT_SPRINT); string promptText = Game.CallNative<string>((ulong)natives.MISC._CREATE_VAR_STRING, 10, "LITERAL_STRING", name); Rage.Game.CallNative((ulong)natives.HUD._UIPROMPT_SET_TEXT, prompt, promptText); Rage.Game.CallNative((ulong)natives.HUD._UIPROMPT_SET_HOLD_MODE, prompt, 1); Rage.Game.CallNative((ulong)natives.HUD._UIPROMPT_SET_PRIORITY, prompt, 1); Rage.Game.CallNative((ulong)natives.HUD._UIPROMPT_SET_TRANSPORT_MODE, prompt, 1); Rage.Game.CallNative((ulong)natives.HUD._UIPROMPT_SET_ATTRIBUTE, prompt, 18, 1); Rage.Game.CallNative((ulong)natives.HUD._UIPROMPT_SET_STANDARD_MODE, prompt, 1); Rage.Game.CallNative((ulong)natives.HUD._UIPROMPT_REGISTER_END, prompt); togglePrompt(prompt, true); if (addToGroup) { ulong group = Rage.Game.CallNative<ulong>((ulong)natives.HUD._UIPROMPT_GET_GROUP_ID_FOR_TARGET_ENTITY, entity); Rage.Game.CallNative((ulong)natives.HUD._UIPROMPT_SET_GROUP, prompt, group, 0); } } public static void togglePrompt(int prompt, bool enable) { Rage.Game.CallNative((ulong)natives.HUD._UIPROMPT_SET_VISIBLE, prompt, enable); Rage.Game.CallNative((ulong)natives.HUD._UIPROMPT_SET_ENABLED, prompt, enable); } } } Edited February 11, 2022 by KMM Quote Link to comment Share on other sites More sharing options...
LMS 673 Posted February 11, 2022 Share Posted February 11, 2022 Try changing the return type for _CREATE_VAR_STRING to long. String is a managed type and cannot be created from an unmanaged pointer like that. Quote Link to comment Share on other sites More sharing options...
KMM 0 Posted February 15, 2022 Share Posted February 15, 2022 (edited) @LMS Thank you for your help! This worked perfectly! How would I run a script once the prompt has been activated? For example, after holding the "INPUT_SPRINT" key run a particular function in the script. I have tried using _UIPROMPT_HAS_HOLD_MODE_COMPLETED but have had no luck. Edited February 15, 2022 by KMM Additional Info Quote Link to comment Share on other sites More sharing options...
LMS 673 Posted February 16, 2022 Share Posted February 16, 2022 If it is not hold mode, you want to call _PROMPT_HAS_STANDARD_MODE_COMPLETED. Quote Link to comment Share on other sites More sharing options...
KMM 0 Posted February 21, 2022 Share Posted February 21, 2022 Hi, I've updated my code to the following but I'm still not having any luck. The prompt appears correctly but I am unable to trigger a script once a button is pressed. I've also tried using _UIPROMPT_IS_VALID for testing purposes and it returns false. namespace RDR2Mod { using System; using System.Windows.Forms; using Rage; internal static class RDR2Mod { // These variables are shared between all functions! static int prompt; static Entity target; public static void Start() { // Announce us to the world :) Game.DisplayHelp("RDR2Mod Loaded."); } public static void Process() { if (Game.CallNative<bool>((ulong)Natives.HUD._UIPROMPT_IS_ACTIVE, prompt)) { if (Rage.Game.CallNative<bool>((ulong)Natives.HUD._UIPROMPT_HAS_STANDARD_MODE_COMPLETED, prompt)) { Game.DisplayHelp("ACTIVE PROMPT"); } } if (Game.CallNative<bool>((ulong)Natives.PLAYER.IS_PLAYER_TARGETTING_ANYTHING, Game.LocalPlayer)) { if (Rage.Game.LocalPlayer.Target == target) { togglePrompt(prompt, true); } } else { if (Game.LocalPlayer.IsFreeAimingAtAnyEntity) { if (TempApi.WasKeyJustPressed(Keys.G)) { target = Rage.Game.LocalPlayer.FreeAimingTarget; Game.DisplayHelp(Rage.Game.CallNative<ulong>((ulong)Natives.HUD._UIPROMPT_GET_GROUP_ID_FOR_TARGET_ENTITY, target).ToString()); Game.CallNative((ulong)Natives.HUD._UIPROMPT_DELETE, prompt); registerPrompt(prompt, "INPUT_SPRINT", "TEST", false, true, target); } } } } public static void End() { // You would free any resources here when the plugin is being unloaded. } public static void registerPrompt(int prompt, string input, string name, bool toggle, bool addToGroup, Entity entity) { prompt = Rage.Game.CallNative<int>((ulong)Natives.HUD._UIPROMPT_REGISTER_BEGIN); ulong inputHash = Rage.Game.CallNative<ulong>((ulong)Natives.MISC.GET_HASH_KEY, input); Rage.Game.CallNative((ulong)Natives.HUD._UIPROMPT_SET_CONTROL_ACTION, prompt, inputHash); long promptText = Game.CallNative<long>((ulong)Natives.MISC._CREATE_VAR_STRING, 10, "LITERAL_STRING", name); Rage.Game.CallNative((ulong)Natives.HUD._UIPROMPT_SET_TEXT, prompt, promptText); //Rage.Game.CallNative((ulong)Natives.HUD._UIPROMPT_SET_HOLD_MODE, prompt, 1); Rage.Game.CallNative((ulong)Natives.HUD._UIPROMPT_SET_PRIORITY, prompt, 1); Rage.Game.CallNative((ulong)Natives.HUD._UIPROMPT_SET_TRANSPORT_MODE, prompt, 1); Rage.Game.CallNative((ulong)Natives.HUD._UIPROMPT_SET_ATTRIBUTE, prompt, 18, 1); Rage.Game.CallNative((ulong)Natives.HUD._UIPROMPT_SET_STANDARD_MODE, prompt, 1); Rage.Game.CallNative((ulong)Natives.HUD._UIPROMPT_REGISTER_END, prompt); togglePrompt(prompt, true); if (addToGroup) { ulong group = Rage.Game.CallNative<ulong>((ulong)Natives.HUD._UIPROMPT_GET_GROUP_ID_FOR_TARGET_ENTITY, entity); Rage.Game.CallNative((ulong)Natives.HUD._UIPROMPT_SET_GROUP, prompt, group, 0); } } public static void togglePrompt(int prompt, bool enable) { Rage.Game.CallNative((ulong)Natives.HUD._UIPROMPT_SET_VISIBLE, prompt, enable); Rage.Game.CallNative((ulong)Natives.HUD._UIPROMPT_SET_ENABLED, prompt, enable); } } } Quote Link to comment Share on other sites More sharing options...
LMS 673 Posted February 21, 2022 Share Posted February 21, 2022 Not sure why it is not valid, but try passing another parameter (0) to the standard mode completion call. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.