Lua接口/时间与计时:修订间差异
来自天龙知识库
跳到导航跳到搜索
维护服务端 Lua 接口:核对参数、返回值、边界条件与调用示例 |
维护服务端 Lua 接口:核对参数、返回值、边界条件与调用示例 |
||
| 第1行: | 第1行: | ||
__NOTOC__ | __NOTOC__ | ||
<div class="lua-reference | <div class="lua-reference"> | ||
[[首页|首页]] · [[Lua接口/服务端函数索引|服务端接口]] · [[Lua接口/服务端调用约定|调用约定]] | [[首页|首页]] · [[Lua接口/服务端函数索引|服务端接口]] · [[Lua接口/服务端调用约定|调用约定]] | ||
| 第6行: | 第6行: | ||
== 当前时间 == | == 当前时间 == | ||
{| class="wikitable | {| class="wikitable" | ||
! scope="col | ! scope="col" | 接口 | ||
! scope="col | ! scope="col" | 参数与返回 | ||
|- | |- | ||
| [[Lua接口/服务端/LuaFnGetCurrentTime|LuaFnGetCurrentTime]] | |||
| <code>()</code> → 当前时间(秒,无参)。 | |||
|- | |- | ||
| [[Lua接口/服务端/mytime|mytime]] | |||
| <code>()</code> → 当前 ANSI 时间戳(无参);失败 -1。 | |||
|- | |- | ||
| [[Lua接口/服务端/GetHour|GetHour]] | |||
| <code>()</code> → 当前小时 0-23(无参);失败 -1。 | |||
|- | |- | ||
| [[Lua接口/服务端/GetMinute|GetMinute]] | |||
| <code>()</code> → 当前分钟 0-59(无参);失败 -1。 | |||
|- | |- | ||
| [[Lua接口/服务端/GetDayTime|GetDayTime]] | |||
| <code>()</code> → 当前天数(如 1140 表示 2001 年第 140 天,无参);失败 -1。 | |||
|} | |} | ||
这几个接口都不接受参数。 | 这几个接口都不接受参数。 | ||
== 日期字段 == | == 日期字段 == | ||
{| class="wikitable | {| class="wikitable" | ||
! scope="col | ! scope="col" | 接口 | ||
! scope="col | ! scope="col" | 参数与返回 | ||
|- | |- | ||
| [[Lua接口/服务端/GetTodayYear|GetTodayYear]] | |||
| <code>()</code> → 四位公历年份;失败 -1。 | |||
|- | |- | ||
| [[Lua接口/服务端/GetTodayMonth|GetTodayMonth]] | |||
| <code>()</code> → 月份索引 0-11;失败 -1。 | |||
|- | |- | ||
| [[Lua接口/服务端/GetTodayDate|GetTodayDate]] | |||
| <code>()</code> → 本月日号;失败 -1。 | |||
|- | |- | ||
| [[Lua接口/服务端/GetTodayWeek|GetTodayWeek]] | |||
| <code>()</code> → 星期索引,星期日为 0;失败 -1。 | |||
|- | |- | ||
| [[Lua接口/服务端/LuaFnGetThisYear|LuaFnGetThisYear]] | |||
| <code>()</code> → 公历年份;失败 -1。 | |||
|- | |- | ||
| [[Lua接口/服务端/LuaFnGetThisMonth|LuaFnGetThisMonth]] | |||
| <code>()</code> → 月份 0-11(tm 约定);失败 -1。 | |||
|- | |- | ||
| [[Lua接口/服务端/LuaFnGetDayOfThisMonth|LuaFnGetDayOfThisMonth]] | |||
| <code>()</code> → 本月日号 1-31;失败 -1。 | |||
|} | |} | ||
[[Lua接口/服务端/GetTodayMonth|GetTodayMonth]] 与 [[Lua接口/服务端/LuaFnGetThisMonth|LuaFnGetThisMonth]] 都返回 **0 到 11**(tm 约定),不要当 1 到 12 用。[[Lua接口/服务端/GetTodayWeek|GetTodayWeek]] 里**星期日是 0**。 | [[Lua接口/服务端/GetTodayMonth|GetTodayMonth]] 与 [[Lua接口/服务端/LuaFnGetThisMonth|LuaFnGetThisMonth]] 都返回 **0 到 11**(tm 约定),不要当 1 到 12 用。[[Lua接口/服务端/GetTodayWeek|GetTodayWeek]] 里**星期日是 0**。 | ||
== 周与时间片 == | == 周与时间片 == | ||
{| class="wikitable | {| class="wikitable" | ||
! scope="col | ! scope="col" | 接口 | ||
! scope="col | ! scope="col" | 参数与返回 | ||
|- | |- | ||
| [[Lua接口/服务端/GetWeekTime|GetWeekTime]] | |||
| <code>()</code> → 年份和周序号组合值;失败 -1。 | |||
|- | |- | ||
| [[Lua接口/服务端/GetTime2Day|GetTime2Day]] | |||
| <code>()</code> → 当前日期 YYYYMMDD 数值;失败 -1。 | |||
|- | |- | ||
| [[Lua接口/服务端/GetQuarterTime|GetQuarterTime]] | |||
| <code>()</code> → 15 分钟时间片编号;失败 -1。 | |||
|} | |} | ||
[[Lua接口/服务端/GetTime2Day|GetTime2Day]] 返回形如 20260912 的整数,便于直接比较日期。[[Lua接口/服务端/GetQuarterTime|GetQuarterTime]] 以 15 分钟为一片。 | [[Lua接口/服务端/GetTime2Day|GetTime2Day]] 返回形如 20260912 的整数,便于直接比较日期。[[Lua接口/服务端/GetQuarterTime|GetQuarterTime]] 以 15 分钟为一片。 | ||
== 世界时间 == | == 世界时间 == | ||
{| class="wikitable | {| class="wikitable" | ||
! scope="col | ! scope="col" | 接口 | ||
! scope="col | ! scope="col" | 参数与返回 | ||
|- | |- | ||
| [[Lua接口/服务端/LuaFnGetCurrentWorldTime|LuaFnGetCurrentWorldTime]] | |||
| <code>()</code> → 世界服务器同步的十二时辰索引;失败 -1。 | |||
|} | |} | ||
[[Lua接口/服务端/LuaFnGetCurrentWorldTime|LuaFnGetCurrentWorldTime]] 取的是**世界服同步的十二时辰**,与本地小时不同。 | [[Lua接口/服务端/LuaFnGetCurrentWorldTime|LuaFnGetCurrentWorldTime]] 取的是**世界服同步的十二时辰**,与本地小时不同。 | ||
== 玩家计时器 == | == 玩家计时器 == | ||
{| class="wikitable | {| class="wikitable" | ||
! scope="col | ! scope="col" | 接口 | ||
! scope="col | ! scope="col" | 参数与返回 | ||
|- | |- | ||
| [[Lua接口/服务端/SetTimer|SetTimer]] | |||
| <code>sceneId, selfId, scriptId, funcName, tickTime</code> → 计时器索引;失败 -1。 | |||
|- | |- | ||
| [[Lua接口/服务端/StopTimer|StopTimer]] | |||
| <code>sceneId, sceneTimerIndex</code>;无返回值。 | |||
|- | |- | ||
| [[Lua接口/服务端/CheckTimer|CheckTimer]] | |||
| <code>sceneId, TimeIndex</code> → 是否在使用中;失败 -1。 | |||
|} | |} | ||
[[Lua接口/服务端/SetTimer|SetTimer]] 需要 5 个参数,时间到会自动调用指定脚本的 funcName(约定为 OnTimer)。**每个玩家身上最多绑定三个计时器**。[[Lua接口/服务端/StopTimer|StopTimer]] 无返回值,且只传计时器索引,不传 selfId。 | [[Lua接口/服务端/SetTimer|SetTimer]] 需要 5 个参数,时间到会自动调用指定脚本的 funcName(约定为 OnTimer)。**每个玩家身上最多绑定三个计时器**。[[Lua接口/服务端/StopTimer|StopTimer]] 无返回值,且只传计时器索引,不传 selfId。 | ||
== 单位与在线时间 == | == 单位与在线时间 == | ||
{| class="wikitable | {| class="wikitable" | ||
! scope="col | ! scope="col" | 接口 | ||
! scope="col | ! scope="col" | 参数与返回 | ||
|- | |- | ||
| [[Lua接口/服务端/SetCharacterTimer|SetCharacterTimer]] | |||
| <code>sceneId, selfId, nTime</code>;无返回值。nTime 为 0 时停止时钟。 | |||
|- | |- | ||
| [[Lua接口/服务端/SetCharacterDieTime|SetCharacterDieTime]] | |||
| <code>sceneId, selfId, nTime</code>;无返回值。只对 Monster 和 Pet 有效。 | |||
|- | |- | ||
| [[Lua接口/服务端/GetGameTime|GetGameTime]] | |||
| <code>sceneId, selfId</code> → 玩家在线时间(秒);失败 -1。 | |||
|- | |- | ||
| [[Lua接口/服务端/GetObjCreateTime|GetObjCreateTime]] | |||
| <code>sceneId, selfId</code> → 对象创建时间;失败 -1。 | |||
|} | |} | ||
[[Lua接口/服务端/SetCharacterTimer|SetCharacterTimer]] 设置单位时钟间隔,传 0 停止;[[Lua接口/服务端/SetCharacterDieTime|SetCharacterDieTime]] 只对怪物和珍兽有效。 | [[Lua接口/服务端/SetCharacterTimer|SetCharacterTimer]] 设置单位时钟间隔,传 0 停止;[[Lua接口/服务端/SetCharacterDieTime|SetCharacterDieTime]] 只对怪物和珍兽有效。 | ||
== 读取当前日期 == | == 读取当前日期 == | ||
<pre | <pre>local year = GetTodayYear() | ||
local month = GetTodayMonth() | local month = GetTodayMonth() | ||
local day = GetTodayDate() | local day = GetTodayDate() | ||
| 第126行: | 第126行: | ||
== 设置玩家计时器 == | == 设置玩家计时器 == | ||
<pre | <pre>local idx = SetTimer(sceneId, selfId, scriptId, "OnTimer", 60000) | ||
if type(idx) == "number" and idx ~= -1 then | if type(idx) == "number" and idx ~= -1 then | ||
-- 计时器创建成功,idx 为索引 | -- 计时器创建成功,idx 为索引 | ||
| 第166行: | 第166行: | ||
[[Lua接口/函数不存在|函数不存在或提示 nil]] · [[Lua接口/参数类型与顺序|参数类型与顺序]] · [[Lua接口/返回值判断|返回值判断]] · [[Lua接口/对象ID与GUID|对象 ID 与 GUID]] | [[Lua接口/函数不存在|函数不存在或提示 nil]] · [[Lua接口/参数类型与顺序|参数类型与顺序]] · [[Lua接口/返回值判断|返回值判断]] · [[Lua接口/对象ID与GUID|对象 ID 与 GUID]] | ||
<div | <div class="lua-note">本页函数签名与返回约定依据当前服务端注册表整理;sceneId、selfId 由实际回调提供,业务枚举、属性类型编号与运行效果需要实测。</div> | ||
</div> | </div> | ||
2026年9月19日 (六) 16:59的版本
读取服务器时间、日期字段、世界时间,以及为玩家设置计时器。取日期时注意月份为 0 到 11(tm 约定)。
当前时间
| 接口 | 参数与返回 |
|---|---|
| LuaFnGetCurrentTime | () → 当前时间(秒,无参)。
|
| mytime | () → 当前 ANSI 时间戳(无参);失败 -1。
|
| GetHour | () → 当前小时 0-23(无参);失败 -1。
|
| GetMinute | () → 当前分钟 0-59(无参);失败 -1。
|
| GetDayTime | () → 当前天数(如 1140 表示 2001 年第 140 天,无参);失败 -1。
|
这几个接口都不接受参数。
日期字段
| 接口 | 参数与返回 |
|---|---|
| GetTodayYear | () → 四位公历年份;失败 -1。
|
| GetTodayMonth | () → 月份索引 0-11;失败 -1。
|
| GetTodayDate | () → 本月日号;失败 -1。
|
| GetTodayWeek | () → 星期索引,星期日为 0;失败 -1。
|
| LuaFnGetThisYear | () → 公历年份;失败 -1。
|
| LuaFnGetThisMonth | () → 月份 0-11(tm 约定);失败 -1。
|
| LuaFnGetDayOfThisMonth | () → 本月日号 1-31;失败 -1。
|
GetTodayMonth 与 LuaFnGetThisMonth 都返回 **0 到 11**(tm 约定),不要当 1 到 12 用。GetTodayWeek 里**星期日是 0**。
周与时间片
| 接口 | 参数与返回 |
|---|---|
| GetWeekTime | () → 年份和周序号组合值;失败 -1。
|
| GetTime2Day | () → 当前日期 YYYYMMDD 数值;失败 -1。
|
| GetQuarterTime | () → 15 分钟时间片编号;失败 -1。
|
GetTime2Day 返回形如 20260912 的整数,便于直接比较日期。GetQuarterTime 以 15 分钟为一片。
世界时间
| 接口 | 参数与返回 |
|---|---|
| LuaFnGetCurrentWorldTime | () → 世界服务器同步的十二时辰索引;失败 -1。
|
LuaFnGetCurrentWorldTime 取的是**世界服同步的十二时辰**,与本地小时不同。
玩家计时器
| 接口 | 参数与返回 |
|---|---|
| SetTimer | sceneId, selfId, scriptId, funcName, tickTime → 计时器索引;失败 -1。
|
| StopTimer | sceneId, sceneTimerIndex;无返回值。
|
| CheckTimer | sceneId, TimeIndex → 是否在使用中;失败 -1。
|
SetTimer 需要 5 个参数,时间到会自动调用指定脚本的 funcName(约定为 OnTimer)。**每个玩家身上最多绑定三个计时器**。StopTimer 无返回值,且只传计时器索引,不传 selfId。
单位与在线时间
| 接口 | 参数与返回 |
|---|---|
| SetCharacterTimer | sceneId, selfId, nTime;无返回值。nTime 为 0 时停止时钟。
|
| SetCharacterDieTime | sceneId, selfId, nTime;无返回值。只对 Monster 和 Pet 有效。
|
| GetGameTime | sceneId, selfId → 玩家在线时间(秒);失败 -1。
|
| GetObjCreateTime | sceneId, selfId → 对象创建时间;失败 -1。
|
SetCharacterTimer 设置单位时钟间隔,传 0 停止;SetCharacterDieTime 只对怪物和珍兽有效。
读取当前日期
local year = GetTodayYear()
local month = GetTodayMonth()
local day = GetTodayDate()
if type(year) == "number" and type(month) == "number" and type(day) == "number" then
-- month 为 0-11,显示时需要加 1
end
GetTodayMonth 返回 0 到 11,展示给玩家时需要加 1。
设置玩家计时器
local idx = SetTimer(sceneId, selfId, scriptId, "OnTimer", 60000)
if type(idx) == "number" and idx ~= -1 then
-- 计时器创建成功,idx 为索引
end
SetTimer 返回计时器索引,失败 -1;关闭时用 StopTimer 传该索引。
相关主题
- 角色信息
- 属性读取与修改
- 等级与经验
- 货币相关
- 物品查询
- 物品发放与扣除
- 背包空间
- 装备操作
- 任务状态
- 任务变量
- NPC 对话
- 对话选项
- 技能相关
- 心法相关
- 状态效果
- 生活技能
- 珍兽查询
- 珍兽操作
- 场景查询
- 坐标与传送
- 副本相关
- 活动相关
- 时间与计时
- 怪物相关
- 队伍相关
- 帮会相关
- 消息与提示
- 聊天与公告
函数不存在或提示 nil · 参数类型与顺序 · 返回值判断 · 对象 ID 与 GUID
本页函数签名与返回约定依据当前服务端注册表整理;sceneId、selfId 由实际回调提供,业务枚举、属性类型编号与运行效果需要实测。