防外挂移动检测『幻邃出品』

首先是配置区域:

-- ========================================
-- 幻邃防外挂
-- ========================================

-- ==================== 配置区域 ====================
local Config = {
    -- 处理方式选择 (1=踢出游戏, 2=传送回出生点, 3=禁止移动10秒, 4=仅警告)
    punishmentType = 2,
    
    -- 检测灵敏度 (1=严格, 2=正常, 3=宽松)
    sensitivity = 2,
    
    -- 管理员白名单 (填入管理员的迷你号)
    adminList = {
        -- 1000, 1001, 1002  -- 示例,请替换成实际管理员迷你号,支持多位管理员
    },
    
    -- 是否排除骑乘状态
    excludeRiding = true,
    
    -- 是否记录日志
    enableLog = true,
    
    -- 检测间隔(秒) 建议0.5-2秒
    checkInterval = 1,
    
    -- 速度阈值设置 (根据灵敏度自动调整)
    speedThreshold = {
        [1] = 15,  -- 严格模式
        [2] = 20,  -- 正常模式
        [3] = 25   -- 宽松模式
    },
    
    -- 瞬移距离阈值
    teleportThreshold = {
        [1] = 30,
        [2] = 50,
        [3] = 80
    },
    
    -- 飞行时间阈值(秒)
    flyTimeThreshold = {
        [1] = 3,
        [2] = 5,
        [3] = 8
    },
    
    -- 违规次数达到多少次后执行处罚
    violationLimit = 3
}

-- ==================== 数据存储 ====================
local PlayerData = {}  -- 存储玩家数据
local ViolationLog = {}  -- 违规日志

-- 初始化玩家数据
local function InitPlayerData(playerid)
    if not PlayerData[playerid] then
        PlayerData[playerid] = {
            lastPos = nil,
            lastCheckTime = 0,
            airTime = 0,
            violationCount = 0,
            isFrozen = false,
            frozenEndTime = 0
        }
    end
end

-- ==================== 工具函数 ====================

-- 检查是否是管理员
local function IsAdmin(playerid)
    for _, adminId in ipairs(Config.adminList) do
        if playerid == adminId then
            return true
        end
    end
    return false
end

-- 计算两点距离
local function CalculateDistance(pos1, pos2)
    local dx = pos1.x - pos2.x
    local dy = pos1.y - pos2.y
    local dz = pos1.z - pos2.z
    return math.sqrt(dx * dx + dy * dy + dz * dz)
end

-- 记录违规日志
local function LogViolation(playerid, reason)
    if not Config.enableLog then return end
    
    local result, nickname = Player:getNickname(playerid)
    local logEntry = {
        playerid = playerid,
        nickname = nickname or "未知",
        reason = reason,
        time = os.time()
    }
    
    table.insert(ViolationLog, logEntry)
    
    -- 输出到控制台
    print(string.format("[防外挂] 玩家 %s(%d) 触发检测: %s", 
        logEntry.nickname, playerid, reason))
end

-- ==================== 处罚系统 ====================

-- 执行处罚
local function ExecutePunishment(playerid, reason)
    local result, nickname = Player:getNickname(playerid)
    local name = nickname or "玩家"
    
    if Config.punishmentType == 1 then
        -- 方式1: 踢出游戏
        Player:setGameResults(playerid, 2)
        Chat:sendSystemMsg(string.format("✘ %s 因使用外挂被踢出游戏!", name))
        
    elseif Config.punishmentType == 2 then
        -- 方式2: 传送回出生点
        Player:reviveToPos(playerid, 0, 0, 0)
        Player:notifyGameInfo2Self(playerid, "✘ 检测到异常移动,已传送回出生点!")
        Chat:sendSystemMsg(string.format("✘ %s 触发移动检测", name))
        
    elseif Config.punishmentType == 3 then
        -- 方式3: 禁止移动10秒
        Player:setActionAttrState(playerid, 1, false)
        PlayerData[playerid].isFrozen = true
        PlayerData[playerid].frozenEndTime = os.time() + 10
        Player:notifyGameInfo2Self(playerid, "✘ 检测到异常移动,禁止移动10秒!")
        
    elseif Config.punishmentType == 4 then
        -- 方式4: 仅警告
        Player:notifyGameInfo2Self(playerid, "✘ 警告:检测到异常移动行为!")
    end
    
    LogViolation(playerid, reason)
