Skip to content

Commit

Permalink
fix(server): spawning guards in vehicle reliably
Browse files Browse the repository at this point in the history
* fix(server): spawning guards in vehicle reliably

* fix not setting truck entity
  • Loading branch information
Manason authored Mar 15, 2024
1 parent f2abb5b commit 23285e5
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local config = require 'config.server'
local sharedConfig = require 'config.shared'
local isMissionAvailable = true
local truck
lib.locale()

lib.callback.register('qbx_truckrobbery:server:startMission', function(source)
local player = exports.qbx_core:GetPlayer(source)
Expand Down Expand Up @@ -31,19 +32,22 @@ lib.callback.register('qbx_truckrobbery:server:startMission', function(source)
end)

local function spawnGuardInSeat(seat, weapon)
local coords = GetEntityCoords(truck)
local guard = CreatePed(26, config.guardModel, coords.x, coords.y, coords.z, 268.9422, true, false)
SetPedIntoVehicle(guard, truck, seat)
local guard = CreatePedInsideVehicle(truck, 26, config.guardModel, seat, true, false)
lib.waitFor(function()
return DoesEntityExist(guard) or nil
end, "guard does not exist")
GiveWeaponToPed(guard, weapon, 250, false, true)
Entity(guard).state:set('qbx_truckrobbery:initGuard', true, true)
Wait(0)
end

lib.callback.register('qbx_truckrobbery:server:spawnVehicle', function(source, coords)
local netId = qbx.spawnVehicle({spawnSource = coords, model = config.truckModel})
truck = NetworkGetEntityFromNetworkId(netId)
local netId, veh = qbx.spawnVehicle({spawnSource = coords, model = config.truckModel})
truck = veh
SetVehicleDoorsLocked(truck, 2)
local state = Entity(truck).state
state:set('truckstate', TruckState.PLANTABLE, true)
Wait(0)
spawnGuardInSeat(-1, config.driverWeapon)
spawnGuardInSeat(0, config.passengerWeapon)
spawnGuardInSeat(1, config.backPassengerWeapon)
Expand Down

0 comments on commit 23285e5

Please sign in to comment.