Skip to content

Commit

Permalink
fix(server/main): testdrive qol (#121)
Browse files Browse the repository at this point in the history
* chore(config/shared): improve pdm return location

* fix(server/main): error when ending test drive

* feat(server/main): attempt to clean up testdrives when stopping
  • Loading branch information
D4isDAVID authored Dec 28, 2024
1 parent fc016bc commit 5a258ba
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion config/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ return {
spawn = vec4(-7.84, -1081.35, 26.67, 121.83),
endBehavior = 'return'
},
returnLocation = vec3(-44.74, -1082.58, 26.68),
returnLocation = vec3(-32.77, -1095.75, 26.42),
vehicleSpawn = vec4(-31.69, -1090.78, 26.42, 328.79),
showroomVehicles = {
[1] = {coords = vec4(-45.65, -1093.66, 25.44, 69.5), vehicle = 'asbo'},
Expand Down
16 changes: 13 additions & 3 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,16 @@ AddStateBagChangeHandler('isInTestDrive', nil, function(bagName, _, value)

local plySrc = GetPlayerFromStateBagName(bagName)
if not plySrc then return end
local netId = testDrives[plySrc].netId
local endBehavior = testDrives[plySrc].endBehavior
local testDrive = testDrives[plySrc]
if not testDrive then return end
local netId = testDrive.netId
local endBehavior = testDrive.endBehavior
if not netId or endBehavior == 'none' then return end

local vehicle = NetworkGetEntityFromNetworkId(netId)

if endBehavior == 'return' then
local coords = testDrives[plySrc].returnLocation
local coords = testDrive.returnLocation
local plyPed = GetPlayerPed(plySrc)
if #(GetEntityCoords(plyPed) - coords) > 10 then -- don't teleport if they are standing near the spot
SetEntityCoords(plyPed, coords.x, coords.y, coords.z, false, false, false, false)
Expand All @@ -98,6 +100,14 @@ AddStateBagChangeHandler('isInTestDrive', nil, function(bagName, _, value)
testDrives[plySrc] = nil
end)

AddEventHandler('onResourceStop', function (resourceName)
if cache.resource ~= resourceName then return end

for player, _ in pairs(testDrives) do
Player(player).state:set('isInTestDrive', nil, true)
end
end)

---@param vehicleData {buyVehicle: string}
RegisterNetEvent('qbx_vehicleshop:server:buyShowroomVehicle', function(vehicleData)
local src = source
Expand Down

0 comments on commit 5a258ba

Please sign in to comment.