end

-- ==================== 检测系统 ====================

-- 速度检测
local function CheckSpeed(playerid, distance, deltaTime)
    if deltaTime <= 0 then return false end
    
    local speed = distance / deltaTime
    local threshold = Config.speedThreshold[Config.sensitivity]
    
    -- 排除骑乘状态
    if Config.excludeRiding then
        local result, ridingObjId = Actor:getRidingActorObjId(playerid)
        if result == 0 and ridingObjId ~= 0 then
            return false
        end
    end
    
    if speed > threshold then
        return true, string.format("移动速度异常 (%.2f > %d)", speed, threshold)
    end
    
    return false
end

-- 瞬移检测
local function CheckTeleport(playerid, distance, deltaTime)
    local threshold = Config.teleportThreshold[Config.sensitivity]
    
    if distance > threshold and deltaTime < 1 then
        return true, string.format("疑似瞬移 (距离%.2f > %d)", distance, threshold)
    end
    
    return false
end

-- 飞行检测
local function CheckFly(playerid)
    local result = Actor:isInAir(playerid)
    local data = PlayerData[playerid]
    
    if result == 0 then
        -- 在空中
        data.airTime = data.airTime + Config.checkInterval
        
        local threshold = Config.flyTimeThreshold[Config.sensitivity]
        if data.airTime > threshold then
            return true, string.format("长时间飞行 (%.1f秒 > %d秒)", data.airTime, threshold)
        end
    else
        -- 在地面,重置空中时间
        data.airTime = 0
    end
    
    return false
end

主检测逻辑和事件注册

-- ==================== 主检测逻辑 ====================

-- 主检测函数
local function CheckPlayer(playerid)
    -- 跳过管理员
    if IsAdmin(playerid) then
        return
    end
    
    -- 初始化玩家数据
    InitPlayerData(playerid)
    
    local data = PlayerData[playerid]
    local currentTime = os.time()
    
    -- 检查是否被冻结
    if data.isFrozen then
        if currentTime >= data.frozenEndTime then
            -- 解除冻结
            Player:setActionAttrState(playerid, 1, true)
            data.isFrozen = false
            Player:notifyGameInfo2Self(playerid, "✔ 移动限制已解除")
        end
        return
    end
    
    -- 获取当前位置
    local result, x, y, z = Actor:getPosition(playerid)
    if result ~= 0 then return end
    
    local currentPos = {x = x, y = y, z = z}
    
    -- 如果有上次位置,进行检测
    if data.lastPos then
        local deltaTime = currentTime - data.lastCheckTime
        
        if deltaTime > 0 then
            local distance = CalculateDistance(currentPos, data.lastPos)
            
            -- 速度检测
            local isSpeedViolation, speedReason = CheckSpeed(playerid, distance, deltaTime)
            if isSpeedViolation then
                data.violationCount = data.violationCount + 1
                if data.violationCount >= Config.violationLimit then
                    ExecutePunishment(playerid, speedReason)
                    data.violationCount = 0
                end
            end
            
            -- 瞬移检测
            local isTeleportViolation, teleportReason = CheckTeleport(playerid, distance, deltaTime)
            if isTeleportViolation then
                data.violationCount = data.violationCount + 1
                if data.violationCount >= Config.violationLimit then
                    ExecutePunishment(playerid, teleportReason)
                    data.violationCount = 0
                end
            end
            
            -- 飞行检测
            local isFlyViolation, flyReason = CheckFly(playerid)
            if isFlyViolation then
                data.violationCount = data.violationCount + 1
                if data.violationCount >= Config.violationLimit then
                    ExecutePunishment(playerid, flyReason)
                    data.violationCount = 0
                    data.airTime = 0
                end
            end
        end
    end
    
    -- 更新位置和时间
    data.lastPos = currentPos
    data.lastCheckTime = currentTime
end

-- ==================== 事件系统 ====================

-- 游戏运行时检测
local function Game_Update(event)
    local result, num, players = World:getAllPlayers(1)
    if result == 0 and num > 0 then
        for i = 1, num do
            CheckPlayer(players[i])
        end
    end
end

-- 玩家进入游戏
local function Player_EnterGame(event)
    local playerid = event.eventobjid
    InitPlayerData(playerid)
    
    local result, nickname = Player:getNickname(playerid)
    print(string.format("[防外挂] 玩家 %s(%d) 进入游戏", nickname or "未知", playerid))
