赴爱 发表于 前天 04:54

修改为指令/jailcp


--Send to jail
RegisterNetEvent('wasabi_police:sendToJail', function()
    if not wsb.hasGroup(Config.policeJobs) then return end
    local target, time

    if Config.Jail.input then
      local coords = GetEntityCoords(wsb.cache.ped)
      local player = wsb.getClosestPlayer(vec3(coords.x, coords.y, coords.z), 2.0, false)
      if not player then
            TriggerEvent('wasabi_bridge:notify', Strings.no_nearby, Strings.no_nearby_desc, 'error')
      else
            local input = wsb.inputDialog(Strings.minutes_dialog, { Strings.minutes_dialog_field }, Config.UIColor)
            if not input then return end
            local input1 = tonumber(input[1])
            if type(input1) ~= 'number' then return end
            local quantity = math.floor(input1)
            if quantity < 1 then
                TriggerEvent('wasabi_bridge:notify', Strings.invalid_amount, Strings.invalid_amount_desc, 'error')
            else
                target, time = GetPlayerServerId(player), quantity
            end
      end
    end
    if Config.Jail.jail == 'qb' then
      TriggerServerEvent('wasabi_police:qbPrisonJail', target, time)
    elseif Config.Jail.jail == 'rcore' then
      ExecuteCommand('jail ' .. target .. ' jailed ' .. time .. ' Sentenced')
    elseif Config.Jail.jail == 'tk_jail' then
      if wsb.framework == 'esx' then
            exports.esx_tk_jail:jail(target, time)
      elseif wsb.framework == 'qb' then
            exports.qb_tk_jail:jail(target, time)
      end
    elseif Config.Jail.jail == 'hd_jail' then
      TriggerServerEvent('HD_Jail:sendToJail', target, 'Prison', time, 'Sentenced', 'Police')
    elseif Config.Jail.jail == 'myPrison' then
      ExecuteCommand('jail')
    elseif Config.Jail.jail == 'qalle-jail' then
      TriggerServerEvent('esx-qalle-jail:jailPlayer', target, time, 'Sentenced')
    elseif Config.Jail.jail == 'plouffe' then
      exports.plouffe_jail:Set(target, time)
    elseif Config.Jail.jail == 'mx' then
      TriggerServerEvent('mx_jail:jailPlayer', target, time, target)
      TriggerServerEvent('mx_jail:setTime', target, time)
    elseif Config.Jail.jail == 'custom' then
      -- Custom logic here?
    end
end)


ChatGPT 发表于 前天 04:55

以下是修改后的代码,将指令改为 `/jailcp`,并添加了注释以便理解代码逻辑:


-- 发送至监狱的事件
RegisterNetEvent('wasabi_police:sendToJail', function()
    -- 检查玩家是否在警察职业组
    if not wsb.hasGroup(Config.policeJobs) then return end
    local target, time

    -- 如果允许输入时间
    if Config.Jail.input then
      local coords = GetEntityCoords(wsb.cache.ped)-- 获取玩家位置
      local player = wsb.getClosestPlayer(vec3(coords.x, coords.y, coords.z), 2.0, false)-- 获取附近玩家
      if not player then
            -- 如果没有找到附近玩家,发送通知
            TriggerEvent('wasabi_bridge:notify', Strings.no_nearby, Strings.no_nearby_desc, 'error')
      else
            -- 弹出输入对话框,询问监禁时间
            local input = wsb.inputDialog(Strings.minutes_dialog, { Strings.minutes_dialog_field }, Config.UIColor)
            if not input then return end
            local input1 = tonumber(input)-- 将输入值转换为数字
            if type(input1) ~= 'number' then return end
            local quantity = math.floor(input1)-- 向下取整
            if quantity < 1 then
                -- 如果输入无效,发送错误通知
                TriggerEvent('wasabi_bridge:notify', Strings.invalid_amount, Strings.invalid_amount_desc, 'error')
            else
                target, time = GetPlayerServerId(player), quantity-- 保存目标玩家的ID和监禁时间
            end
      end
    end
   
    -- 根据配置决定使用哪个监禁方式
    if Config.Jail.jail == 'qb' then
      TriggerServerEvent('wasabi_police:qbPrisonJail', target, time)
    elseif Config.Jail.jail == 'rcore' then
      ExecuteCommand('jail ' .. target .. ' jailed ' .. time .. ' Sentenced')-- 使用指令监禁
    elseif Config.Jail.jail == 'tk_jail' then
      if wsb.framework == 'esx' then
            exports.esx_tk_jail:jail(target, time)-- ESX框架监禁
      elseif wsb.framework == 'qb' then
            exports.qb_tk_jail:jail(target, time)-- QB框架监禁
      end
    elseif Config.Jail.jail == 'hd_jail' then
      TriggerServerEvent('HD_Jail:sendToJail', target, 'Prison', time, 'Sentenced', 'Police')
    elseif Config.Jail.jail == 'myPrison' then
      ExecuteCommand('jail')-- 自定义监禁命令
    elseif Config.Jail.jail == 'qalle-jail' then
      TriggerServerEvent('esx-qalle-jail:jailPlayer', target, time, 'Sentenced')
    elseif Config.Jail.jail == 'plouffe' then
      exports.plouffe_jail:Set(target, time)-- Plouffe监禁
    elseif Config.Jail.jail == 'mx' then
      TriggerServerEvent('mx_jail:jailPlayer', target, time, target)
      TriggerServerEvent('mx_jail:setTime', target, time)-- MX监禁
    elseif Config.Jail.jail == 'custom' then
      -- 自定义逻辑处理
    end
end)

-- 注册指令 /jailcp
RegisterCommand('jailcp', function()
    -- 触发发送至监狱的事件
    TriggerEvent('wasabi_police:sendToJail')
end, false)


### 说明:
- 代码中将原本的监禁操作封装在 `sendToJail` 事件中,并新增了一个 `/jailcp` 指令来触发该事件。
- 添加的注释有助于理解每一部分代码的作用。
- 此代码可以放在 `Client.lua` 中,因为它涉及客户端的事件监听和指令注册。
页: [1]
查看完整版本: 修改为指令/jailcp