查看“︁Lua接口/属性读取与修改”︁的源代码
来自天龙知识库
←
Lua接口/属性读取与修改
跳到导航
跳到搜索
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
__NOTOC__ <div class="lua-reference" style="max-width:1200px;margin:0 auto;line-height:1.8;color:#29343a;font-family:Arial,'Microsoft YaHei',sans-serif;letter-spacing:0;overflow-wrap:anywhere;"> [[首页|首页]] · [[Lua接口/服务端函数索引|服务端接口]] · [[Lua接口/服务端调用约定|调用约定]] 读写角色的生命、气、怒气、基础属性、限时修正、活力精力与潜能点。先查接口作用对象:多数针对玩家 selfId,少数限时修正针对怪物。 == 生命与气 == {| class="wikitable" style="width:100%;table-layout:fixed;border-collapse:collapse;font-size:13px;" ! scope="col" style="text-align:left;background:#edf3f2;padding:8px;" | 接口 ! scope="col" style="text-align:left;background:#edf3f2;padding:8px;" | 参数与返回 |- | style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | [[Lua接口/服务端/GetHp|GetHp]] / [[Lua接口/服务端/GetMp|GetMp]] | style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | <code style="white-space:normal;overflow-wrap:anywhere;">sceneId, selfId</code> → 当前生命 / 气。 |- | style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | [[Lua接口/服务端/GetMaxHp|GetMaxHp]] / [[Lua接口/服务端/GetMaxMp|GetMaxMp]] | style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | <code style="white-space:normal;overflow-wrap:anywhere;">sceneId, selfId</code> → 生命 / 气上限。 |- | style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | [[Lua接口/服务端/SetHp|SetHp]] | style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | <code style="white-space:normal;overflow-wrap:anywhere;">sceneId, selfId, hp</code>;部分分支无返回值。 |- | style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | [[Lua接口/服务端/SetMp|SetMp]] | style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | <code style="white-space:normal;overflow-wrap:anywhere;">sceneId, selfId, mp</code>;部分分支无返回值。 |} [[Lua接口/服务端/SetHp|SetHp]]、[[Lua接口/服务端/SetMp|SetMp]] 在对象无效等分支不返回值,赋值接收得到 nil,不能用 <code style="white-space:normal;overflow-wrap:anywhere;">if result then</code> 判断是否设置成功。生命 / 气上限由等级与基础属性决定,先改等级或属性,上限随之更新。 == 怒气 == {| class="wikitable" style="width:100%;table-layout:fixed;border-collapse:collapse;font-size:13px;" ! scope="col" style="text-align:left;background:#edf3f2;padding:8px;" | 接口 ! scope="col" style="text-align:left;background:#edf3f2;padding:8px;" | 参数与返回 |- | style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | [[Lua接口/服务端/GetRage|GetRage]] | style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | <code style="white-space:normal;overflow-wrap:anywhere;">sceneId, selfId</code> → 当前怒气;非角色单位返回 -1。 |- | style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | [[Lua接口/服务端/GetMaxRage|GetMaxRage]] | style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | <code style="white-space:normal;overflow-wrap:anywhere;">sceneId, selfId</code> → 怒气上限;非角色单位返回 -1。 |- | style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | [[Lua接口/服务端/SetRage|SetRage]] | style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | <code style="white-space:normal;overflow-wrap:anywhere;">sceneId, selfId, rage</code>;无返回值。 |} [[Lua接口/服务端/GetRage|GetRage]]、[[Lua接口/服务端/GetMaxRage|GetMaxRage]] 对非角色单位(如物品箱、传送点)返回 -1,不能只靠 <code style="white-space:normal;overflow-wrap:anywhere;">>= 0</code> 判断,应先确认对象是角色。 == 基础属性 == {| class="wikitable" style="width:100%;table-layout:fixed;border-collapse:collapse;font-size:13px;" ! scope="col" style="text-align:left;background:#edf3f2;padding:8px;" | 接口 ! scope="col" style="text-align:left;background:#edf3f2;padding:8px;" | 参数与返回 |- | style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | [[Lua接口/服务端/GetHumanAttr|GetHumanAttr]] | style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | <code style="white-space:normal;overflow-wrap:anywhere;">sceneId, selfId, attrType</code> → 按官方编号返回六类攻击属性。 |- | style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | [[Lua接口/服务端/LuaFnGetBaseAttackPhysics|LuaFnGetBaseAttackPhysics]] | style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | <code style="white-space:normal;overflow-wrap:anywhere;">sceneId, selfId</code> → 基础外功攻击。 |- | style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | [[Lua接口/服务端/SetCharacterAttrRefix|SetCharacterAttrRefix]] | style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | <code style="white-space:normal;overflow-wrap:anywhere;">sceneId, selfId, attrType, refix</code> → 设置冰、火、玄、毒攻击修正值。 |} [[Lua接口/服务端/GetHumanAttr|GetHumanAttr]] 按 attrType 取六类攻击属性之一,attrType 是配置约定的编号,不在这里枚举。[[Lua接口/服务端/SetCharacterAttrRefix|SetCharacterAttrRefix]] 只改冰、火、玄、毒四系攻击修正值,不直接改最终面板;修改后最终数值仍要由属性刷新流程汇总。各系攻击 / 防御的基础读取接口名带 Base 前缀([[Lua接口/服务端/LuaFnGetBaseAttackPhysics|LuaFnGetBaseAttackPhysics]] 等),均为只读。 == 限时属性修正(怪物专用)== {| class="wikitable" style="width:100%;table-layout:fixed;border-collapse:collapse;font-size:13px;" ! scope="col" style="text-align:left;background:#edf3f2;padding:8px;" | 接口 ! scope="col" style="text-align:left;background:#edf3f2;padding:8px;" | 参数与返回 |- | style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | [[Lua接口/服务端/LuaFnGetLifeTimeAttrRefix_MaxHP|LuaFnGetLifeTimeAttrRefix_MaxHP]] | style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | <code style="white-space:normal;overflow-wrap:anywhere;">sceneId, monsterId</code> → 怪物本次存活期间的生命上限修正。 |- | style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | [[Lua接口/服务端/LuaFnSetLifeTimeAttrRefix_MaxHP|LuaFnSetLifeTimeAttrRefix_MaxHP]] | style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | <code style="white-space:normal;overflow-wrap:anywhere;">sceneId, monsterId, value</code>;设置本次存活期间修正。 |} 这一组 LifeTimeAttrRefix 接口**针对怪物的 monsterId,不是玩家 selfId**。修正只在该怪物本次存活期间生效,怪物重生后会重置。同组还有外功 / 内功 / 各系攻防、命中 / 闪避、暴击等子项,按 <code style="white-space:normal;overflow-wrap:anywhere;">LuaFnGetLifeTimeAttrRefix_<属性></code> / <code style="white-space:normal;overflow-wrap:anywhere;">LuaFnSetLifeTimeAttrRefix_<属性></code> 命名。 == 活力与精力 == {| class="wikitable" style="width:100%;table-layout:fixed;border-collapse:collapse;font-size:13px;" ! scope="col" style="text-align:left;background:#edf3f2;padding:8px;" | 接口 ! scope="col" style="text-align:left;background:#edf3f2;padding:8px;" | 参数与返回 |- | style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | [[Lua接口/服务端/GetHumanVigor|GetHumanVigor]] / [[Lua接口/服务端/GetHumanMaxVigor|GetHumanMaxVigor]] | style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | <code style="white-space:normal;overflow-wrap:anywhere;">sceneId, selfId</code> → 当前 / 上限活力。 |- | style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | [[Lua接口/服务端/SetHumanVigor|SetHumanVigor]] | style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | <code style="white-space:normal;overflow-wrap:anywhere;">sceneId, selfId, value</code>;无返回值。 |- | style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | [[Lua接口/服务端/GetHumanEnergy|GetHumanEnergy]] / [[Lua接口/服务端/GetHumanMaxEnergy|GetHumanMaxEnergy]] | style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | <code style="white-space:normal;overflow-wrap:anywhere;">sceneId, selfId</code> → 当前 / 上限精力。 |- | style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | [[Lua接口/服务端/SetHumanEnergy|SetHumanEnergy]] | style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | <code style="white-space:normal;overflow-wrap:anywhere;">sceneId, selfId, value</code>;无返回值。 |} == 潜能点 == {| class="wikitable" style="width:100%;table-layout:fixed;border-collapse:collapse;font-size:13px;" ! scope="col" style="text-align:left;background:#edf3f2;padding:8px;" | 接口 ! scope="col" style="text-align:left;background:#edf3f2;padding:8px;" | 参数与返回 |- | style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | [[Lua接口/服务端/GetPlayerRemainPoints|GetPlayerRemainPoints]] | style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | <code style="white-space:normal;overflow-wrap:anywhere;">sceneId, selfId</code> → 尚未分配的一级属性点。 |- | style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | [[Lua接口/服务端/SetPlayerRemainPoints|SetPlayerRemainPoints]] | style="padding:8px;vertical-align:top;overflow-wrap:anywhere;" | <code style="white-space:normal;overflow-wrap:anywhere;">sceneId, selfId, remainPoints</code> → 设置后返回设置值。 |} [[Lua接口/服务端/GetPlayerRemainPoints|GetPlayerRemainPoints]]、[[Lua接口/服务端/SetPlayerRemainPoints|SetPlayerRemainPoints]] 在部分分支无返回值,赋值接收得到 nil,不等于失败。实际分配一级属性点由客户端加点流程或对应接口完成,这里只读写尚未分配的余量。 == 读取生命与上限 == <pre style="white-space:pre-wrap;overflow-wrap:anywhere;font-size:13px;line-height:1.7;padding:12px;background:#f5f7f8;border:1px solid #dbe3e6;">local hp = GetHp(sceneId, selfId) local maxHp = GetMaxHp(sceneId, selfId) if type(hp) == "number" and type(maxHp) == "number" and hp >= 0 and maxHp > 0 then -- 有效生命与上限 end</pre> [[Lua接口/服务端/GetHp|GetHp]] 失败路径返回的值需要按具体接口核对;先用 type 判断再判数值范围,避免把异常值当有效。 == 设置当前生命 == <pre style="white-space:pre-wrap;overflow-wrap:anywhere;font-size:13px;line-height:1.7;padding:12px;background:#f5f7f8;border:1px solid #dbe3e6;">SetHp(sceneId, selfId, 1) -- 部分分支无返回值;不能写 if SetHp(...) then 判断成功 -- 想确认生效应改读 GetHp 回比</pre> [[Lua接口/服务端/SetHp|SetHp]] 不保证返回成功标志。需要确认生效,应在设置后用 [[Lua接口/服务端/GetHp|GetHp]] 读回比较,而不是接收返回值。 == 相关主题 == * [[Lua接口/角色信息|角色信息]] * [[Lua接口/属性读取与修改|属性读取与修改]] * [[Lua接口/等级与经验|等级与经验]] * [[Lua接口/货币相关|货币相关]] * [[Lua接口/物品查询|物品查询]] * [[Lua接口/物品发放与扣除|物品发放与扣除]] * [[Lua接口/背包空间|背包空间]] * [[Lua接口/装备操作|装备操作]] * [[Lua接口/任务状态|任务状态]] * [[Lua接口/任务变量|任务变量]] * [[Lua接口/NPC对话|NPC 对话]] * [[Lua接口/对话选项|对话选项]] [[Lua接口/服务端调用约定|服务端调用约定]] · [[Lua接口/服务端调用示例|服务端调用示例]] · [[Lua接口/服务端函数索引|服务端函数索引]] [[Lua接口/函数不存在|函数不存在或提示 nil]] · [[Lua接口/参数类型与顺序|参数类型与顺序]] · [[Lua接口/返回值判断|返回值判断]] · [[Lua接口/对象ID与GUID|对象 ID 与 GUID]] <div style="margin-top:20px;padding-top:10px;border-top:1px solid #dbe3e6;color:#657078;font-size:12px;">本页函数签名与返回约定依据当前服务端注册表整理;sceneId、selfId 由实际回调提供,业务枚举、属性类型编号与运行效果需要实测。</div> </div>
返回
Lua接口/属性读取与修改
。
导航菜单
页面操作
页面
讨论
阅读
查看源代码
历史
页面操作
页面
讨论
更多
工具
个人工具
创建账号
登录
导航
首页
最近更改
随机页面
MediaWiki帮助
特殊页面
搜索
工具
链入页面
相关更改
页面信息