在线时长奖励:每30分钟领取一次 + 每日次数上限
这个脚本用于做在线奖励系统,玩家登录后开始计时,达到指定在线时长后可以领取奖励。功能点:
1. 登录时记录在线开始时间。
2. 每隔 30 分钟可领取一次奖励。
3. 每日最多领取指定次数,跨天自动重置。
4. 所有引擎接口集中在 VvApi 里,方便按自己的版本替换。
-- OnlineReward.lua
-- 在线奖励:累计在线时长、分档领取、每日领取次数限制
local VvApi = {}
function VvApi.getPlayerName(player)
return player.name
end
function VvApi.now()
return os.time()
end
function VvApi.getVar(key, default)
_G.__vv_vars = _G.__vv_vars or {}
local v = _G.__vv_vars
if v == nil then return default end
return v
end
function VvApi.setVar(key, value)
_G.__vv_vars = _G.__vv_vars or {}
_G.__vv_vars = value
end
function VvApi.addItem(player, itemName, count)
print("add item", VvApi.getPlayerName(player), itemName, count)
end
function VvApi.sendMsg(player, msg)
print(msg)
end
local OnlineReward = {}
OnlineReward.config = {
intervalSeconds = 30 * 60,
maxClaimPerDay = 6,
reward = { name = "在线奖励宝箱", count = 1 },
}
local function date()
return os.date("%Y%m%d")
end
function OnlineReward.onLogin(player)
local name = VvApi.getPlayerName(player)
VvApi.setVar("online:login:" .. name, VvApi.now())
VvApi.sendMsg(player, "在线奖励计时开始,每 30 分钟可领取一次。")
end
function OnlineReward.claim(player)
local name = VvApi.getPlayerName(player)
local day = date()
local loginKey = "online:login:" .. name
local claimDayKey = "online:claimday:" .. name
local claimCountKey = "online:claimcount:" .. name
local lastClaimKey = "online:lastclaim:" .. name
if VvApi.getVar(claimDayKey, "") ~= day then
VvApi.setVar(claimDayKey, day)
VvApi.setVar(claimCountKey, 0)
VvApi.setVar(lastClaimKey, VvApi.getVar(loginKey, VvApi.now()))
end
local count = VvApi.getVar(claimCountKey, 0)
if count >= OnlineReward.config.maxClaimPerDay then
VvApi.sendMsg(player, "今日在线奖励次数已达上限。")
return false
end
local lastClaim = VvApi.getVar(lastClaimKey, VvApi.getVar(loginKey, VvApi.now()))
local passed = VvApi.now() - lastClaim
if passed < OnlineReward.config.intervalSeconds then
local left = math.ceil((OnlineReward.config.intervalSeconds - passed) / 60)
VvApi.sendMsg(player, "还需要在线 " .. left .. " 分钟才能领取下一档奖励。")
return false
end
VvApi.addItem(player, OnlineReward.config.reward.name, OnlineReward.config.reward.count)
VvApi.setVar(claimCountKey, count + 1)
VvApi.setVar(lastClaimKey, VvApi.now())
VvApi.sendMsg(player, "领取成功,今日已领取 " .. (count + 1) .. "/" .. OnlineReward.config.maxClaimPerDay .. " 次。")
return true
end
return OnlineReward
独家版本后期最怕的不是功能少,而是脚本结构乱。
独家版本后期最怕的不是功能少,而是脚本结构乱。 独家版本后期最怕的不是功能少,而是脚本结构乱。 谢谢楼主分享! 独家版本后期最怕的不是功能少,而是脚本结构乱。 30分钟领取一次 + 每日次数上限顶顶顶 感谢大佬分享~~~
独家版本后期最怕的不是功能少,而是脚本结构乱。
谢谢楼主分享!
页:
[1]
2