搜索
开启左侧

[有效回答] 翻译一下

[复制链接]
waaaa 发表于 2024-4-29 20:14:44 | 显示全部楼层 |阅读模式
ESX = exports['es_extended']:getSharedObject()

local titlement = {}
RegisterNetEvent('0title0:selectTitle')
AddEventHandler('0title0:selectTitle', function(title)
    local elements = {{label = '关闭', value = 'close'}}
    for i=1, #title do
        local data1 = {label = title[i], value = title[i]}
        table.insert(elements, data1)
    end

    ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'title_menu', {
        title    = '称号系統',
        align    = 'top-left',
        elements = elements
    }, function(data, menu)
            if data.current.value == 'close' then
                TriggerServerEvent('0title0:offTittle')
                titlement['self'] = nil
                menu.close()
            else
                TriggerServerEvent('0title0:toggleTittle', data.current.value)
                titlement['self'] = data.current.value
                menu.close()
            end
        end, function(data, menu)
        menu.close()
    end)
end)

RegisterNetEvent('0title0:addTitle')
AddEventHandler('0title0:addTitle', function(ped, title)
    titlement[ped] = title
end)

RegisterNetEvent('0title0:removeTitle')
AddEventHandler('0title0:removeTitle', function(ped)
    titlement[ped] = nil
end)


Citizen.CreateThread(function()
    while true do
        local found = 0
        local self_ped = PlayerPedId()
        local self_coord = GetEntityCoords(self_ped)
        for pedid, title in pairs(titlement) do
            if pedid == 'self' then
                DrawText3D(self_coord.x,self_coord.y,self_coord.z+1.0, title)
                found = found + 1
            else
                local playerIdx = GetPlayerFromServerId(pedid)
                if  NetworkIsPlayerActive(playerIdx) then
                    local ped = GetPlayerPed(playerIdx)
                    if DoesEntityExist(ped) and ped ~= self_ped then
                        coords = GetEntityCoords(ped)
                        local dist = Vdist(coords, self_coord)
                        if dist <= Config.drawDistance then
                            DrawText3D(coords.x,coords.y,coords.z+1.0,title)
                            found = found + 1
                        end
                    end
                end
            end
        end
        if found == 0 then
            Citizen.Wait(500)
        else
            Citizen.Wait(0)
        end
    end
end)

function DrawText3D(x,y,z, text)
    local onScreen,_x,_y=World3dToScreen2d(x,y,z)
    local px,py,pz=table.unpack(GetGameplayCamCoords())
    local dist = GetDistanceBetweenCoords(px,py,pz, x,y,z, 1)

    local scale = (1/dist)*2
    local fov = (1/GetGameplayCamFov())*100
    local scale = scale*fov
    if onScreen then
        SetTextScale(0.0*scale, 0.35*scale)
        SetTextFont(0)
        SetTextProportional(true)
        SetTextScale(0.0, 0.35)
        SetTextColour(255, 255, 255, 255)
        SetTextDropshadow(0, 0, 0, 0, 255)
        SetTextEdge(2, 0, 0, 0, 150)
        SetTextDropShadow()
        SetTextOutline()
        SetTextEntry("STRING")
        SetTextCentre(true)
        AddTextComponentString(text)
        DrawText(_x,_y)
    end
end
回复 论坛版权

使用道具 举报

ChatGPT 发表于 2024-4-29 20:14:56 | 显示全部楼层
ESX = exports:getSharedObject()

local titlement = {}
RegisterNetEvent('0title0:selectTitle')
AddEventHandler('0title0:selectTitle', function(title)
    local elements = {{label = '关闭', value = 'close'}}
    for i=1, #title do
        local data1 = {label = title, value = title}
        table.insert(elements, data1)
    end

    ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'title_menu', {
        title    = '称号系统',
        align    = 'top-left',
        elements = elements
    }, function(data, menu)
            if data.current.value == 'close' then
                TriggerServerEvent('0title0:offTittle')
                titlement = nil
                menu.close()
            else
                TriggerServerEvent('0title0:toggleTittle', data.current.value)
                titlement = data.current.value
                menu.close()
            end
        end, function(data, menu)
        menu.close()
    end)
end)

RegisterNetEvent('0title0:addTitle')
AddEventHandler('0title0:addTitle', function(ped, title)
    titlement[ped] = title
end)

RegisterNetEvent('0title0:removeTitle')
AddEventHandler('0title0:removeTitle', function(ped)
    titlement[ped] = nil
end)


Citizen.CreateThread(function()
    while true do
        local found = 0
        local self_ped = PlayerPedId()
        local self_coord = GetEntityCoords(self_ped)
        for pedid, title in pairs(titlement) do
            if pedid == 'self' then
                DrawText3D(self_coord.x,self_coord.y,self_coord.z+1.0, title)
                found = found + 1
            else
                local playerIdx = GetPlayerFromServerId(pedid)
                if  NetworkIsPlayerActive(playerIdx) then
                    local ped = GetPlayerPed(playerIdx)
                    if DoesEntityExist(ped) and ped ~= self_ped then
                        coords = GetEntityCoords(ped)
                        local dist = Vdist(coords, self_coord)
                        if dist < 15.0 then
                            DrawText3D(coords.x,coords.y,coords.z+1.0, title)
                            found = found + 1
                        end
                    end
                end
            end
        end
        Citizen.Wait(0)
    end
end)
```
此代码应放在服务器的脚本文件server.lua中。
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-2-9 01:50 , Processed in 0.095381 second(s), 10 queries , Gzip On, Redis On.

Powered by Discuz! X3.4

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

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