Skip to content

Commit

Permalink
Merge pull request #84 from t0r3tto/main
Browse files Browse the repository at this point in the history
feat: added crash detection, bonus system, ped speeches...
  • Loading branch information
GhzGarage authored May 20, 2024
2 parents d4116d4 + ed0b567 commit e887125
Show file tree
Hide file tree
Showing 16 changed files with 103 additions and 76 deletions.
84 changes: 62 additions & 22 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ local QBCore = exports['qb-core']:GetCoreObject()
local meterIsOpen = false
local meterActive = false
local lastLocation = nil
local mouseActive = false
local PlayerJob = {}
local jobRequired = Config.jobRequired

Expand Down Expand Up @@ -33,7 +32,8 @@ local NpcData = {
NpcDelivered = false,
CountDown = 180,
startingLength = 0,
distanceLeft = 0
distanceLeft = 0,
CrashCount = 0
}

-- events
Expand Down Expand Up @@ -90,7 +90,8 @@ local function ResetNpcTask()
NpcTaken = false,
NpcDelivered = false,
startingLength = 0,
distanceLeft = 0
distanceLeft = 0,
CrashCount = 0
}
end

Expand All @@ -105,8 +106,7 @@ local function resetMeter()
end

local function whitelistedVehicle()
local ped = PlayerPedId()
local veh = GetEntityModel(GetVehiclePedIsIn(ped))
local veh = GetEntityModel(GetVehiclePedIsIn(PlayerPedId()))
local retval = false

for i = 1, #Config.AllowedVehicles, 1 do
Expand All @@ -121,6 +121,7 @@ local function whitelistedVehicle()

return retval
end

