赴爱 发表于 2025-7-6 01:20:05

注释


if Config.sellShop.enabled then
    CreateThread(function()
      CreateBlip(Config.sellShop.coords, 207, 5, Strings.sell_shop_blip, 0.80)
      local ped, pedSpawned
      local textUI
      while true do
            local sleep = 1500
            local playerPed = cache.ped
            local coords = GetEntityCoords(playerPed)
            local dist = #(coords - Config.sellShop.coords)
            if dist <= 30 and not pedSpawned then
                lib.requestAnimDict('mini@strip_club@idles@bouncer@base', 100)
                lib.requestModel(Config.sellShop.ped, 100)
                ped = CreatePed(28, Config.sellShop.ped, Config.sellShop.coords.x, Config.sellShop.coords.y, Config.sellShop.coords.z, Config.sellShop.heading, false, false)
                FreezeEntityPosition(ped, true)
                SetEntityInvincible(ped, true)
                SetBlockingOfNonTemporaryEvents(ped, true)
                TaskPlayAnim(ped, 'mini@strip_club@idles@bouncer@base', 'base', 8.0, 0.0, -1, 1, 0, 0, 0, 0)
                pedSpawned = true
            elseif dist <= 1.8 and pedSpawned then
                sleep = 0
                if not textUI then
                  lib.showTextUI(Strings.sell_material)
                  textUI = true
                end
                if IsControlJustReleased(0, 38) then
                  miningSellItems()
                end
            elseif dist >= 1.9 and textUI then
                sleep = 0
                lib.hideTextUI()
                textUI = nil
            elseif dist >= 31 and pedSpawned then
                local model = GetEntityModel(ped)
                SetModelAsNoLongerNeeded(model)
                DeletePed(ped)
                SetPedAsNoLongerNeeded(ped)
                RemoveAnimDict('mini@strip_club@idles@bouncer@base')
                pedSpawned = nil
            end
            Wait(sleep)
      end
    end)


ChatGPT 发表于 2025-7-6 01:20:20

下面是您给出的代码片段的注释和翻译:


-- 如果卖店功能启用
if Config.sellShop.enabled then
    -- 创建一个新线程
    CreateThread(function()
      -- 在指定坐标创建一个图标,图标类型为207,颜色为5,标题为sell_shop_blip,缩放为0.80
      CreateBlip(Config.sellShop.coords, 207, 5, Strings.sell_shop_blip, 0.80)
      
      local ped, pedSpawned-- 定义ped(NPC)和pedSpawned(标识NPC是否已生成)
      local textUI-- 定义文本用户界面变量
      
      -- 持续循环
      while true do
            local sleep = 1500-- 设置等待时间为1500毫秒
            local playerPed = cache.ped-- 获取玩家的ped(角色)
            local coords = GetEntityCoords(playerPed)-- 获取玩家当前坐标
            local dist = #(coords - Config.sellShop.coords)-- 计算玩家和卖店之间的距离
            
            -- 如果距离小于等于31并且NPC已生成
            if dist <= 31 and pedSpawned then
                local model = GetEntityModel(ped)-- 获取NPC模型
                SetModelAsNoLongerNeeded(model)-- 将模型设置为不再需要
                DeletePed(ped)-- 删除NPC
                SetPedAsNoLongerNeeded(ped)-- 将NPC设置为不再需要
                RemoveAnimDict('mini@strip_club@idles@bouncer@base')-- 移除动画字典
                pedSpawned = nil-- 重置pedSpawned状态
            end
            
            Wait(sleep)-- 等待指定时间
      end
    end)
end


### 注释翻译:
1. `if Config.sellShop.enabled then`:如果卖店功能启用
2. `CreateThread(function()`:创建一个新线程
3. `CreateBlip(Config.sellShop.coords, 207, 5, Strings.sell_shop_blip, 0.80)`:在指定坐标创建一个图标
4. `local ped, pedSpawned`:定义NPC和标识NPC是否已生成
5. `local textUI`:定义文本用户界面变量
6. `while true do`:持续循环
7. `local sleep = 1500`:设置等待时间为1500毫秒
8. `local playerPed = cache.ped`:获取玩家的角色
9. `local coords = GetEntityCoords(playerPed)`:获取玩家当前坐标
10. `local dist = #(coords - Config.sellShop.coords)`:计算玩家和卖店之间的距离
11. `if dist <= 31 and pedSpawned then`:如果距离小于等于31并且NPC已生成
12. `local model = GetEntityModel(ped)`:获取NPC模型
13. `SetModelAsNoLongerNeeded(model)`:将模型设置为不再需要
14. `DeletePed(ped)`:删除NPC
15. `SetPedAsNoLongerNeeded(ped)`:将NPC设置为不再需要
16. `RemoveAnimDict('mini@strip_club@idles@bouncer@base')`:移除动画字典
17. `pedSpawned = nil`:重置NPC生成状态
18. `Wait(sleep)`:等待指定时间

这段代码应该放在 `client.lua` 中,因为它涉及到创建客户端图标和处理与玩家位置相关的逻辑。
页: [1]
查看完整版本: 注释