1214570993 发表于 2024-8-28 15:54:08

翻译成中文,保留源代码


ESX = nil

Citizen.CreateThread(function()
    while ESX == nil do
      TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
      Citizen.Wait(0)
    end
end)

local DumpsterCooldown = 7 -- In Minutes

local dumspterModel = {
    218085040,
    666561306,
    -58485588,
    -206690185,
    1511880420,
    682791951,
}

exports['qtarget']:AddTargetModel(dumspterModel, {
    options = {
      {
            event = 'dumpsterTrigger',
            icon = 'fas fa-dumpster',
            label = 'Search Dumpster',
      },
    },
    distance = 1.5
})


local Searched = {}

function CheckSearch(dumpster)
    local dumpstermodel = dumpster.entity
    for k, v in ipairs(Searched) do
      if v == dumpstermodel then
            return true
      end
    end
    return false
end


RegisterNetEvent('dumpsterTrigger')
AddEventHandler('dumpsterTrigger', function(data)
    local dumpstermodel = data.entity
    print(dumpstermodel)
    if CheckSearch(data) then
      exports['mythic_notify']:SendAlert('error', "You've already searched this dumpster")
    else
      exports['mythic_notify']:SendAlert('inform', "Searching Dumpster")
      table.insert(Searched, dumpstermodel)
      TriggerEvent('dumpster:starttimer', dumpstermodel)
      SearchDumpster()
    end
end)

function SearchDumpster()
    local time = math.random(30000, 40000)
    exports['mythic_progbar']:Progress({
      name = "unique_action_name",
      duration = time,
      label = 'Searching Dumpster',
      useWhileDead = false,
      canCancel = false,
      controlDisables = {
            disableMovement = true,
            disableCarMovement = true,
            disableMouse = false,
            disableCombat = true,
      },
      animation = {
          animDict = "mini@repair",
          anim = "fixing_a_ped",
      },
    })
    Citizen.Wait(time)
    ClearPedTasks(PlayerPedId(-1))
    TriggerServerEvent('dumpster:givereward')
end

RegisterNetEvent('dumpster:starttimer')
AddEventHandler('dumpster:starttimer', function(dumpster)
    local timer = DumpsterCooldown * 60000
    while timer > 0 do
      Wait(1000)
      timer = timer - 1000
      if timer == 0 then
            for i = 1, #Searched do
                if Searched[i] == dumpster then
                  table.remove(Searched, i)
                end
            end
      end
    end
end)



ChatGPT 发表于 2024-8-28 15:54:33

ESX = nil

Citizen.CreateThread(function()
    while ESX == nil do
      TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
      Citizen.Wait(0)
    end
end)

local DumpsterCooldown = 7 -- 冷却时间(分钟)

local dumspterModel = {
    218085040,
    666561306,
    -58485588,
    -206690185,
    1511880420,
    682791951,
}

exports['qtarget']:AddTargetModel(dumspterModel, {
    options = {
      {
            event = 'dumpsterTrigger',
            icon = 'fas fa-dumpster',
            label = '搜索垃圾箱',
      },
    },
    distance = 1.5
})

local Searched = {}

function CheckSearch(dumpster)
    local dumpstermodel = dumpster.entity
    for k, v in ipairs(Searched) do
      if v == dumpstermodel then
            return true
      end
    end
    return false
end

RegisterNetEvent('dumpsterTrigger')
AddEventHandler('dumpsterTrigger', function(data)
    local dumpstermodel = data.entity
    print(dumpstermodel)
    if CheckSearch(data) then
      exports['mythic_notify']:SendAlert('error', "你已经搜索过这个垃圾箱了")
    else
      exports['mythic_notify']:SendAlert('inform', "正在搜索垃圾箱")
      table.insert(Searched, dumpstermodel)
      TriggerEvent('dumpster:starttimer', dumpstermodel)
      SearchDumpster()
    end
end)

function SearchDumpster()
    local time = math.random(30000, 40000)
    exports['mythic_progbar']:Progress({
      name = "unique_action_name",
      duration = time,
      label = '正在搜索垃圾箱',
      useWhileDead = false,
      canCancel = false,
      controlDisables = {
            disableMovement = true,
            disableCarMovement = true,
            disableMouse = false,
            disableCombat = true,
      },
      animation = {
          animDict = "mini@repair",
          anim = "fixing_a_ped",
      },
    })
    Citizen.Wait(time)
    ClearPedTasks(PlayerPedId(-1))
    TriggerServerEvent('dumpster:givereward')
end

RegisterNetEvent('dumpster:starttimer')
AddEventHandler('dumpster:starttimer', function(dumpster)
    local timer = DumpsterCooldown * 60000
    while timer > 0 do
      Wait(1000)
      timer = timer - 1000
      if timer == 0 then
            for i = 1, #Searched do
                if Searched == dumpster then
                  table.remove(Searched, i)
                end
            end
      end
    end
end)

这段代码是一个FiveM插件的示例,主要用于处理玩家搜索垃圾箱的功能。代码中包含了冷却时间、搜索逻辑和通知功能。代码应该放在`Client.lua`中,因为它涉及到客户端的事件处理和用户界面交互。
页: [1]
查看完整版本: 翻译成中文,保留源代码