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: 1142
Joined: Sat Feb 04, 2006 5:49 pm
Location: Chicago, IL USA
Contact:

Code to extract the text string from 0xAD

Post by CWO » 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.

User avatar
*Edwards
Forum Regular
Posts: 301
Joined: Fri Dec 28, 2007 11:19 pm
Location: Montreal, Canada
Contact:

Re: Code to extract the text string from 0xAD

Post by *Edwards » Mon Mar 16, 2009 1:36 am

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 » Mon Mar 16, 2009 4:29 am

You don`t?

User avatar
*Edwards
Forum Regular
Posts: 301
Joined: Fri Dec 28, 2007 11:19 pm
Location: Montreal, Canada
Contact:

Re: Code to extract the text string from 0xAD

Post by *Edwards » Mon Mar 16, 2009 8:09 am

:( I did.

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

Re: Code to extract the text string from 0xAD

Post by CWO » Mon Mar 16, 2009 1:26 pm

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: 301
Joined: Fri Dec 28, 2007 11:19 pm
Location: Montreal, Canada
Contact:

Re: Code to extract the text string from 0xAD

Post by *Edwards » Mon Mar 16, 2009 6:24 pm

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

Post Reply