搜索
开启左侧

注释

[复制链接]
赴爱 发表于 前天 18:18 | 显示全部楼层 |阅读模式

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 发表于 前天 18:18 | 显示全部楼层
以下是代码的注释和中文翻译:
-- 注册一个网络事件 '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` 中,因为它涉及到客户端的事件处理和用户界面交互。
回复

使用道具 举报

文明发言,和谐互动
文明发言,和谐互动
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|FiveM技术教程分享 ( 冀ICP备2021005225号-1 ) |网站地图

GMT+8, 2025-5-8 08:08 , Processed in 0.093822 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

© 2001-2013 ELITE论坛【技术无价-分享快乐】

快速回复 返回顶部 返回列表