Jump to content

How to script a controller with a prompt


SAC
 Share

Recommended Posts

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"

 

My Fallout 4 and Skyrim mods: SAC - LoversLab

 

Link to comment
Share on other sites

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 by crossed99
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

  • 1 month later...

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 by KMM
Link to comment
Share on other sites

@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 by KMM
Additional Info
Link to comment
Share on other sites

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);
            
        }

    }
}

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...