local function IsDriver()
return GetPedInVehicleSeat(GetVehiclePedIsIn(PlayerPedId(), false), -1) == PlayerPedId()
end
Expand Down Expand Up @@ -176,7 +177,8 @@ local function GetDeliveryLocation()
SendNUIMessage({
action = 'toggleMeter'
})
TriggerServerEvent('qb-taxi:server:NpcPay', meterData.currentFare)
TriggerServerEvent('qb-taxi:server:NpcPay', meterData.currentFare, NpcData.CrashCount == 0)
PlayPedAmbientSpeechNative(NpcData.Npc, NpcData.CrashCount == 0 and Config.Advanced.Speech.Happy or Config.Advanced.Speech.Grateful, 'SPEECH_PARAMS_ALLOW_REPEAT')
meterActive = false
SendNUIMessage({
action = 'resetMeter'
Expand Down Expand Up @@ -284,6 +286,50 @@ local function calculateFareAmount()
end
end

local function listenForVehicleDamage()
CreateThread(function()
local lastVehicleHealth = nil
while true do
if not Config.Advanced.Bonus.Enabled or not NpcData.Active then return end

if NpcData.NpcTaken then
local vehicle = GetVehiclePedIsIn(PlayerPedId(), false)

if vehicle and vehicle ~= 0 then
local currentHealth = GetEntityHealth(vehicle)
if currentHealth < Config.Advanced.MinCabHealth then
TriggerEvent('qb-taxi:client:CancelTaxiNpc')
return QBCore.Functions.Notify(Lang:t('error.broken_taxi'), 'error')
end

if lastVehicleHealth and currentHealth < lastVehicleHealth then
if Config.Advanced.Speech.Enabled then
if lastVehicleHealth - currentHealth < 10 then -- small crash = angry / big crash = scared
PlayPedAmbientSpeechNative(NpcData.Npc, Config.Advanced.Speech.Angry, 'SPEECH_PARAMS_ALLOW_REPEAT')
else
PlayPedAmbientSpeechNative(NpcData.Npc, Config.Advanced.Speech.Scared, 'SPEECH_PARAMS_ALLOW_REPEAT')
end
end

NpcData.CrashCount += 1
if NpcData.CrashCount >= Config.Advanced.MaxCrashesAllowed then
TriggerEvent('qb-taxi:client:CancelTaxiNpc')
return QBCore.Functions.Notify(Lang:t('error.ride_canceled'), 'error')
end

local count = Config.Advanced.MaxCrashesAllowed - NpcData.CrashCount
QBCore.Functions.Notify(string.format(Lang:t('error.crash_warning'), count, count == 1 and Lang:t('error.time') or Lang:t('error.times')), 'error')
end
lastVehicleHealth = currentHealth
else
lastVehicleHealth = nil
end
end
Wait(200)
end
end)
end

-- qb-menu

function TaxiGarage()
Expand Down Expand Up @@ -426,6 +472,7 @@ RegisterNetEvent('qb-taxi:client:DoTaxiNpc', function()
ClearPedTasksImmediately(NpcData.Npc)
FreezeEntityPosition(NpcData.Npc, false)
TaskEnterVehicle(NpcData.Npc, veh, -1, freeSeat, 1.0, 0)
listenForVehicleDamage()
resetMeter()
QBCore.Functions.Notify(Lang:t('info.go_to_location'))
if NpcData.NpcBlip ~= nil then
Expand Down Expand Up @@ -456,6 +503,7 @@ RegisterNetEvent('qb-taxi:client:CancelTaxiNpc', function()
NpcData.LastNpc = nil
NpcData.CurrentDeliver = nil
NpcData.LastDeliver = nil
NpcData.CrashCount = 0

if DoesEntityExist(NpcData.Npc) then
SetEntityAsMissionEntity(NpcData.Npc, false, true)
Expand All @@ -478,10 +526,6 @@ RegisterNetEvent('qb-taxi:client:CancelTaxiNpc', function()
})
meterActive = false
end

QBCore.Functions.Notify(Lang:t('success.mission_cancelled'), 'success')
else
QBCore.Functions.Notify(Lang:t('error.no_mission_active'), 'error')
end
end)

Expand Down Expand Up @@ -530,12 +574,6 @@ RegisterNUICallback('enableMeter', function(data, cb)
cb('ok')
end)

RegisterNUICallback('hideMouse', function(_, cb)
SetNuiFocus(false, false)
mouseActive = false
cb('ok')
end)

-- Threads
CreateThread(function()
local TaxiBlip = AddBlipForCoord(Config.Location)
Expand Down Expand Up @@ -654,7 +692,7 @@ function setupTarget()
end

local zone
local delieveryZone
local deliveryZone

function createNpcPickUpLocation()
zone = BoxZone:Create(Config.PZLocations.TakeLocations[NpcData.CurrentNpc].coord, Config.PZLocations.TakeLocations[NpcData.CurrentNpc].height, Config.PZLocations.TakeLocations[NpcData.CurrentNpc].width, {
Expand All @@ -678,14 +716,14 @@ function createNpcPickUpLocation()
end

function createNpcDelieveryLocation()
delieveryZone = BoxZone:Create(Config.PZLocations.DropLocations[NpcData.CurrentDeliver].coord, Config.PZLocations.DropLocations[NpcData.CurrentDeliver].height, Config.PZLocations.DropLocations[NpcData.CurrentDeliver].width, {
deliveryZone = BoxZone:Create(Config.PZLocations.DropLocations[NpcData.CurrentDeliver].coord, Config.PZLocations.DropLocations[NpcData.CurrentDeliver].height, Config.PZLocations.DropLocations[NpcData.CurrentDeliver].width, {
heading = Config.PZLocations.DropLocations[NpcData.CurrentDeliver].heading,
debugPoly = false,
minZ = Config.PZLocations.DropLocations[NpcData.CurrentDeliver].minZ,
maxZ = Config.PZLocations.DropLocations[NpcData.CurrentDeliver].maxZ,
})

delieveryZone:onPlayerInOut(function(isPlayerInside)
deliveryZone:onPlayerInOut(function(isPlayerInside)
if isPlayerInside then
if whitelistedVehicle() and not isInsideDropZone and NpcData.NpcTaken then
isInsideDropZone = true
Expand All @@ -705,7 +743,7 @@ function callNpcPoly()
if isInsidePickupZone then
if IsControlJustPressed(0, 38) then
exports['qb-core']:KeyPressed()
local veh = GetVehiclePedIsIn(ped, 0)
local veh = GetVehiclePedIsIn(ped, false)
local maxSeats, freeSeat = GetVehicleMaxNumberOfPassengers(veh)

for i = maxSeats - 1, 0, -1 do
Expand All @@ -729,6 +767,7 @@ function callNpcPoly()
ClearPedTasksImmediately(NpcData.Npc)
FreezeEntityPosition(NpcData.Npc, false)
TaskEnterVehicle(NpcData.Npc, veh, -1, freeSeat, 1.0, 0)
listenForVehicleDamage()
resetMeter()
QBCore.Functions.Notify(Lang:t('info.go_to_location'))
if NpcData.NpcBlip ~= nil then
Expand Down Expand Up @@ -761,7 +800,8 @@ function dropNpcPoly()
SendNUIMessage({
action = 'toggleMeter'
})
TriggerServerEvent('qb-taxi:server:NpcPay', meterData.currentFare)
TriggerServerEvent('qb-taxi:server:NpcPay', meterData.currentFare, NpcData.CrashCount == 0)
PlayPedAmbientSpeechNative(NpcData.Npc, NpcData.CrashCount == 0 and Config.Advanced.Speech.Happy or Config.Advanced.Speech.Grateful, 'SPEECH_PARAMS_ALLOW_REPEAT')
meterActive = false
SendNUIMessage({
action = 'resetMeter'
Expand All @@ -777,7 +817,7 @@ function dropNpcPoly()
end
RemovePed(NpcData.Npc)
ResetNpcTask()
delieveryZone:destroy()
deliveryZone:destroy()
break
end
end
Expand Down
16 changes: 16 additions & 0 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,22 @@ Config = {

Duty = vector3(894.88, -179.22, 74.7),

Advanced = {
Bonus = {
Enabled = true,
Percentage = 10, -- bonus in % for intact vehicle
},
Speech = {
Enabled = true,
Angry = 'GENERIC_INSULT_HIGH',
Scared = 'GENERIC_FRIGHTENED_HIGH',
Grateful = 'GENERIC_THANKS',
Happy = 'GENERIC_HAPPY'
},
MinCabHealth = 750, -- min vehicle health before mission stops
MaxCrashesAllowed = 5, -- amount of crashes before mission stops
},

NPCLocations = {
TakeLocations = {
[1] = vector4(257.61, -380.57, 44.71, 340.5),
Expand Down
4 changes: 0 additions & 4 deletions locales/ar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ local Translations = {
['missing_meter'] = 'هذه السيارة لا تحتوي على عداد سيارات الأجرة',
['no_vehicle'] = 'أنت لست في سيارة',
['not_active_meter'] = 'عداد سيارة الأجرة غير نشط',
['no_mission_active'] = 'You dont have any mission to cancel'
},
success = {
['mission_cancelled'] = 'Mission canceled successfully'
},
info = {
['person_was_dropped_off'] = 'تم إنزال الشخص',
Expand Down
4 changes: 0 additions & 4 deletions locales/da.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ local Translations = {
['missing_meter'] = 'Dette køretøj har intet taxameter',
['no_vehicle'] = 'Du er ikke i et køretøj',
['not_active_meter'] = 'Taxameteret er ikke aktivt',
['no_mission_active'] = 'You dont have any mission to cancel'
},
success = {
['mission_cancelled'] = 'Mission canceled successfully'
},
info = {
['person_was_dropped_off'] = 'Personen blev sat af!',
Expand Down
4 changes: 0 additions & 4 deletions locales/de.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ local Translations = {
['missing_meter'] = 'Dieses Fahrzeug hat keine Taxameter',
['no_vehicle'] = 'Sie sind nicht in einem Fahrzeug',
['not_active_meter'] = 'Das Taxameter ist nicht aktiv',
['no_mission_active'] = 'You dont have any mission to cancel'
},
success = {
['mission_cancelled'] = 'Mission canceled successfully'
},
info = {
['person_was_dropped_off'] = 'Person wurde abgesetzt!',
Expand Down
10 changes: 8 additions & 2 deletions locales/en.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ local Translations = {
['missing_meter'] = 'This Vehicle Has No Taxi Meter',
['no_vehicle'] = "You're not in a vehicle",
['not_active_meter'] = 'The Taxi Meter Is Not Active',
['no_mission_active'] = 'You dont have any mission to cancel'
['ride_canceled'] = 'You have crashed too many times, the ride is canceled!',
['broken_taxi'] = 'Your taxi needs to be repaired before resuming work!',
['crash_warning'] = 'If you crash %d more %s the customer will stop the ride and you will not be paid!',
['time'] = 'time',
['times'] = 'times',
},
success = {
['mission_cancelled'] = 'Mission canceled successfully',
Expand All @@ -23,7 +27,9 @@ local Translations = {
['no_spawn_point'] = 'Unable to find a location to bring the cab',
['taxi_returned'] = 'Cab Parked',
['on_duty'] = '[E] - Go on duty',
['off_duty'] = '[E] - Go off duty'
['off_duty'] = '[E] - Go off duty',
['tip_received'] = 'You have been tipped $%d for your safe driving',
['tip_not_received'] = 'Try not to crash the cab if you want to receive any tips in the future',
},
menu = {
['taxi_menu_header'] = 'Taxi Vehicles',
Expand Down
4 changes: 0 additions & 4 deletions locales/es.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ local Translations = {
['missing_meter'] = 'Este vehículo no tiene taxímetro',
['no_vehicle'] = 'No estás en un vehículo',
['not_active_meter'] = 'El taxímetro no está activo',
['no_mission_active'] = 'You dont have any mission to cancel'
},
success = {
['mission_cancelled'] = 'Mission canceled successfully'
},
info = {
['person_was_dropped_off'] = 'La persona se bajó del taxi',
Expand Down
4 changes: 0 additions & 4 deletions locales/fa.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ local Translations = {
['missing_meter'] = 'Dar In Vasile Nagliye Taxi Meter Mojud Nist',
['no_vehicle'] = 'Shoma Dar Vasile Nagliye Nist',
['not_active_meter'] = 'Taxi Meter Faal Nist',
['no_mission_active'] = 'You dont have any mission to cancel'
},
success = {
['mission_cancelled'] = 'Mission canceled successfully'
},
info = {
['person_was_dropped_off'] = 'Mosafer Piyade Shod!',
Expand Down
4 changes: 0 additions & 4 deletions locales/fi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ local Translations = {
['missing_meter'] = 'Ajoneuvossa ei ole taksimittaria',
['no_vehicle'] = 'Et ole ajoneuvossa!',
['not_active_meter'] = 'Taksimittari ei ole aktiivinen',
['no_mission_active'] = 'You dont have any mission to cancel'
},
success = {
['mission_cancelled'] = 'Mission canceled successfully'
},
info = {
['person_was_dropped_off'] = 'Jätit matkustajan pois!',
Expand Down
4 changes: 0 additions & 4 deletions locales/fr.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ local Translations = {
['missing_meter'] = "Ce véhicule n'a pas de taximètre",
['no_vehicle'] = 'Vous n\'êtes pas dans un véhicule',
['not_active_meter'] = 'Le taximètre n\'est pas activé',
['no_mission_active'] = 'You dont have any mission to cancel'
},
success = {
['mission_cancelled'] = 'Mission canceled successfully'
},
info = {
['person_was_dropped_off'] = 'La personne a été déposée!',
Expand Down
4 changes: 0 additions & 4 deletions locales/nl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ local Translations = {
['missing_meter'] = 'Dit voertuig heeft geen taximeter',
['no_vehicle'] = 'Je zit niet in een voertuig',
['not_active_meter'] = 'De taximeter is niet actief',
['no_mission_active'] = 'You dont have any mission to cancel'
},
success = {
['mission_cancelled'] = 'Mission canceled successfully'
},
info = {
['person_was_dropped_off'] = 'Persoon is afgezet!',
Expand Down
4 changes: 0 additions & 4 deletions locales/pt.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ local Translations = {
['missing_meter'] = 'Este veículo não possui um taxímetro',
['no_vehicle'] = 'Não estás num veículo',
['not_active_meter'] = 'O taxímetro não se encontra activo',
['no_mission_active'] = 'You dont have any mission to cancel'
},
success = {
['mission_cancelled'] = 'Mission canceled successfully'
},
info = {
['person_was_dropped_off'] = 'O passageiro foi entregue!',
Expand Down
4 changes: 0 additions & 4 deletions locales/sv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ local Translations = {
['missing_meter'] = 'Det här fordonet har ingen taxameter',
['no_vehicle'] = 'Du är inte i ett fordon',
['not_active_meter'] = 'Taxametern är inte aktiv',
['no_mission_active'] = 'You dont have any mission to cancel'
},
success = {
['mission_cancelled'] = 'Mission canceled successfully'
},
info = {
['person_was_dropped_off'] = 'Passageraren släpptes av!',
Expand Down
4 changes: 0 additions & 4 deletions locales/th.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ local Translations = {
['missing_meter'] = 'รถคันนี้ไม่มีมิเตอร์แท็กซี่',
['no_vehicle'] = 'คุณไม่ได้อยู่ในยานพาหนะ',
['not_active_meter'] = 'มิเตอร์แท็กซี่ไม่ทำงาน',
['no_mission_active'] = 'You dont have any mission to cancel'
},
success = {
['mission_cancelled'] = 'Mission canceled successfully'
},
info = {
['person_was_dropped_off'] = 'ปล่อยคนลง',
Expand Down
4 changes: 0 additions & 4 deletions locales/tr.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ local Translations = {
['missing_meter'] = 'Bu Aracın Taksimetresi Yok',
['no_vehicle'] = 'Bir araçta değilsin',
['not_active_meter'] = 'Taksimetre Aktif Değil',
['no_mission_active'] = 'You dont have any mission to cancel'
},
success = {
['mission_cancelled'] = 'Mission canceled successfully'
},
info = {
['person_was_dropped_off'] = 'Kişi Bırakıldı!',
Expand Down
Loading

0 comments on commit e887125

Please sign in to comment.