Speaking PEDs?

Hi everyone, I was writing a shop script and I thought if I could make the clerk talk it would be cool. I checked the natives document and found this PlayPedAmbientSpeechNative function but I couldn’t make it work. The example code is in c++ and only works for modding. I was wondering if anybody managed to run this function properly.

I haven’t tried it yet, but I think the real question here is how to replicate the struct data structure from the decompiled scripts. There is an example of how to do that in LUA here and in JavaScript here.

I got it working in JavaScript, not sure if the code is entirely correct though.

const speechParams = new DataView(new ArrayBuffer(128));

const speechName = 'RE_PH_RHD_V3_AGGRO';
const voiceName = '0405_U_M_M_RhdSheriff_01';

const string1 = CreateVarString(10, "LITERAL_STRING", speechName);
const string2 = CreateVarString(10, "LITERAL_STRING", voiceName);

speechParams.setBigInt64(0, BigInt(string1), true);
speechParams.setBigInt64(8, BigInt(string2), true);
speechParams.setInt32(16, 1, true);
speechParams.setInt32(24, 0x67f3ab43, true);
speechParams.setBigInt64(32, BigInt(PlayerPedId()), true);
speechParams.setBigInt64(40, BigInt(true), true);
speechParams.setInt32(48, 1, true);
speechParams.setInt32(56, 1, true);

Citizen.invokeNative('0x8E04FEDD28D42462', PlayerPedId(), speechParams);

Thanks! that’s exactly what I was looking for.