1
0
Fork 0
forked from Simnation/Main
Main/resources/[tools]/cfx_nteam_train_scenario/train_interaction_points.lua

134 lines
4.1 KiB
Lua
Raw Normal View History

2025-08-13 19:56:48 +02:00
-- train_interaction_points.lua
-- Configuration for interaction points
local interactionPoints = {
{
coords = vector3(126.0, -1037.0, 29.3), -- City center location (change as needed)
scenario = "Welcome",
text = "Press ~INPUT_CONTEXT~ to take train to City Center",
blip = {
sprite = 513, -- Train sprite
color = 2,
name = "Train to City Center"
}
},
{
coords = vector3(1851.5, 2585.7, 45.67), -- Near prison (change as needed)
scenario = "Jail",
text = "Press ~INPUT_CONTEXT~ to take train to Prison",
blip = {
sprite = 513, -- Train sprite
color = 1,
name = "Train to Prison"
}
},
{
coords = vector3(-459.9, 5368.5, 81.3), -- Paleto area (change as needed)
scenario = "Paleto",
text = "Press ~INPUT_CONTEXT~ to take train to Paleto Bay",
blip = {
sprite = 513, -- Train sprite
color = 5,
name = "Train to Paleto Bay"
}
}
-- Add more interaction points as needed
}
-- Variables
local isInMarker = false
local currentPoint = nil
local interactionRadius = 2.0
-- Function to draw 3D text
function Draw3DText(x, y, z, text)
local onScreen, _x, _y = World3dToScreen2d(x, y, z)
local px, py, pz = table.unpack(GetGameplayCamCoords())
SetTextScale(0.35, 0.35)
SetTextFont(4)
SetTextProportional(1)
SetTextColour(255, 255, 255, 215)
SetTextEntry("STRING")
SetTextCentre(1)
AddTextComponentString(text)
DrawText(_x, _y)
local factor = (string.len(text)) / 370
DrawRect(_x, _y + 0.0125, 0.015 + factor, 0.03, 41, 11, 41, 68)
end
-- Main thread for checking player position
Citizen.CreateThread(function()
-- Create blips for all interaction points
for _, point in ipairs(interactionPoints) do
if point.blip then
local blip = AddBlipForCoord(point.coords)
SetBlipSprite(blip, point.blip.sprite)
SetBlipDisplay(blip, 4)
SetBlipScale(blip, 0.8)
SetBlipColour(blip, point.blip.color)
SetBlipAsShortRange(blip, true)
BeginTextCommandSetBlipName("STRING")
AddTextComponentString(point.blip.name)
EndTextCommandSetBlipName(blip)
end
end
while true do
Citizen.Wait(0)
local playerPed = PlayerPedId()
local coords = GetEntityCoords(playerPed)
isInMarker = false
currentPoint = nil
-- Check if player is near any interaction point
for _, point in ipairs(interactionPoints) do
local dist = #(coords - point.coords)
if dist < interactionRadius then
isInMarker = true
currentPoint = point
Draw3DText(point.coords.x, point.coords.y, point.coords.z + 1.0, point.text)
-- Check for E press
if IsControlJustReleased(0, 38) then -- 38 is E
-- Start the specific scenario for this point
TriggerEvent('train:startscenario', point.scenario)
-- Add a small cooldown to prevent spam
Citizen.Wait(1000)
end
break
end
end
-- Optimization: If not near any point, wait longer
if not isInMarker then
Citizen.Wait(500)
end
end
end)
-- Optional: Add a notification when player enters/exits an interaction zone
Citizen.CreateThread(function()
local wasInMarker = false
while true do
Citizen.Wait(500)
if isInMarker and not wasInMarker then
-- Player just entered an interaction zone
-- You can add a notification here if desired
-- TriggerEvent('notification', 'You can take a train from here')
wasInMarker = true
elseif not isInMarker and wasInMarker then
-- Player just left an interaction zone
wasInMarker = false
end
end
end)