Code to extract the text string from 0xAD
Posted: Tue Mar 10, 2009 11:32 am
I just wanted to release this packethook code to anyone who finds it useful. The thing to realize is that 0xAD packet can send the player's speech in 2 different ways and at 2 different offsets based on whether the player has speech.mul installed and the text is using it or not. This is a very simple code that will set the variable 'speech' to a string containing the exact text the character has said. This was never intended to be a complete code in this post, just a snippet to put in your code and handle the speech from there in any way you like. The exported function start is there only for reference to the variable names.
Code: Select all
exported function HandleSpeech( character, byref packet )
var speech := "";
var speechstart := 12;
if (packet.GetInt8(3) == 0xC0)
var triggers := packet.GetInt16(12)/16;
var bytes := CInt(triggers*1.5 + 2);
speechstart := CInt(speechstart + bytes);
var speechlen := packet.GetInt16(1) - 1 - speechstart;
speech := CStr(packet.GetString(speechstart, speechlen));
else
var speechlen := (packet.GetInt16(1) - 13)/2;
speech := CChrZ(packet.GetUnicodeString(speechstart, speechlen));
endif
// the variable 'speech' is now the exact text they said. Do whatever you want with it from here.