Message 表用于向玩家发送文字。字符串过长时会按 UTF-8 边界截断(NPC 说话最多 1024 字节;Message.Box / Message.BoxAll 对话框在发送给客户端的数据包中只能容纳 150 字节的内容和 100 字节的标题)。向单个玩家发送的函数只要求角色已登录(LOGGED 及以上);如果无效则不发送任何内容。
Message.Send、Message.SendAll、Message.SendGlobal 的通知类型(type):0 屏幕中央的黄色文字,1 蓝色文字,2 公会频道,3 红色文字。该值被限制在 0 到 255 之间。
Message.GetText)或模块的配置文件,不要在代码中写死,以便于修改和翻译。Message.Send
向单个玩家发送通知。
Message.Send(aIndex, type, text)
| 参数 | 类型 | 说明 |
|---|---|---|
aIndex | integer | 接收角色的索引 |
type | integer | 通知类型(默认 1) |
text | string | 内容 |
简称:NoticeSend。
Message.Send(aIndex, 1, "您获得了 100 WCoin")
Message.SendAll
向此 GameServer 上的所有玩家发送通知。
Message.SendAll(type, text)
| 参数 | 类型 | 说明 |
|---|---|---|
type | integer | 通知类型(默认 0) |
text | string | 内容 |
简称:NoticeSendToAll。
Message.SendAll(0, "活动即将开始!")
Message.SendGlobal
向所有 GameServer 上的所有玩家发送通知(通过服务器间连接,包括此 GameServer)。如果服务器间连接中断,通知只会在此 GameServer 内发送。
Message.SendGlobal(type, text)
| 参数 | 类型 | 说明 |
|---|---|---|
type | integer | 通知类型(默认 0) |
text | string | 内容 |
简称:NoticeGlobalSend。
Message.SendGlobal(0, "世界 Boss 已经出现!")
Message.Box
在单个玩家的屏幕中央显示一个对话框。
Message.Box(aIndex, type, title, text)
| 参数 | 类型 | 说明 |
|---|---|---|
aIndex | integer | 接收角色的索引 |
type | integer | 对话框类型(0 到 255,默认 1) |
title | string | 标题 |
text | string | 内容(发送给客户端的数据包最多容纳 150 字节,超出部分被截断) |
简称:MessageSend。
type 值会原样发送给客户端(限制在 0 到 255 之间);GameServer 不处理其含义,由客户端决定显示哪种对话框样式。发送给客户端的数据包中,内容最长 150 字节,标题最长 100 字节(超出部分按 UTF-8 边界截断)。
Message.Box(aIndex, 0, "签到", "您已领取今天的礼物。")
Message.BoxAll
向此 GameServer 上所有正在游戏中的玩家显示对话框。
Message.BoxAll(type, title, text)
| 参数 | 类型 | 说明 |
|---|---|---|
type | integer | 对话框类型(0 到 255,默认 1) |
title | string | 标题 |
text | string | 内容(发送给客户端的数据包最多容纳 150 字节,超出部分被截断) |
简称:MessageSendToAll。
Message.BoxAll(0, "维护", "服务器将在 5 分钟后重启。")
Message.NpcSay
让 NPC(或怪物)说一句话。默认只在 NPC 头顶显示文字气泡;也可以同时在聊天框中添加一行。
Message.NpcSay(npcIndex, aIndex, text [, toChat])
| 参数 | 类型 | 说明 |
|---|---|---|
npcIndex | integer | 处于活动状态的 NPC / 怪物的索引 |
aIndex | integer | 听到的玩家索引。-1 = 站在 NPC 周围的所有人 |
text | string | 内容(最多 1024 字节) |
toChat | boolean | true = 同时在聊天框中显示一行“名称 Say: ...”;默认 false |
如果 NPC 不处于活动状态或听者无效,函数不执行任何操作。简称:ChatTargetSend。
Message.NpcSay(npcIndex, aIndex, "欢迎来到 Lorencia!", false)
Message.Post
向此 GameServer 上的所有人发送一行 /post 命令风格的文字。
Message.Post(name, text)
| 参数 | 类型 | 说明 |
|---|---|---|
name | string | 发送者的显示名称(按角色名称的最大长度截断) |
text | string | 内容(最多约 198 字节,超出部分被截断) |
简称:PostSend(postType, msgIndex, name, text);前两个参数被忽略。
Message.Post("系统", "新年快乐!")
Message.GetText
从服务器的语言文件(Lang 文件夹,结构为 <Group Type> / <Data ID>)中获取一个字符串。有两种调用方式。
Message.GetText(type, id, default) -> string
Message.GetText(id, default) -> string
| 参数 | 类型 | 说明 |
|---|---|---|
type | integer | 组编号(Group Type)。2 个参数的调用形式使用组 0(System 组) |
id | integer | 字符串编号(Data ID) |
default | string | 未找到时返回的字符串 |
返回:语言文件中的字符串;如果不存在则返回 default。简称:MessageGet(id, lang)(lang 参数被忽略,默认返回空字符串)。
local t = Message.GetText(0, 1, "Hello")