Skip to content

Commit

Permalink
refactor: improvements (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
mafewtm authored Jan 17, 2024
1 parent 2fc14f9 commit 1262ebf
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 74 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"QBX",
"DrawText3D",
"lib",
"cache"
"cache",
"qbx"
]
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# qb-truckrobbery
Armored Truck Robbery For QB-Core
# qbx_truckrobbery
Armored Truck Robbery For QBox
96 changes: 44 additions & 52 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@ local config = require 'config.client'
local guardsDead = false
local truckBlip
local truck
local netId
local area
local missionStarted = false
local dealer, pilot, navigator

AddEventHandler('onResourceStart', function(resource)
if resource ~= GetCurrentResourceName() then return end
lib.requestModel(config.dealerModel)
dealer = CreatePed(26, config.dealerModel, config.dealerCoords.x, config.dealerCoords.y, config.dealerCoords.z, 268.9422, false, false)
SetEntityHeading(dealer, 1.8)
SetBlockingOfNonTemporaryEvents(dealer, true)
if resource ~= cache.resource then return end
lib.requestModel(config.dealerModel, 5000)
dealer = CreatePed(26, config.dealerModel, config.dealerCoords.x, config.dealerCoords.y, config.dealerCoords.z, config.dealerCoords.w, false, false)
TaskStartScenarioInPlace(dealer, 'WORLD_HUMAN_AA_SMOKE', 0, false)
SetEntityInvincible(dealer, true)
SetBlockingOfNonTemporaryEvents(dealer, true)
Wait(1000)
FreezeEntityPosition(dealer, true)

exports.ox_target:addLocalEntity(dealer, {
name = 'dealer',
Expand All @@ -28,7 +32,7 @@ AddEventHandler('onResourceStart', function(resource)
end)

AddEventHandler('onResourceStop', function(resource)
if resource ~= GetCurrentResourceName() then return end
if resource ~= cache.resource then return end
exports.ox_target:removeLocalEntity(dealer)
DeletePed(dealer)
end)
Expand All @@ -38,38 +42,11 @@ local function callCops()
PlaySoundFrontend(-1, 'Mission_Pass_Notify', 'DLC_HEISTS_GENERAL_FRONTEND_SOUNDS', false)
end

lib.callback.register('qbx_truckrobbery:client:notifyCop', function(msg, coords)
PlaySound(-1, 'Lose_1st', 'GTAO_FM_Events_Soundset', false, 0, true)
exports.qbx_core:Notify(msg, 'police', 10000)

local transG = 250
local blip = AddBlipForCoord(coords.x, coords.y, coords.z)
SetBlipSprite(blip, 487)
SetBlipColour(blip, 4)
SetBlipDisplay(blip, 4)
SetBlipAlpha(blip, transG)
SetBlipScale(blip, 1.2)
SetBlipFlashes(blip, true)
BeginTextCommandSetBlipName('STRING')
AddTextComponentString(Lang:t('info.cop_blip'))
EndTextCommandSetBlipName(blip)
while transG ~= 0 do
Wait(180 * 4)
transG = transG - 1
SetBlipAlpha(blip, transG)
if transG == 0 then
SetBlipSprite(blip, 2)
RemoveBlip(blip)
return
end
end
end)

local function resetMission()
guardsDead = false
missionStarted = false
RemoveBlip(truckBlip)
SetBlipRoute(truckBlip, false)
RemoveBlip(area)
end

lib.callback.register('qbx_truckrobbery:resetMission', resetMission)
Expand All @@ -79,7 +56,7 @@ local function grabMoney()

if lib.progressBar({
duration = 5000,
label = Lang:t('info.grabing_money'),
label = Lang:t('info.grabbing_money'),
useWhileDead = false,
canCancel = true,
disable = {
Expand Down Expand Up @@ -108,7 +85,7 @@ local function grabMoney()
},
}
}) then
exports.ox_target:removeLocalEntity(truck, 'transportTake')
exports.ox_target:removeEntity(netId, 'transportTake')
SetPedComponentVariation(cache.ped, 5, 45, 0, 2)
lib.callback('qbx_truckrobbery:server:giveReward')
resetMission()
Expand All @@ -128,8 +105,13 @@ local function plantBomb()
exports.qbx_core:Notify(Lang:t('info.get_out_water'), 'error')
return
end
exports.ox_target:removeLocalEntity(truck, 'transportPlant')
SetCurrentPedWeapon(cache.ped, `WEAPON_UNARMED`,true)
local hasBomb = exports.ox_inventory:Search('count', 'WEAPON_STICKYBOMB') > 0
if not hasBomb then
exports.qbx_core:Notify(Lang:t('error.missing_bomb'), 'error')
return
end
exports.ox_target:removeEntity(netId, 'transportPlant')
SetCurrentPedWeapon(cache.ped, `WEAPON_UNARMED`, true)
Wait(500)

if lib.progressBar({
Expand Down Expand Up @@ -162,11 +144,13 @@ local function plantBomb()
},
}
}) then
exports.ox_target:removeLocalEntity(truck, 'transportPlant')
local removeBomb = lib.callback.await('qbx_truckrobbery:server:plantedBomb', false)
if not removeBomb then return end
exports.ox_target:removeEntity(netId, 'transportPlant')
local coords = GetEntityCoords(cache.ped)
local prop = CreateObject(`prop_c4_final_green`, coords.x, coords.y, coords.z + 0.2, true, true, true)
AttachEntityToEntity(prop, truck, GetEntityBoneIndexByName(truck, 'door_pside_r'), -0.7, 0.0, 0.0, 0.0, 0.0, 0.0, true, true, false, true, 1, true)
exports.qbx_core:Notify(Lang:t('info.bomb_timer', {TimeToBlow = config.timetoDetonation / 1000}), 'error')
exports.qbx_core:Notify(Lang:t('info.bomb_timer', {TimeToBlow = config.timetoDetonation / 1000}), 'inform')
Wait(config.timetoDetonation)
local transCoords = GetEntityCoords(truck)
SetVehicleDoorBroken(truck, 2, false)
Expand All @@ -175,8 +159,8 @@ local function plantBomb()
ApplyForceToEntity(truck, 0, 20.0, 500.0, 0.0, 0.0, 0.0, 0.0, 1, false, true, true, false, true)

