forked from Simnation/Main
ed
This commit is contained in:
parent
a45e43f22a
commit
123ea8a800
79 changed files with 3338 additions and 157 deletions
|
@ -1,152 +0,0 @@
|
|||
-- train_interaction.lua
|
||||
|
||||
-- Configuration for the interaction point
|
||||
local interactionPoint = {
|
||||
coords = vector3(126.0, -1037.0, 29.3), -- Change to your desired location
|
||||
radius = 2.0,
|
||||
text = "Press ~INPUT_CONTEXT~ to use train transportation"
|
||||
}
|
||||
|
||||
-- Available scenarios
|
||||
local scenarios = {
|
||||
{name = "Welcome", label = "City Center"},
|
||||
{name = "Jail", label = "Prison"},
|
||||
{name = "Paleto", label = "Paleto Bay"}
|
||||
}
|
||||
|
||||
-- Variables
|
||||
local isInMarker = false
|
||||
local menuOpen = false
|
||||
|
||||
-- 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
|
||||
|
||||
-- Function to open scenario selection menu
|
||||
function OpenScenarioMenu()
|
||||
menuOpen = true
|
||||
|
||||
-- Simple menu display
|
||||
Citizen.CreateThread(function()
|
||||
local selected = 1
|
||||
|
||||
while menuOpen do
|
||||
Citizen.Wait(0)
|
||||
|
||||
-- Draw background
|
||||
DrawRect(0.5, 0.5, 0.3, 0.5, 0, 0, 0, 200)
|
||||
|
||||
-- Draw title
|
||||
SetTextFont(4)
|
||||
SetTextScale(0.5, 0.5)
|
||||
SetTextColour(255, 255, 255, 255)
|
||||
SetTextCentre(true)
|
||||
SetTextEntry("STRING")
|
||||
AddTextComponentString("Train Transportation")
|
||||
DrawText(0.5, 0.3)
|
||||
|
||||
-- Draw options
|
||||
for i, scenario in ipairs(scenarios) do
|
||||
local y = 0.35 + (i * 0.05)
|
||||
local color = {r = 255, g = 255, b = 255}
|
||||
|
||||
if selected == i then
|
||||
color = {r = 255, g = 255, b = 0}
|
||||
DrawRect(0.5, y, 0.28, 0.04, 41, 41, 41, 200)
|
||||
end
|
||||
|
||||
SetTextFont(4)
|
||||
SetTextScale(0.35, 0.35)
|
||||
SetTextColour(color.r, color.g, color.b, 255)
|
||||
SetTextCentre(true)
|
||||
SetTextEntry("STRING")
|
||||
AddTextComponentString(scenario.label)
|
||||
DrawText(0.5, y - 0.015)
|
||||
end
|
||||
|
||||
-- Instructions
|
||||
SetTextFont(4)
|
||||
SetTextScale(0.3, 0.3)
|
||||
SetTextColour(255, 255, 255, 255)
|
||||
SetTextCentre(true)
|
||||
SetTextEntry("STRING")
|
||||
AddTextComponentString("↑/↓: Navigate | ENTER: Select | BACKSPACE: Cancel")
|
||||
DrawText(0.5, 0.65)
|
||||
|
||||
-- Handle controls
|
||||
DisableControlAction(0, 172, true) -- UP
|
||||
DisableControlAction(0, 173, true) -- DOWN
|
||||
DisableControlAction(0, 176, true) -- ENTER
|
||||
DisableControlAction(0, 177, true) -- BACKSPACE
|
||||
|
||||
if IsDisabledControlJustPressed(0, 172) then -- UP
|
||||
selected = selected - 1
|
||||
if selected < 1 then selected = #scenarios end
|
||||
PlaySoundFrontend(-1, "NAV_UP_DOWN", "HUD_FRONTEND_DEFAULT_SOUNDSET", true)
|
||||
elseif IsDisabledControlJustPressed(0, 173) then -- DOWN
|
||||
selected = selected + 1
|
||||
if selected > #scenarios then selected = 1 end
|
||||
PlaySoundFrontend(-1, "NAV_UP_DOWN", "HUD_FRONTEND_DEFAULT_SOUNDSET", true)
|
||||
elseif IsDisabledControlJustPressed(0, 176) then -- ENTER
|
||||
menuOpen = false
|
||||
PlaySoundFrontend(-1, "SELECT", "HUD_FRONTEND_DEFAULT_SOUNDSET", true)
|
||||
TriggerEvent('train:startscenario', scenarios[selected].name)
|
||||
elseif IsDisabledControlJustPressed(0, 177) then -- BACKSPACE
|
||||
menuOpen = false
|
||||
PlaySoundFrontend(-1, "CANCEL", "HUD_FRONTEND_DEFAULT_SOUNDSET", true)
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
-- Main thread for checking player position
|
||||
Citizen.CreateThread(function()
|
||||
while true do
|
||||
Citizen.Wait(0)
|
||||
|
||||
local playerPed = PlayerPedId()
|
||||
local coords = GetEntityCoords(playerPed)
|
||||
local dist = #(coords - interactionPoint.coords)
|
||||
|
||||
if dist < interactionPoint.radius then
|
||||
isInMarker = true
|
||||
Draw3DText(interactionPoint.coords.x, interactionPoint.coords.y, interactionPoint.coords.z + 1.0, interactionPoint.text)
|
||||
|
||||
-- Check for E press
|
||||
if IsControlJustReleased(0, 38) and not menuOpen then -- 38 is E
|
||||
OpenScenarioMenu()
|
||||
end
|
||||
else
|
||||
isInMarker = false
|
||||
if menuOpen then
|
||||
menuOpen = false
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
-- Create a blip on the map (optional)
|
||||
Citizen.CreateThread(function()
|
||||
local blip = AddBlipForCoord(interactionPoint.coords)
|
||||
SetBlipSprite(blip, 513) -- Train sprite
|
||||
SetBlipDisplay(blip, 4)
|
||||
SetBlipScale(blip, 0.8)
|
||||
SetBlipColour(blip, 2)
|
||||
SetBlipAsShortRange(blip, true)
|
||||
BeginTextCommandSetBlipName("STRING")
|
||||
AddTextComponentString("Train Transportation")
|
||||
EndTextCommandSetBlipName(blip)
|
||||
end)
|
|
@ -0,0 +1,133 @@
|
|||
-- 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)
|
Loading…
Add table
Add a link
Reference in a new issue