Code to extract the text string from 0xAD

Post your Custom Scripts or Packages.

Moderator: POL Developer

Post Reply
User avatar
CWO
POL Expert
Posts: 1159
Joined: Sat Feb 04, 2006 5:49 pm
Location: Chicago, IL USA

Code to extract the text string from 0xAD

Post 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.
User avatar
*Edwards
Forum Regular
Posts: 303
Joined: Fri Dec 28, 2007 11:19 pm
Location: Montreal, Canada

Re: Code to extract the text string from 0xAD

Post by *Edwards »

Do you spy your players? :whip:
8)
coltain
Grandmaster Poster
Posts: 159
Joined: Tue Mar 20, 2007 7:17 am
Location: Poland

Re: Code to extract the text string from 0xAD

Post by coltain »

You don`t?
User avatar
*Edwards
Forum Regular
Posts: 303
Joined: Fri Dec 28, 2007 11:19 pm
Location: Montreal, Canada

Re: Code to extract the text string from 0xAD

Post by *Edwards »

:( I did.
User avatar
CWO
POL Expert
Posts: 1159
Joined: Sat Feb 04, 2006 5:49 pm
Location: Chicago, IL USA

Re: Code to extract the text string from 0xAD

Post 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.
User avatar
*Edwards
Forum Regular
Posts: 303
Joined: Fri Dec 28, 2007 11:19 pm
Location: Montreal, Canada

Re: Code to extract the text string from 0xAD

Post by *Edwards »

No panic. I just added a little sarcasm and thanks for your topic. ;)
Post Reply