一天三盒半 发表于 前天 14:05

VVM2每日签到系统 - Lua脚本

本代码声明

[*]本人仅提供 VVM2 引擎 相关 Lua 代码的设计思路、逻辑框架、参考示例,不提供完整成品代码、安装程序、环境部署、使用教程、运营方案等任何可直接落地使用的内容。
[*]本人不负责安装指导、使用调试、故障修复、运营维护、技术支持等一切后续服务;
[*]不对使用者基于本思路开发、使用、运营过程中产生的任何问题(包括但不限于代码报错、程序故障、合规风险、经济损失等)承担任何法律、民事及经济责任。
[*]使用者需独立判断思路适用性,自行完成开发、安装、使用、运营全流程操作,自愿承担所有相关风险与后果。
[*]使用者必须严格遵守国家法律法规及相关平台规则,因违规使用产生的一切责任由使用者自行承担。
[*]欢迎在下方留言反馈问题~




=====================================================================================
                        VVM2每日签到系统 - Lua脚本
=====================================================================================
功能说明:
    本脚本实现一个完整的每日签到系统,支持每日登录点击签到获取奖励
    奖励包括:元宝、经验丹、绑定金币、材料礼盒
    参与条件:无等级限制,每日1次

作者: 一天三盒半
=====================================================================================


-- ========================================
-- 配置表 - 签到奖励配置
-- ========================================
local SIGN_IN_CONFIG = {
    -- NPC配置
    npc_id = 1002,                  -- NPC配置ID
    npc_name = "签到有礼",             -- NPC显示名称
   
    -- 奖励配置
    rewards = {
      { type = "gamegold", value = 50, name = "元宝" },         -- 元宝奖励
      { type = "exp", value = 10000, name = "经验" },             -- 经验奖励
      { type = "gold", value = 10000, name = "绑定金币" },      -- 绑定金币奖励
      { type = "item", value = 1001, count = 1, name = "经验丹" },-- 经验丹物品
      { type = "item", value = 1002, count = 1, name = "材料礼盒" }-- 材料礼盒物品
    },
   
    -- 签到时间配置
    reset_hour = 0,                   -- 每日重置时间(小时)
    max_sign_days = 30,               -- 最大连续签到天数
   
    -- 连续签到额外奖励
    consecutive_rewards = {
       = { gamegold = 100, item = { id = 1003, count = 1 } },-- 7天额外奖励
       = { gamegold = 200, item = { id = 1004, count = 1 } }, -- 14天额外奖励
       = { gamegold = 500, item = { id = 1005, count = 1 } }-- 30天额外奖励
    }
}

-- ========================================
-- 全局变量定义
-- ========================================
local NpcLib = NpcLib or {}

-- ========================================
-- 辅助函数 - 获取今日日期字符串
-- ========================================
local function GetTodayString()
    local timestamp = os.time()
    local date = os.date("*t", timestamp)
    return string.format("%04d%02d%02d", date.year, date.month, date.day)
end

-- ========================================
-- 辅助函数 - 获取玩家最后签到日期
-- ========================================
local function GetLastSignDate(actor)
    local last_date = getplayervalue(actor, 100)-- 使用玩家变量100存储签到日期
    return last_date or ""
end

-- ========================================
-- 辅助函数 - 设置玩家最后签到日期
-- ========================================
local function SetLastSignDate(actor, date)
    setplayervalue(actor, 100, date)
end

-- ========================================
-- 辅助函数 - 获取连续签到天数
-- ========================================
local function GetConsecutiveDays(actor)
    local days = getplayervalue(actor, 101)-- 使用玩家变量101存储连续签到天数
    return days or 0
end

-- ========================================
-- 辅助函数 - 设置连续签到天数
-- ========================================
local function SetConsecutiveDays(actor, days)
    setplayervalue(actor, 101, days)
end

-- ========================================
-- 辅助函数 - 判断是否可以签到
-- ========================================
local function CanSignIn(actor)
    local today = GetTodayString()
    local last_date = GetLastSignDate(actor)
   
    -- 如果今天已经签到过,返回false
    if last_date == today then
      return false, "今天已经签到过了"
    end
   
    return true, "可以签到"
end

-- ========================================
-- 辅助函数 - 计算连续签到天数
-- ========================================
local function CalculateConsecutiveDays(actor)
    local today = GetTodayString()
    local last_date = GetLastSignDate(actor)
    local current_days = GetConsecutiveDays(actor)
   
    if last_date == "" then
      -- 第一次签到
      return 1
    end
   
    -- 解析日期
    local last_year = tonumber(last_date:sub(1, 4))
    local last_month = tonumber(last_date:sub(5, 6))
    local last_day = tonumber(last_date:sub(7, 8))
   
    local today_year = tonumber(today:sub(1, 4))
    local today_month = tonumber(today:sub(5, 6))
    local today_day = tonumber(today:sub(7, 8))
   
    -- 计算两个日期之间的天数差
    local last_time = os.time({year=last_year, month=last_month, day=last_day})
    local today_time = os.time({year=today_year, month=today_month, day=today_day})
    local diff_days = (today_time - last_time) / (24 * 60 * 60)
   
    if diff_days == 1 then
      -- 连续签到
      return current_days + 1
    else
      -- 断签,重新计算
      return 1
    end
end


admin 发表于 前天 14:07

怎么看着像ai写的

一天三盒半 发表于 前天 14:13

admin 发表于 2026-5-25 14:07
怎么看着像ai写的

小龙虾~~
页: [1]
查看完整版本: VVM2每日签到系统 - Lua脚本