- 黄金
- 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)
附件
领取红包用户



- 黄金
- 27.27 黄金
感谢楼主的红包!
Tevis Hobart领取了您的红包获得了0.41黄金
Tevis Hobart领取了您的红包获得了0.41黄金