赴爱 发表于 2025-5-6 18:18:04

注释


RegisterNetEvent('shx-idcard:client:buyPDBadge')
AddEventHandler('shx-idcard:client:buyPDBadge', function(whynot)
    if Config.Framework == "qbcore" then
      if QBCore.Functions.GetPlayerData().job.name == whynot.job then
            if Config.oxlibRequire and Config.MenuType == "ox_lib" then
                local alert = lib.alertDialog({
                content = Lang["buytext"].." $"..whynot.price,
                centered = true,
                cancel = true
                })
                if alert == "confirm" then
                  TriggerServerEvent("shx-idcard:server:buyRequest", whynot.price, "pdbadge")
                end
            elseif Config.MenuType == "qb_menu" then
                local dialog = exports['qb-input']:ShowInput({
                  header = Lang["idcardMenu"],
                  submitText = "Accept",
                  inputs = {
                        {
                            text = Lang["buytext"].." $"..whynot.price, -- text you want to be displayed as a input header
                            name = "buytype", -- name of the input should be unique otherwise it might override
                            type = "radio", -- type of the input - Radio is useful for "or" options e.g; billtype = Cash OR Bill OR bank
                            options = { -- The options (in this case for a radio) you want displayed, more than 6 is not recommended
                              { value = "no", text = "No" }, -- Options MUST include a value and a text option
                              { value = "yes", text = "Yes" }, -- Options MUST include a value and a text option
                            },
                        },
                  },
                })
                if dialog.buytype == "yes" then
                  TriggerServerEvent("shx-idcard:server:buyRequest", whynot.price, "pdbadge")
                end
            end


ChatGPT 发表于 2025-5-6 18:18:17

以下是代码的注释和中文翻译:


-- 注册一个网络事件 'shx-idcard:client:buyPDBadge'
RegisterNetEvent('shx-idcard:client:buyPDBadge')

-- 添加事件处理器,当事件被触发时会执行以下函数
AddEventHandler('shx-idcard:client:buyPDBadge', function(whynot)
    -- 检查框架是否为 "qbcore"
    if Config.Framework == "qbcore" then
      -- 检查玩家的工作是否与传入的参数相符
      if QBCore.Functions.GetPlayerData().job.name == whynot.job then
            -- 如果配置要求 oxlib,并且菜单类型为 "ox_lib"
            if Config.oxlibRequire and Config.MenuType == "ox_lib" then
                -- 弹出警告对话框,询问用户是否确认购买
                local alert = lib.alertDialog({
                  content = Lang("buytext") .. " $" .. whynot.price, -- 显示的内容
                  centered = true, -- 对话框居中显示
                  cancel = true -- 允许取消操作
                })
                -- 如果用户选择确认
                if alert == "confirm" then
                  -- 触发服务器事件,请求购买徽章
                  TriggerServerEvent("shx-idcard:server:buyRequest", whynot.price, "pdbadge")
                end
            -- 如果菜单类型为 "qb_menu"
            elseif Config.MenuType == "qb_menu" then
                -- 显示输入对话框,询问用户是否接受购买
                local dialog = exports['qb-input']:ShowInput({
                  header = Lang("idcardMenu"), -- 输入对话框的标题
                  submitText = "Accept", -- 提交文本
                  inputs = {
                        {
                            text = Lang("buytext") .. " $" .. whynot.price, -- 显示的输入头部文本
                            name = "buytype", -- 输入的名称,应该是唯一的
                            type = "radio", -- 输入的类型 - 单选
                            options = { -- 选项
                              { value = "no", text = "No" }, -- 选项必须包含值和文本
                              { value = "yes", text = "Yes" }, -- 选项必须包含值和文本
                            },
                        },
                  },
                })
                -- 如果用户选择了 "yes"
                if dialog.buytype == "yes" then
                  -- 触发服务器事件,请求购买徽章
                  TriggerServerEvent("shx-idcard:server:buyRequest", whynot.price, "pdbadge")
                end
            end
      end
    end
end)


这段代码应该放在 `Client.lua` 中,因为它涉及到客户端的事件处理和用户界面交互。
页: [1]
查看完整版本: 注释