example
example

资源 qbcore自动删车

橙留香

活跃的用户
高级用户
认证用户
黄金
41.43 黄金
qb自动删车插件,管理员可用指令手动删车
代码:
-- 配置
TimeInterval = 60               -- 时间间隔(分钟)
DistanceToVehicles = 50.0       -- 允许载具与玩家之间的最大距离
Command = "delcars"             -- 管理员命令

-- QBCore初始化
local QBCore = exports['qb-core']:GetCoreObject()

-- 权限配置
AdminGroups = {
    'admin',
    'god'
}

Messages = {
    [1] = { time = 5, msg = "距离玩家超过50米的载具将在5分钟后删除!" },
    [2] = { time = 3, msg = "距离玩家超过50米的载具将在3分钟后删除!" },
    [3] = { time = 1, msg = "距离玩家超过50米的载具将在1分钟后删除!" },
}

NotAllowed = "您没有权限使用此命令!"
DeletedVehs = " 辆载具已被删除!"

-- 通知函数
function notify(msg, source)
    if source then
        TriggerClientEvent('QBCore:Notify', source, "[载具清理] " .. msg, "primary", 5000)
    else
        local players = QBCore.Functions.GetQBPlayers()
        for _, v in pairs(players) do
            TriggerClientEvent('QBCore:Notify', v.PlayerData.source, "[载具清理] " .. msg, "primary", 5000)
        end
    end
end

-- 内部计时器
local lastWipe = os.time()

-- 消息时间逻辑
function getWarningMessage(currentTime)
    for _, v in pairs(Messages) do
        if (TimeInterval * 60 - v.time * 60) == (currentTime - lastWipe) then
            return v.msg
        end
    end
end

-- 载具清理函数
function wipeVehicles()
    local deleted = 0
    local allPeds = GetAllPeds()
    local allVehicles = GetAllVehicles()

    for _, veh in pairs(allVehicles) do
        if DoesEntityExist(veh) then
            local vehCoords = GetEntityCoords(veh)
            local tooClose = false

            for _, ped in pairs(allPeds) do
                if #(vehCoords - GetEntityCoords(ped)) <= DistanceToVehicles then
                    tooClose = true
                    break
                end
            end

            if not tooClose then
                DeleteEntity(veh)
                deleted = deleted + 1
            end
        end
    end

    notify(deleted .. DeletedVehs)
end

-- 主计时循环
CreateThread(function()
    while true do
        Wait(1000)
        local now = os.time()

        if now - lastWipe >= TimeInterval * 60 then
            lastWipe = now
            wipeVehicles()
        else
            local msg = getWarningMessage(now)
            if msg then
                notify(msg)
            end
        end
    end
end)

-- 手动命令
RegisterCommand(Command, function(source)
    if source == 0 then
        wipeVehicles()
        return
    end

    local Player = QBCore.Functions.GetPlayer(source)
    if not Player then return end
    
    local isAllowed = false
    for _, group in pairs(AdminGroups) do
        if QBCore.Functions.HasPermission(source, group) then
            isAllowed = true
            break
        end
    end

    if isAllowed then
        wipeVehicles()
    else
        notify(NotAllowed, source)
    end
end, false)
 

附件

橙留香

还可以输入20字数。
领取红包用户
橙留香 weijiabao Tevis Hobart
感谢楼主的红包!

哇呜哇呜领取了您的红包获得了1.49黄金
 
后退
顶部