Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Custom "speech" function
Author Message
karma
Moderator
****

Posts: 178
Likes Given: 17
Likes Received: 32 in 29 posts
Joined: Jul 2012
Reputation: 3



Post: #1
Custom "speech" function
All the infos you need are in the comments in the code.

Code:
[FUNCTION UTEXT]
//sends *unicode* text packet (AE) to client and allows to specify useful data, which usually is automatic (you can manage all the packet components)
//SYNTAX: UTEXT forclients, talkmode, serial, name, color, text

// - forclients: send the packet to chars in "argument" range.
//    Notice that if you want to use this function to show a SYSMESSAGE, you should use -1 as argument
//    ** -1: only to I (char on whom the function is called)
//    **  0: default (16)
//    **  1-100: range (if you need 100+ range you may consider using other ways, like SERV.ALLCLIENTS or SECTOR.ALLCLIENTS)
// - talkmode: in Enhanced Client, same talkmodes produce different effects from what espected in Classic Client or pre-KR/older clients
//    Main talkmodes in EC are:
//    ** 0: text over the char, like with SAY. Is the only talkmode that generates hued text
//    ** 1: gray text showed in the bottom-left corner of the game screen (or in the System box in EC), like SYSMESSAGE
//    ** 2: yellow (maybe the hue is chosen by the client) text over the char, like with SAY, probably used to *emote* something
//    ** 3: purple (no chance to change the hue) SYSMESSAGE
// - serial: UID of the char speaking (or receiving text, if used to obtain a sysmessage)
//    **  0: default (serial of I object, which is <UID>)
//    ** -1: in EC, causes the text to be shown in the top-left corner of the game screen
// - name: who is speaking or sending text (text argument)
//    ** 0: use default (name of I object, which is <NAME>)

//Packet structure:
//byte ID (AE)
//word Packet Size //length in bytes
//dword Serial
//word Graphic
//byte Mode (0x00 = say, 0x01 = system, 0x02 = emote, 0x06 = label, 0x07 = focus,
//  0x08 = whisper, 0x09 = yell, 0x10 = spell, 0x13 = guild, 0x14 = alliance, 0x15 =
//  GM, 0xC0 = encoded commands) (reported talkmodes may not be correct)
//word Text Color
//word Font
//char[4] Language
//char[30] Name
//uchar[*] Text  //no fixed dimension

IF (<ARGV> < 6)
    RETURN 0
ENDIF

LOCAL.TALKMODE=0<ARGV[1]>
LOCAL.SERIAL=0<ARGV[2]>
IF !(<LOCAL.SERIAL>)
    LOCAL.SERIAL=<UID>
ENDIF
LOCAL.NAME=<ARGV[3]>
IF (<ISNUM <LOCAL.NAME>>)
    IF !(<LOCAL.NAME>)
        LOCAL.NAME=<NAME>
    ENDIF
ENDIF
LOCAL.COLOR=0<ARGV[4]>
LOCAL._TEXT=<ASC <ARGV[5]>>
LOCAL._TEXTLEN=<HVAL STRLEN(<LOCAL._TEXT>)>
LOCAL.GRAPHIC=01 090
LOCAL.FONT=00 03
LOCAL.LANGUAGE=00 00 00 00 //no localization
//LOCAL.LANGUAGE=045 04E 055 00 //ENU
LOCAL.NAME=<ASCPAD 30, <LOCAL.NAME>>

LOCAL.TEXT=00 <STRARG <LOCAL._TEXT>>
LOCAL._TEXT=<STREAT <LOCAL._TEXT>>
FOR 2 <LOCAL._TEXTLEN>
    LOCAL.TEXT=<LOCAL.TEXT> 00 <STRARG <LOCAL._TEXT>>
    LOCAL._TEXT=<STREAT <LOCAL._TEXT>>
ENDFOR
LOCAL.TEXT=<LOCAL.TEXT> 00 00
LOCAL._TEXTLEN += 1
//LOCAL.LEN=( (<LOCAL._TEXTLEN>*2)+1+2+4+2+1+2+2+4+30 )
LOCAL.LEN=( (<LOCAL._TEXTLEN>*2)+48 )

LOCAL.PACKET=0AE W(<LOCAL.LEN>) D(<LOCAL.SERIAL>) <LOCAL.GRAPHIC> B(<LOCAL.TALKMODE>) W(<LOCAL.COLOR>) <LOCAL.FONT> <LOCAL.LANGUAGE> <LOCAL.NAME> <LOCAL.TEXT>

LOCAL.RANGE=0<ARGV[0]>
IF (<LOCAL.RANGE> == -1)
    SENDPACKET <LOCAL.PACKET>
ELSE
    IF (<LOCAL.RANGE> > 100)
        LOCAL.RANGE=100
    ELSEIF !(<LOCAL.RANGE>)
        LOCAL.RANGE=16
    ENDIF
    FORCLIENTS <LOCAL.RANGE>
        SENDPACKET <LOCAL.PACKET>
    ENDFOR
ENDIF
RETURN 1

[FUNCTION SYSMESSAGEEXT]
//like SYSMESSAGE, but you can specify the "sender" name
//i'm using it for the EC, so there is not a parameter for the color because it won't work, but you can easily add it if you need
//SYNTAX: SYSMESSAGEEXT senderName, text
IF (<ARGV> < 2)
    RETURN 0
ENDIF
LOCAL.NAME=<ARGV[0]>
IF (<ISNUM <LOCAL.NAME>>)
    IF !(<LOCAL.NAME>)
        LOCAL.NAME=System
    ENDIF
ENDIF
RETURN <UTEXT -1,1,0,<LOCAL.NAME>,0,<ARGV[1]>>
05-04-2014 09:53 AM
Find all posts by this user Like Post Quote this message in a reply
[+] 1 user Likes karma's post
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)

This forum uses Lukasz Tkacz MyBB addons.