Skip to content
View in the app

A better way to browse. Learn more.

RDR2Mods.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Making NPCs speak..? [SOLVED]

You're viewing a summary of the most helpful posts in this topic — about 14 minutes of reading instead of 764 minutes for all 51 posts.

Featured Replies

I was wondering if anybody knew how to make NPCs talk.

I have been searching the game files with OpenIV and have found some speech samples I would like to use, but have no idea how.

Under "x64\audio\sfx" there are multiple PED_XX.rpf files which hold awc files (for each NPC type like "white townfolk", there is a file) which again hold a lot of speech files. Those speech files have the same hashes/names throughout the different NPC types, so there must be a generic option of calling them (like the PLAY_PAIN - which automatically plays the pain sound fitting the NPC).

Does anybody know which natives to use and how to use them to get NPCs to speak (like saying "Piss off!" or some other generic lines)?

Edited by HughJanus

  • Replies 50
  • Views 18.2k
  • Created
  • Last Reply

Top Posters In This Topic

Most Popular Posts

  • I offered it in the mapeditor thru the chaiscript implementation with a single line:     Ped.PlayAmbientSpeech("FAREWELL_NO_SALE", "0078_U_M_M_BLWTRAINSTATIONWORKER_01"); But heres how you do i

  • You can use the native below. It needs a struct as argument though, which you need to set up properly first. Like this:   var1[0] = speechline; var1[1] = voice; // Can be 0 var1[2] = 0; // up

  • The first is the ped, the second is the container. And there is no "type" for this, you can define your own struct or just use new memory and pass a pointer to that.

You can use the native below. It needs a struct as argument though, which you need to set up properly first. Like this:

 

var1[0] = speechline;
var1[1] = voice; // Can be 0
var1[2] = 0; // uparam5
var1[3] = 291934926; // iparam11
var1[4] = target; // Ped target
var1[5] = NativeFunction.Call<int>(0x10FAB35428CCC9D7); // network is game in progress
var1[6] = 1; // bool at the end?

Then you can use it with lines like "GENERIC_THANKS" or "GOING_WELL".

 

I changed my model to U_M_M_ValSheriff_01 and only filled the first parameter (speech name) and the fourth: GENERIC_THANKS and 0xE7176FB2 respectively. The rest I left as their default values. It played just fine for me when calling the native with player ped and the params.

 

RPH mods do not use C++, but C# so it is definitely quite some work to port it.

1 hour ago, HughJanus said:

I now tried going around the wrapper and directly invoking the native hash, but it also threw an error (with or without filling the rest of the contruct with default values).


struct CSpeechStruct
{
	public: char* SpeechName;
	public: char* VoiceName;
	public: uint UnknownUInt1;
	public: uint SpeechModifier;
	public: uint UnknownUInt2;
	public: bool UnknownBool1;
	public: int UnknownBool2;
	public: uint UnknownUInt3;
};

CSpeechStruct s;
s.SpeechName = "GENERIC_THANKS";
s.VoiceName = 0;
s.UnknownUInt1 = 0;
s.SpeechModifier = 0xE7176FB2;
s.UnknownUInt2 = 0;
s.UnknownBool1 = false;
s.UnknownBool2 = 0;
s.UnknownUInt3 = 0;

invoke<BOOL>(0x8E04FEDD28D42462, ped, s);

 

I give up for now.

Maybe I will find the passion to further try this later some time.

I suppose it will take less time porting the whole mod to RPH than trying to make this native work^^

Thanks for the help, though.

 

 

You would need to pass the reference, so &s, but you tried that before too iirc, so probably also not going to work. And no problem.

  • 4 weeks later...

Good to see you are back and sad to see it is still not working..

 

When the decompiler puts "Var0 = sParam1;" that just means that the first field (at offset 0) is being assigned. You hence should move that to be the first field in your definition.

If ScriptHook still throws errors, try casting your "CSpeechStruct* x" to UINT_PTR before passing it. Maybe that makes it accept it.

I don't think Any works for the rest of the types, as that will be too big. I would suggest using the types I provided initially, but you already tried that, so not sure. This is actually interesting me as to why it does not work, so I might try to get it to work in C++ myself this weekend. I don't think including C will do anything for you (and C# is not possible).

  • 1 month later...

   I offered it in the mapeditor thru the chaiscript implementation with a single line:

    Ped.PlayAmbientSpeech("FAREWELL_NO_SALE", "0078_U_M_M_BLWTRAINSTATIONWORKER_01");

But heres how you do it in c++ 

Spoiler

struct ScriptedSpeechParams
{
    const char* speechName;
    const char* voiceName;
    alignas(8) int v3;
    alignas(8) Hash speechParamHash;
    alignas(8) Entity entity;
    alignas(8) BOOL v6;
    alignas(8) int v7;
    alignas(8) int v8;
};


  void PlayAmbientSpeech(std::string speechline, std::string voice) {
       // Entity is not required..
      ScriptedSpeechParams params{ speechline.c_str(), voice.c_str(), 1, 0x67F3AB43, 0, true, 1, 1 };
      AUDIO::_PLAY_AMBIENT_SPEECH1(this->id, (Any*)&params);
  }

 

 

Was problaby a bit unclear with that comment the ScriptedSpeechParams struct has an entity variable. That one is 0 in my example and that works just fine. In the native AUDIO::_PLAY_AMBIENT_SPEECH1 you pass the ped  you want to be the source of the sound (where i use this->id).

 

There are several big warning signs here. Why do you call PedFearTest to only call another function? Not to mention it's return type is bool and you return nothing.

And it should be quite obvious that you cant set the voice to be 0 when it expects a string representing a voice.

Looking a bit closer i would not recommend you going thru the entire ped pool each frame to check the timer it's a massive waste of cpu time.

 

Edited by Lambda

12 hours ago, HughJanus said:

 

Edit: Is there a way to make NPCs speak each with their own voice (so a generic value for the voice parameter)?


Not that i know of, you can set the ambient voice name for peds so it's likely that there is an for now unkown native to get the voice from a ped.

Edited by Lambda

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...

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.