2026-04-14 17:41:39 +02:00

217 lines
9.2 KiB
Lua

function DrawText3D(x, y, z, text)
-- Use local function instead
SetTextScale(0.35, 0.35)
SetTextFont(4)
SetTextProportional(1)
SetTextColour(255, 255, 255, 215)
SetTextEntry('STRING')
SetTextCentre(true)
AddTextComponentString(text)
SetDrawOrigin(x, y, z, 0)
DrawText(0.0, 0.0)
local factor = (string.len(text)) / 370
DrawRect(0.0, 0.0 + 0.0125, 0.017 + factor, 0.03, 0, 0, 0, 75)
ClearDrawOrigin()
end
RegisterNetEvent('esx:playerLoaded')
AddEventHandler('esx:playerLoaded', function()
TriggerServerEvent('codem-vehicleshopv2:CheckJobData')
end)
RegisterNetEvent('QBCore:Client:OnPlayerLoaded')
AddEventHandler('QBCore:Client:OnPlayerLoaded', function()
TriggerServerEvent('codem-vehicleshopv2:CheckJobData')
end)
function InteractionHandler()
for _,v in pairs(Config.VehicleShops) do
BossMenuDrawMarkerLoop(v)
end
end
CreateThread(function()
local isTextUiOpen = {}
while true do
local cd = 1000
local ped = PlayerPedId()
local pedCoords = GetEntityCoords(ped)
local markerData = Config.InteractionHandler.marker
local nearAnyShop = false
for _, shop in pairs(Config.VehicleShops) do
local shopCoords = shop.vehicleshop.location
local dist = #(pedCoords - shopCoords)
if dist < 3.0 then
cd = 0
nearAnyShop = true
if not isTextUiOpen[shop.id] then
isTextUiOpen[shop.id] = false
end
if Config.InteractionHandler.drawtext then
DrawText3D(shopCoords.x, shopCoords.y, shopCoords.z + 0.3, Config.InteractionHandler.vehicleshop_text)
end
if Config.InteractionHandler.marker then
DrawMarker(
markerData.type, shopCoords.x, shopCoords.y, shopCoords.z - 0.1,
0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
markerData.size, markerData.size, markerData.size,
markerData.r, markerData.g, markerData.b, markerData.a,
false, false, 0, true, false, false, false
)
end
if not isTextUiOpen[shop.id] then
OpenTextUI(shop.id)
isTextUiOpen[shop.id] = true
end
if IsControlJustPressed(0, Config.InteractionHandler.openKey) then
openVehicleShop(shop.id)
end
else
if isTextUiOpen[shop.id] then
CloseTextUI(shop.id)
isTextUiOpen[shop.id] = false
end
end
end
if not nearAnyShop then
for shopId, open in pairs(isTextUiOpen) do
if open then
CloseTextUI(shopId)
isTextUiOpen[shopId] = false
end
end
end
Wait(cd)
end
end)
function OpenTextUI(shopId)
local shopText = Config.InteractionHandler.vehicleshop_text
if Config.InteractionHandler.codemtextui.enable then
exports["codem-textui"]:OpenTextUI(shopText, Config.InteractionHandler.codemtextui.keytext, Config.InteractionHandler.codemtextui.theme)
elseif Config.InteractionHandler.okoktextui.enable then
exports['okokTextUI']:Open(shopText, Config.InteractionHandler.okoktextui.color, Config.InteractionHandler.okoktextui.position)
elseif Config.InteractionHandler.ethTextUI.enable then
exports['eth-textUi']:Show('', shopText)
elseif Config.InteractionHandler.qb_textui.enable then
TriggerEvent('qb-core:client:DrawText', shopText, 'left')
elseif Config.InteractionHandler.esx_textui.enable then
TriggerEvent('ESX:TextUI', shopText)
end
end
function CloseTextUI()
if Config.InteractionHandler.codemtextui.enable then
exports["codem-textui"]:CloseTextUI()
end
if Config.InteractionHandler.okoktextui.enable then
exports['okokTextUI']:Close()
end
if Config.InteractionHandler.ethTextUI.enable then
exports['eth-textUi']:Close()
end
if Config.InteractionHandler.esx_textui.enable then
TriggerEvent('ESX:HideUI')
end
if Config.InteractionHandler.qb_textui.enable then
TriggerEvent('qb-core:client:HideText')
end
end
function OpenTextUI(shopId)
local shopText = Config.InteractionHandler.vehicleshop_text
if Config.InteractionHandler.codemtextui.enable then
exports["codem-textui"]:OpenTextUI(shopText, Config.InteractionHandler.codemtextui.keytext, Config.InteractionHandler.codemtextui.theme)
elseif Config.InteractionHandler.okoktextui.enable then
exports['okokTextUI']:Open(shopText, Config.InteractionHandler.okoktextui.color, Config.InteractionHandler.okoktextui.position)
elseif Config.InteractionHandler.ethTextUI.enable then
exports['eth-textUi']:Show('', shopText)
elseif Config.InteractionHandler.qb_textui.enable then
TriggerEvent('qb-core:client:DrawText', shopText, 'left')
elseif Config.InteractionHandler.esx_textui.enable then
TriggerEvent('ESX:TextUI', shopText)
end
end
function BossMenuDrawMarkerLoop(data)
if not jobData then
return
end
if data.id == jobData.vehicleShopId then
CreateThread(function()
local markerData = Config.InteractionHandler.marker
local ped = PlayerPedId()
local isTextUiOpen = false
while jobData do
local cd = 1000
local dist = #(data.bossmenu.location - GetEntityCoords(ped))
if dist < 3.5 then
cd = 0
if Config.InteractionHandler.drawtext then
DrawText3D(data.bossmenu.location.x, data.bossmenu.location.y, data.bossmenu.location.z+0.3, Config.InteractionHandler.bossmenu_text)
end
if Config.InteractionHandler.marker then
DrawMarker(markerData.type, data.bossmenu.location.x, data.bossmenu.location.y, data.bossmenu.location.z-0.1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, markerData.size, markerData.size, markerData.size, markerData.r, markerData.g, markerData.b, markerData.a, false, false, 0, true, false, false, false)
end
if not isTextUiOpen and Config.InteractionHandler.codemtextui.enable then
isTextUiOpen = true
exports["codem-textui"]:OpenTextUI(Config.InteractionHandler.bossmenu_text, Config.InteractionHandler.codemtextui.keytext, Config.InteractionHandler.codemtextui.theme)
end
if not isTextUiOpen and Config.InteractionHandler.okoktextui.enable then
isTextUiOpen = true
exports['okokTextUI']:Open(Config.InteractionHandler.bossmenu_text, Config.InteractionHandler.okoktextui.color, Config.InteractionHandler.okoktextui.position)
end
if not isTextUiOpen and Config.InteractionHandler.ethTextUI.enable then
isTextUiOpen = true
exports['eth-textUi']:Show('', Config.InteractionHandler.bossmenu_text)
end
if not isTextUiOpen and Config.InteractionHandler.qb_textui.enable then
isTextUiOpen = true
TriggerEvent('qb-core:client:DrawText', Config.InteractionHandler.bossmenu_text, 'left')
end
if not isTextUiOpen and Config.InteractionHandler.esx_textui.enable then
isTextUiOpen = true
TriggerEvent('ESX:TextUI', Config.InteractionHandler.bossmenu_text)
end
if IsControlJustPressed(0, Config.InteractionHandler.openKey) then
openBossMenu()
end
else
if isTextUiOpen and Config.InteractionHandler.codemtextui.enable then
exports["codem-textui"]:CloseTextUI()
isTextUiOpen = false
end
if isTextUiOpen and Config.InteractionHandler.okoktextui.enable then
exports['okokTextUI']:Close()
isTextUiOpen = false
end
if isTextUiOpen and Config.InteractionHandler.ethTextUI.enable then
exports['eth-textUi']:Close()
isTextUiOpen = false
end
if isTextUiOpen and Config.InteractionHandler.esx_textui.enable then
TriggerEvent('ESX:HideUI')
isTextUiOpen = false
end
if isTextUiOpen and Config.InteractionHandler.qb_textui.enable then
TriggerEvent('qb-core:client:HideText')
isTextUiOpen = false
end
end
Wait(cd)
end
end)
end
end