exports.qbx_core:Notify(Lang:t('info.collect'), 'success')
--- TODO: seems like these targets should be added for all players instead of just the bomb planter
exports.ox_target:addLocalEntity(truck, {

exports.ox_target:addEntity(netId, {
name = 'transportTake',
label = Lang:t('info.take_money_target'),
icon = 'fas fa-sack-dollar',
Expand All @@ -190,7 +174,7 @@ local function plantBomb()
end

local function createBombPlantingTarget()
exports.ox_target:addLocalEntity(truck, {
exports.ox_target:addEntity(netId, {
name = 'transportPlant',
label = Lang:t('info.plant_bomb'),
icon = 'fas fa-bomb',
Expand All @@ -206,26 +190,34 @@ RegisterNetEvent('qbx_truckrobbery:client:missionStarted', function()
Wait(2000)
config.emailNotification()
Wait(3000)
ClearPedTasks(dealer)
TaskWanderStandard(dealer, 10.0, 10)
local vehicleSpawnCoords = config.truckSpawns[math.random(1, #config.truckSpawns)]

lib.requestModel(config.truckModel)

area = AddBlipForRadius(vehicleSpawnCoords.x, vehicleSpawnCoords.y, vehicleSpawnCoords.z, 450.0)
SetBlipHighDetail(area, true)
SetBlipAlpha(area, 90)
SetBlipColour(area, config.routeColor)

ClearAreaOfVehicles(vehicleSpawnCoords.x, vehicleSpawnCoords.y, vehicleSpawnCoords.z, 15.0, false, false, false, false, false)
truck = CreateVehicle(config.truckModel, vehicleSpawnCoords.x, vehicleSpawnCoords.y, vehicleSpawnCoords.z, vehicleSpawnCoords.w, true, true)
SetEntityAsMissionEntity(truck)
netId = lib.callback.await('qbx_truckrobbery:server:spawnVehicle', false, config.truckModel, vehicleSpawnCoords)
lib.waitFor(function()
if NetworkDoesEntityExistWithNetworkId(netId) then
truck = NetToVeh(netId)
return truck
end
end, 'It looks like there\'s been a problem...')

exports.qbx_core:Notify('The truck has been spotted! Get to it before anyone else does!', 'inform')

truckBlip = AddBlipForEntity(truck)
SetBlipSprite(truckBlip, 67)
SetBlipColour(truckBlip, 1)
SetBlipFlashes(truckBlip, true)
SetBlipRoute(truckBlip, true)
SetBlipRouteColour(truckBlip, config.routeColor)
BeginTextCommandSetBlipName('STRING')
AddTextComponentString(Lang:t('mission.stockade'))
EndTextCommandSetBlipName(truckBlip)

lib.requestModel(config.guardModel)
lib.requestModel(config.guardModel, 5000)

pilot = CreatePed(26, config.guardModel, vehicleSpawnCoords.x, vehicleSpawnCoords.y, vehicleSpawnCoords.z, 268.9422, true, false)
navigator = CreatePed(26, config.guardModel, vehicleSpawnCoords.x, vehicleSpawnCoords.y, vehicleSpawnCoords.z, 268.9422, true, false)
Expand All @@ -249,7 +241,7 @@ RegisterNetEvent('qbx_truckrobbery:client:missionStarted', function()
SetPedCombatMovement(pilot, 2)
SetPedCombatRange(pilot, 2)
SetPedKeepTask(pilot, true)
GiveWeaponToPed(pilot, config.driverWeapon,250,false,true)
GiveWeaponToPed(pilot, config.driverWeapon, 250, false, true)
SetPedAsCop(pilot, true)

SetPedFleeAttributes(navigator, 0, false)
Expand Down
4 changes: 2 additions & 2 deletions config/client.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
return {
missionMarker = vec3(960.71197509766, -215.51979064941, 76.2552947998), -- Marker to start mission
dealerCoords = vec3(960.78, -216.25, 76.25), -- place where the NPC stands
dealerCoords = vec4(960.78, -216.25, 76.25, 1.8), -- place where the NPC stands

truckSpawns = { -- Possible truck spawn locations
vec4(-1215.97, -355.4, 36.9, 208.6),
Expand All @@ -23,7 +23,7 @@ return {

-- Used for mission notification
emailNotification = function()
TriggerServerEvent('npwd_qbx_phone:server:sendNewMail', {
TriggerServerEvent('qb-phone:server:sendNewMail', {
sender = Lang:t('mission.sender'),
subject = Lang:t('mission.subject'),
message = Lang:t('mission.message'),
Expand Down
2 changes: 1 addition & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ version '1.0.0'

shared_scripts {
'@ox_lib/init.lua',
'@qbx_core/modules/utils.lua',
'@qbx_core/modules/lib.lua',
'@qbx_core/shared/locale.lua',
'locales/en.lua',
'locales/*.lua',
Expand Down
11 changes: 6 additions & 5 deletions locales/en.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ local Translations = {
error = {
get_out_water = 'Get out of the water',
guards_dead = 'The guards must be dead to place the bomb',
truck_ismoving = 'You cant rob a vehicle that is moving.',
truck_ismoving = 'You can\'t rob a vehicle that is moving.',
missing_bomb = 'It appears you don\'t have a bomb...',
active_police = 'Need at least %{police} police to activate the mission.',
already_active = 'Someone is already carrying out this mission',
},
success = {
packing_cash = 'You are packing cash into a bag',
took_bags = 'You took %{bags} bags of cash from the Truck',
packing_cash = 'You are packing the cash into a bag',
took_bags = 'You took $%{bags} from the Truck',
},
mission = {
activation_cost = "You need $ %{cost} in the bank to accept the mission",
Expand All @@ -17,7 +18,7 @@ local Translations = {
stockade = 'Stockade',
sender = "The Boss",
subject ="New Target",
message = "So you are intrested in making some money? good... go get yourself a Gun and make it happen... sending you the location now.",
message = "So you are intrested in making some money? Good. Go get yourself a Gun and make it happen. Sending you the location now.",
},
info = {
before_bomb = 'Get rid of the guards before you place the bomb.',
Expand All @@ -31,7 +32,7 @@ local Translations = {
cop_blip = "10-90: Armored Truck Robbery",
alerttitle = "Armored Truck Robbery Attempt",
alert_desc = "An Armored Truck is being robbed!",
grabing_money = 'You\'re taking the money..'
grabbing_money = 'You\'re taking the money..'
},
}

Expand Down
27 changes: 16 additions & 11 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,15 @@ lib.callback.register('qbx_truckrobbery:server:startMission', function(source)
lib.callback('qbx_truckrobbery:client:resetMission', -1)
end)

lib.callback.register('qbx_truckrobbery:server:spawnVehicle', function(_, model, coords)
local netId = qbx.spawnVehicle({spawnSource = coords, model = model})
return netId
end)

lib.callback.register('qbx_truckrobbery:server:callCops', function(_, coords)
local msg = Lang:t("info.alert_desc")
local alertData = {
title = Lang:t("info.alerttitle"),
title = Lang:t('info.alerttitle'),
coords = {
x = coords.x,
y = coords.y,
Expand All @@ -40,20 +45,20 @@ lib.callback.register('qbx_truckrobbery:server:callCops', function(_, coords)
local numCops, copSrcs = exports.qbx_core:GetDutyCountType('leo')
for i = 1, numCops do
local copSrc = copSrcs[i]
lib.callback('qbx_truckrobbery:client:notifyCop', copSrc, nil, msg, coords)
TriggerClientEvent("qb-phone:client:addPoliceAlert", copSrc, alertData)
TriggerClientEvent('police:client:policeAlert', copSrc, coords, msg)
TriggerClientEvent('qb-phone:client:addPoliceAlert', copSrc, alertData)
end
end)

lib.callback.register('qbx_truckrobbery:server:plantedBomb', function(source)
return exports.ox_inventory:RemoveItem(source, 'weapon_stickybomb', 1)
end)

lib.callback.register('qbx_truckrobbery:server:giveReward', function(source)
local player = exports.qbx_core:GetPlayer(source)
local bags = math.random(1,3)
local info = {
worth = math.random(config.minReward, config.maxReward)
}
player.Functions.AddItem('markedbills', bags, false, info)
exports.qbx_core:Notify(source, Lang:t('success.took_bags', {bags = bags}), 'success')
local reward = math.random(config.minReward, config.maxReward)
exports.ox_inventory:AddItem(source, 'black_money', reward)
exports.qbx_core:Notify(source, Lang:t('success.took_bags', {bags = reward}), 'success')
if math.random() <= 0.05 then
player.Functions.AddItem('security_card_01', 1)
exports.ox_inventory:AddItem(source, 'security_card_01', 1)
end
end)

0 comments on commit 1262ebf

Please sign in to comment.