1
0
Fork 0
forked from Simnation/Main
This commit is contained in:
Nordi98 2025-07-30 02:46:15 +02:00
parent d2994aa88b
commit 7c23484c7c
2 changed files with 383 additions and 258 deletions

View file

@ -8,11 +8,16 @@ local meterRunning = false
local currentFare = 0
local lastTaxiCall = 0
print("^2[TAXI DEBUG]^7 Client script loaded")
-- Taxi rufen Command (Mobile Taxi)
RegisterCommand('taxi', function()
print("^2[TAXI DEBUG]^7 /taxi command executed")
local currentTime = GetGameTimer()
if currentTime - lastTaxiCall < (Config.TaxiCallCooldown * 1000) then
local remainingTime = math.ceil((Config.TaxiCallCooldown * 1000 - (currentTime - lastTaxiCall)) / 1000)
print("^1[TAXI DEBUG]^7 Cooldown active: " .. remainingTime .. " seconds")
lib.notify({
title = 'Taxi Service',
description = 'Du musst noch ' .. remainingTime .. ' Sekunden warten',
@ -22,6 +27,7 @@ RegisterCommand('taxi', function()
end
if currentTaxi then
print("^1[TAXI DEBUG]^7 Taxi already exists")
lib.notify({
title = 'Taxi Service',
description = 'Du hast bereits ein Taxi gerufen',
@ -30,10 +36,12 @@ RegisterCommand('taxi', function()
return
end
print("^2[TAXI DEBUG]^7 Calling mobile taxi...")
CallMobileTaxi()
end)
function CallMobileTaxi()
print("^2[TAXI DEBUG]^7 CallMobileTaxi function started")
lastTaxiCall = GetGameTimer()
lib.notify({
@ -43,34 +51,81 @@ function CallMobileTaxi()
})
CreateThread(function()
print("^2[TAXI DEBUG]^7 Taxi spawn thread started")
local playerPed = PlayerPedId()
local playerCoords = GetEntityCoords(playerPed)
print("^2[TAXI DEBUG]^7 Player coords: " .. tostring(playerCoords))
-- Prüfe ob Config existiert
if not Config.MobileTaxiSpawns then
print("^1[TAXI DEBUG]^7 Config.MobileTaxiSpawns not found!")
return
end
-- Zufällige Spawn-Location wählen
local spawnLocation = Config.MobileTaxiSpawns[math.random(#Config.MobileTaxiSpawns)]
print("^2[TAXI DEBUG]^7 Spawn location: " .. tostring(spawnLocation))
-- Zufälliges Taxi-Fahrzeug wählen
local selectedVehicle = SelectRandomTaxi()
print("^2[TAXI DEBUG]^7 Selected vehicle: " .. selectedVehicle.model)
-- Fahrzeug spawnen
local vehicleHash = GetHashKey(selectedVehicle.model)
print("^2[TAXI DEBUG]^7 Vehicle hash: " .. vehicleHash)
RequestModel(vehicleHash)
while not HasModelLoaded(vehicleHash) do
local timeout = GetGameTimer() + 10000
while not HasModelLoaded(vehicleHash) and GetGameTimer() < timeout do
print("^3[TAXI DEBUG]^7 Waiting for model to load...")
Wait(100)
end
if not HasModelLoaded(vehicleHash) then
print("^1[TAXI DEBUG]^7 Failed to load vehicle model!")
return
end
print("^2[TAXI DEBUG]^7 Creating vehicle...")
currentTaxi = CreateVehicle(vehicleHash, spawnLocation.x, spawnLocation.y, spawnLocation.z, spawnLocation.w, true, false)
if not DoesEntityExist(currentTaxi) then
print("^1[TAXI DEBUG]^7 Failed to create vehicle!")
return
end
print("^2[TAXI DEBUG]^7 Vehicle created successfully: " .. currentTaxi)
SetEntityAsMissionEntity(currentTaxi, true, true)
SetVehicleOnGroundProperly(currentTaxi)
-- Fahrer spawnen
local driverHash = GetHashKey("a_m_m_taxi_01")
RequestModel(driverHash)
while not HasModelLoaded(driverHash) do
timeout = GetGameTimer() + 10000
while not HasModelLoaded(driverHash) and GetGameTimer() < timeout do
print("^3[TAXI DEBUG]^7 Waiting for driver model to load...")
Wait(100)
end
if not HasModelLoaded(driverHash) then
print("^1[TAXI DEBUG]^7 Failed to load driver model!")
DeleteEntity(currentTaxi)
currentTaxi = nil
return
end
print("^2[TAXI DEBUG]^7 Creating driver...")
taxiDriver = CreatePedInsideVehicle(currentTaxi, 26, driverHash, -1, true, false)
if not DoesEntityExist(taxiDriver) then
print("^1[TAXI DEBUG]^7 Failed to create driver!")
DeleteEntity(currentTaxi)
currentTaxi = nil
return
end
print("^2[TAXI DEBUG]^7 Driver created successfully: " .. taxiDriver)
SetEntityAsMissionEntity(taxiDriver, true, true)
SetPedFleeAttributes(taxiDriver, 0, 0)
SetPedCombatAttributes(taxiDriver, 17, 1)
@ -87,15 +142,22 @@ function CallMobileTaxi()
BeginTextCommandSetBlipName("STRING")
AddTextComponentString("Taxi")
EndTextCommandSetBlipName(taxiBlip)
print("^2[TAXI DEBUG]^7 Blip created")
-- Zum Spieler fahren
print("^2[TAXI DEBUG]^7 Sending taxi to player...")
TaskVehicleDriveToCoord(taxiDriver, currentTaxi, playerCoords.x, playerCoords.y, playerCoords.z, 20.0, 0, vehicleHash, 786603, 1.0, true)
-- Warten bis Taxi ankommt
local arrived = false
local timeout = GetGameTimer() + (Config.MaxWaitTime * 1000)
timeout = GetGameTimer() + (Config.MaxWaitTime * 1000)
while not arrived and GetGameTimer() < timeout do
if not DoesEntityExist(currentTaxi) or not DoesEntityExist(taxiDriver) then
print("^1[TAXI DEBUG]^7 Taxi or driver disappeared!")
break
end
local taxiCoords = GetEntityCoords(currentTaxi)
local distance = #(playerCoords - taxiCoords)
@ -103,6 +165,7 @@ function CallMobileTaxi()
arrived = true
TaskVehicleTempAction(taxiDriver, currentTaxi, 27, 3000)
print("^2[TAXI DEBUG]^7 Taxi arrived!")
lib.notify({
title = 'Taxi Service',
description = 'Dein Taxi ist angekommen! Steige ein.',
@ -115,6 +178,7 @@ function CallMobileTaxi()
end
if not arrived then
print("^1[TAXI DEBUG]^7 Taxi failed to arrive in time")
lib.notify({
title = 'Taxi Service',
description = 'Das Taxi konnte dich nicht erreichen',
@ -126,6 +190,11 @@ function CallMobileTaxi()
end
function SelectRandomTaxi()
if not Config.TaxiVehicles or #Config.TaxiVehicles == 0 then
print("^1[TAXI DEBUG]^7 No taxi vehicles configured!")
return {model = 'taxi', pricePerKm = 5}
end
local totalChance = 0
for _, vehicle in pairs(Config.TaxiVehicles) do
totalChance = totalChance + vehicle.spawnChance
@ -145,6 +214,7 @@ function SelectRandomTaxi()
end
function WaitForPlayerToEnter(pricePerKm)
print("^2[TAXI DEBUG]^7 Waiting for player to enter...")
CreateThread(function()
local timeout = GetGameTimer() + 60000
@ -153,6 +223,7 @@ function WaitForPlayerToEnter(pricePerKm)
if IsPedInVehicle(playerPed, currentTaxi, false) then
inTaxi = true
print("^2[TAXI DEBUG]^7 Player entered taxi")
OpenMobileTaxiMenu(pricePerKm)
break
end
@ -161,6 +232,7 @@ function WaitForPlayerToEnter(pricePerKm)
end
if not inTaxi then
print("^1[TAXI DEBUG]^7 Player didn't enter taxi in time")
lib.notify({
title = 'Taxi Service',
description = 'Das Taxi ist weggefahren',
@ -172,6 +244,7 @@ function WaitForPlayerToEnter(pricePerKm)
end
function OpenMobileTaxiMenu(pricePerKm)
print("^2[TAXI DEBUG]^7 Opening mobile taxi menu")
local options = {}
-- Bekannte Ziele hinzufügen
@ -230,8 +303,12 @@ function OpenMobileTaxiMenu(pricePerKm)
end
function StartMobileTaxiRide(destination, price)
if not currentTaxi or not taxiDriver then return end
if not currentTaxi or not taxiDriver then
print("^1[TAXI DEBUG]^7 No taxi or driver for ride")
return
end
print("^2[TAXI DEBUG]^7 Starting taxi ride to: " .. tostring(destination))
currentFare = price
meterRunning = true
@ -262,6 +339,7 @@ function StartMobileTaxiRide(destination, price)
if distance < 10.0 then
TaskVehicleTempAction(taxiDriver, currentTaxi, 27, 3000)
print("^2[TAXI DEBUG]^7 Arrived at destination")
lib.notify({
title = 'Taxi Service',
description = 'Du bist angekommen! Preis: $' .. currentFare,
@ -288,6 +366,7 @@ function CalculateDistance(coords)
end
function ExitMobileTaxi()
print("^2[TAXI DEBUG]^7 Player exiting taxi")
local playerPed = PlayerPedId()
TaskLeaveVehicle(playerPed, currentTaxi, 0)
@ -303,6 +382,7 @@ function ExitMobileTaxi()
end
function CleanupMobileTaxi()
print("^2[TAXI DEBUG]^7 Cleaning up mobile taxi")
meterRunning = false
inTaxi = false