end

-- 玩家离开游戏
local function Player_LeaveGame(event)
    local playerid = event.eventobjid
    
    -- 清理玩家数据
    if PlayerData[playerid] then
        PlayerData[playerid] = nil
    end
    
    local result, nickname = Player:getNickname(playerid)
    print(string.format("[防外挂] 玩家 %s(%d) 离开游戏", nickname or "未知", playerid))
end

-- 游戏开始
local function Game_Start()
    Chat:sendSystemMsg("=================================")
    Chat:sendSystemMsg(" 检测已启动")
    Chat:sendSystemMsg(string.format("☆ 当前配置: 处罚方式=%d, 灵敏度=%d", 
        Config.punishmentType, Config.sensitivity))
    Chat:sendSystemMsg("=================================")
    
    print("[防外挂] 系统初始化完成")
    print(string.format("[防外挂] 处罚方式: %d (1=踢出 2=传送 3=禁止移动 4=警告)", Config.punishmentType))
    print(string.format("[防外挂] 检测灵敏度: %d (1=严格 2=正常 3=宽松)", Config.sensitivity))
end

-- ==================== 管理命令 ====================

-- 查看违规日志
local function ShowViolationLog(playerid)
    if not IsAdmin(playerid) then
        Player:notifyGameInfo2Self(playerid, "✘ 你没有权限查看日志")
        return
    end
    
    if #ViolationLog == 0 then
        Player:notifyGameInfo2Self(playerid, "✘ 暂无违规记录")
        return
    end
    
    Chat:sendSystemMsg("========== 违规日志 ==========")
    local count = math.min(10, #ViolationLog)
    for i = #ViolationLog, #ViolationLog - count + 1, -1 do
        local log = ViolationLog[i]
        Chat:sendSystemMsg(string.format("%s(%d): %s", 
            log.nickname, log.playerid, log.reason))
    end
    Chat:sendSystemMsg("==============================")
end

-- 聊天命令处理
local function Player_InputContent(event)
    local playerid = event.eventobjid
    local content = event.content
    
    if content == "/antilog" then
        ShowViolationLog(playerid)
    elseif content == "/antihelp" then
        Player:notifyGameInfo2Self(playerid, "📖 命令列表:")
        Player:notifyGameInfo2Self(playerid, "/antilog - 查看违规日志")
        Player:notifyGameInfo2Self(playerid, "/antihelp - 显示帮助")
    end
end

-- ==================== 注册事件 ====================

ScriptSupportEvent:registerEvent([=[Game.Start]=], Game_Start)
ScriptSupportEvent:registerEvent([=[Game.Run]=], Game_Update)
ScriptSupportEvent:registerEvent([=[Game.AnyPlayer.EnterGame]=], Player_EnterGame)
ScriptSupportEvent:registerEvent([=[Game.AnyPlayer.LeaveGame]=], Player_LeaveGame)
ScriptSupportEvent:registerEvent([=[Player.NewInputContent]=], Player_InputContent)

print("[防外挂] 脚本加载完成!")

使用说明:

1. 配置修改(在代码开头的Config部分)

punishmentType = 2  -- 改成 1/2/3/4 选择处罚方式
sensitivity = 2     -- 改成 1/2/3 选择检测灵敏度
adminList = {1000, 1001}  -- 填入管理员迷你号,支持多位迷你号

2.处罚方式说明:

1 = 踢出游戏(最严厉)

2 = 传送回出生点(推荐)

3 = 禁止移动10秒

4 = 仅警告提示

3. 灵敏度说明:

1 = 严格模式(可能误判但更安全)

2 = 正常模式(推荐)

3 = 宽松模式(减少误判)

4. 管理员命令:

/antilog – 查看最近10条违规记录

/antihelp – 显示帮助信息

✨ 功能特点:

✅ 自动检测速度异常、瞬移、长时间飞行

✅ 可自定义处罚方式和检测灵敏度

✅ 管理员白名单免检

✅ 自动排除骑乘状态

✅ 完整的违规日志系统

✅ 防止误判的违规次数累计机制

 

请登录后发表评论

    • huansui的头像-辉月官网huansui等级-LV1-辉月官网作者0