function kf_hyd(actor)
local msg = ""
if not checkkuafu(actor) then
return false
end
local map_id = getbaseinfo(actor, 3)
local map_name = getmapname(map_id)
if string.find(map_name, "外") then
changemoney(acto
🤖 回答引擎: 后端Lua |
🕒 时间: 2026-03-14 16:30:27 |
👁️ 阅读: 19
我是lua后端老师!小仙你好呀,看到你的代码了,想简化这个时间判断逻辑对吧?咱们直接获取服务器当前的小时和分钟来判断,这样确实简单多了。
根据你的需求,我来帮你重写这个判断部分。咱们先获取服务器时间,然后判断是否在你指定的那几个“传送门开启”的时间段内。
```lua
function kf_hyd(actor)
local msg = ""
if not checkkuafu(actor) then
return false
end
local map_id = getbaseinfo(actor, 3)
local map_name = getmapname(map_id)
if string.find(map_name, "外") then
changemoney(actor, 25, '+', 10, '跨服积分', true)
end
if string.find(map_name, "内") then
changemoney(actor, 25, '+', 20, '跨服积分', true)
end
local money_jf = querymoney(actor, 25)
-- 获取服务器当前时间
local current_time = getconst(actor, "<$HOUR>:<$MINUTE>")
local hour_min = getconst(actor, "<$HOUR>:<$MINUTE>")
local hour = tonumber(getconst(actor, "<$HOUR>"))
local minute = tonumber(getconst(actor, "<$MINUTE>"))
-- 初始化传送门状态为关闭
local km_zt = "关闭"
-- 判断是否在指定的开启时间段内
-- 时间段1: 20:31-20:34
if hour == 20 and minute >= 31 and minute <= 34 then
km_zt = "开启"
-- 时间段2: 20:36-20:49
elseif hour == 20 and minute >= 36 and minute <= 49 then
km_zt = "开启"
-- 时间段3: 20:40-20:43
elseif hour == 20 and minute >= 40 and minute <= 43 then
km_zt = "开启"
-- 时间段4: 20:44-20:47
elseif hour == 20 and minute >= 44 and minute <= 47 then
km_zt = "开启"
-- 时间段5: 20:49-20:52
elseif hour == 20 and minute >= 49 and minute <= 52 then
km_zt = "开启"
-- 时间段6: 20:54-20:57
elseif hour == 20 and minute >= 54 and minute <= 57 then
km_zt = "开启"
end
-- 更新消息内容,使用动态的传送门状态
msg = [[<RText|x=10|y=25|color=255|size=18|text=<归属:/FCOLOR=255><暂无归属/FCOLOR=250>>
<RText|x=10|y=55.0|color=255|size=18|text=<当前积分:/FCOLOR=255><]] .. money_jf .. [[/FCOLOR=250>>
<RText|x=10|y=85.0|color=249|size=18|text=<结束时间:/FCOLOR=255><20:30/FCOLOR=249>>
<RText|x=10|y=115.0|color=255|size=18|text=<内门状态:/FCOLOR=255><]] .. km_zt .. [[/FCOLOR=249>>
<Button|x=58.0|y=145.0|color=255|size=18|nimg=public/1900000689.png|text=回城|link=@kf_huicheng>]]
addbutton(actor, 110, 0, msg)
end
```
小仙,这样修改后,`km_zt`变量就会根据服务器当前时间自动判断是"开启"还是"关闭"状态了。代码逻辑很清晰:先获取当前的小时和分钟,然后逐个判断是否在你指定的6个时间段内,只要在任何一个时间段内,状态就设为"开启",否则就是"关闭"。
这样是不是简单多了?如果还有不明白的地方,随时问我哦!
我是lua后端老师!小仙你好呀,看到你的代码了,想简化这个时间判断逻辑对吧?咱们直接获取服务器当前的小时和分钟来判断,这样确实简单多了。
根据你的需求,我来帮你重写这个判断部分。咱们先获取服务器时间,然后判断是否在你指定的那几个“传送门开启”的时间段内。
```lua
function kf_hyd(actor)
local msg = ""
if not checkkuafu(actor) then
return false
end
local map_id = getbaseinfo(actor, 3)
local map_name = getmapname(map_id)
if string.find(map_name, "外") then
changemoney(actor, 25, '+', 10, '跨服积分', true)
end
if string.find(map_name, "内") then
changemoney(actor, 25, '+', 20, '跨服积分', true)
end
local money_jf = querymoney(actor, 25)
-- 获取服务器当前时间
local current_time = getconst(actor, "<$HOUR>:<$MINUTE>")
local hour_min = getconst(actor, "<$HOUR>:<$MINUTE>")
local hour = tonumber(getconst(actor, "<$HOUR>"))
local minute = tonumber(getconst(actor, "<$MINUTE>"))
-- 初始化传送门状态为关闭
local km_zt = "关闭"
-- 判断是否在指定的开启时间段内
-- 时间段1: 20:31-20:34
if hour == 20 and minute >= 31 and minute <= 34 then
km_zt = "开启"
-- 时间段2: 20:36-20:49
elseif hour == 20 and minute >= 36 and minute <= 49 then
km_zt = "开启"
-- 时间段3: 20:40-20:43
elseif hour == 20 and minute >= 40 and minute <= 43 then
km_zt = "开启"
-- 时间段4: 20:44-20:47
elseif hour == 20 and minute >= 44 and minute <= 47 then
km_zt = "开启"
-- 时间段5: 20:49-20:52
elseif hour == 20 and minute >= 49 and minute <= 52 then
km_zt = "开启"
-- 时间段6: 20:54-20:57
elseif hour == 20 and minute >= 54 and minute <= 57 then
km_zt = "开启"
end
-- 更新消息内容,使用动态的传送门状态
msg = [[<RText|x=10|y=25|color=255|size=18|text=<归属:/FCOLOR=255><暂无归属/FCOLOR=250>>
<RText|x=10|y=55.0|color=255|size=18|text=<当前积分:/FCOLOR=255><]] .. money_jf .. [[/FCOLOR=250>>
<RText|x=10|y=85.0|color=249|size=18|text=<结束时间:/FCOLOR=255><20:30/FCOLOR=249>>
<RText|x=10|y=115.0|color=255|size=18|text=<内门状态:/FCOLOR=255><]] .. km_zt .. [[/FCOLOR=249>>
<Button|x=58.0|y=145.0|color=255|size=18|nimg=public/1900000689.png|text=回城|link=@kf_huicheng>]]
addbutton(actor, 110, 0, msg)
end
```
小仙,这样修改后,`km_zt`变量就会根据服务器当前时间自动判断是"开启"还是"关闭"状态了。代码逻辑很清晰:先获取当前的小时和分钟,然后逐个判断是否在你指定的6个时间段内,只要在任何一个时间段内,状态就设为"开启",否则就是"关闭"。
这样是不是简单多了?如果还有不明白的地方,随时问我哦!
← 返回问答库