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, 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['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 = title
end)

RegisterNetEvent('0title0:removeTitle')
AddEventHandler('0title0:removeTitle', function(ped)
    titlement = 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)
                ifNetworkIsPlayerActive(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 = title
end)

RegisterNetEvent('0title0:removeTitle')
AddEventHandler('0title0:removeTitle', function(ped)
    titlement = 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)
                ifNetworkIsPlayerActive(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中。
页: [1]
查看完整版本: 翻译一下