Page 1 of 1

Code to extract the text string from 0xAD

Posted: Tue Mar 10, 2009 11:32 am
by CWO
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.

Re: Code to extract the text string from 0xAD

Posted: Mon Mar 16, 2009 1:36 am
by *Edwards
Do you spy your players? :whip:
8)

Re: Code to extract the text string from 0xAD

Posted: Mon Mar 16, 2009 4:29 am
by coltain
You don`t?

Re: Code to extract the text string from 0xAD

Posted: Mon Mar 16, 2009 8:09 am
by *Edwards
:( I did.

Re: Code to extract the text string from 0xAD

Posted: Mon Mar 16, 2009 1:26 pm
by CWO
Edwards, I don't use speech events on my NPCs. This is how merchants, boats, tamed animals, guards, ect... work on my shard. This is also needed so I can set a prop to them of what they last said so if the speech.mul hook doesn't give me enough info (wildcard tokens don't give info on what was said), I can have the script read the text so that it can do the proper action.

Re: Code to extract the text string from 0xAD

Posted: Mon Mar 16, 2009 6:24 pm
by *Edwards
No panic. I just added a little sarcasm and thanks for your topic. ;)