搜索
开启左侧

帮我写一个HUD

[复制链接]
FIVEM 0.0 发表于 2024-3-28 12:36:09 | 显示全部楼层 |阅读模式

带吃喝和速度表的

吃喝显示屏幕中间下面

ʚ 七时吉祥 ɞ 12:35:51
速度表显示在右下角


回复 论坛版权

使用道具 举报

ChatGPT 发表于 2024-3-28 12:36:26 | 显示全部楼层
当然,我可以帮你编写一个HUD。请将以下代码放在客户端的脚本文件中:
-- 创建一个全局变量用于保存当前的饥渴度和喝水量
local hunger = 0
local thirst = 0

-- 创建一个函数用于显示吃喝信息
function DrawHungerAndThirst()
    -- 获取屏幕宽度和高度
    local screenWidth, screenHeight = GetScreenResolution()

    -- 设置文本的位置和大小
    local textX = screenWidth / 2
    local textY = screenHeight - 50
    local textSize = 0.3

    -- 绘制饥渴度和喝水量文本
    SetTextFont(4)
    SetTextProportional(1)
    SetTextScale(textSize, textSize)
    SetTextColour(255, 255, 255, 255)
    SetTextDropShadow(0, 0, 0, 0, 255)
    SetTextEdge(2, 0, 0, 0, 255)
    SetTextCentre(true)

    -- 格式化饥渴度和喝水量文本
    local hungerText = string.format("饥渴度: %.1f%%", hunger)
    local thirstText = string.format("喝水量: %.1f%%", thirst)

    -- 绘制文本
    BeginTextCommandDisplayText("STRING")
    AddTextComponentSubstringPlayerName(hungerText)
    EndTextCommandDisplayText(textX, textY)

    textY = textY + 30

    BeginTextCommandDisplayText("STRING")
    AddTextComponentSubstringPlayerName(thirstText)
    EndTextCommandDisplayText(textX, textY)
end

-- 创建一个函数用于显示速度表
function DrawSpeedometer(speed)
    -- 获取屏幕宽度和高度
    local screenWidth, screenHeight = GetScreenResolution()

    -- 设置文本的位置和大小
    local textX = screenWidth - 100
    local textY = screenHeight - 50
    local textSize = 0.3

    -- 绘制速度文本
    SetTextFont(4)
    SetTextProportional(1)
    SetTextScale(textSize, textSize)
    SetTextColour(255, 255, 255, 255)
    SetTextDropShadow(0, 0, 0, 0, 255)
    SetTextEdge(2, 0, 0, 0, 255)
    SetTextCentre(true)

    local speedText = string.format("速度: %d km/h", speed)

    -- 绘制文本
    BeginTextCommandDisplayText("STRING")
    AddTextComponentSubstringPlayerName(speedText)
    EndTextCommandDisplayText(textX, textY)
end

-- 创建一个循环函数用于更新HUD
Citizen.CreateThread(function()
    while true do
        -- 获取玩家的坐标和车辆
        local playerPed = PlayerPedId()
        local vehicle = GetVehiclePedIsIn(playerPed, false)

        -- 如果玩家在车内
        if IsPedInAnyVehicle(playerPed, false) then
            -- 获取车辆的速度
            local speed = GetEntitySpeed(vehicle) * 3.6

            -- 调用显示速度表的函数
            DrawSpeedometer(speed)
        end

        -- 调用显示吃喝信息的函数
        DrawHungerAndThirst()

        -- 暂停一秒钟
        Citizen.Wait(1000)
    end
end)

-- 创建一个事件监听函数用于更新饥渴度和喝水量
RegisterNetEvent('hud:updateHungerAndThirst')
AddEventHandler('hud:updateHungerAndThirst', function(newHunger, newThirst)
    hunger = newHunger
    thirst = newThirst
end)

请确保你在服务器的资源文件中注册并触发`hud:updateHungerAndThirst`事件,将新的`hunger`和`thirst`值传递到客户端以更新饥渴度和喝水量信息。

希望这个HUD满足你的需求!
回复

使用道具 举报

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

本版积分规则

QQ|Archiver|手机版|小黑屋|首页 ( 冀ICP备2021005225号-1 ) |网站地图

GMT+8, 2025-2-9 05:04 , Processed in 0.051912 second(s), 11 queries , Gzip On, Redis On.

Powered by Discuz! X3.4

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

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