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
|