Skip to content

Commit

Permalink
chore: QBCore -> QBX (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mekz1222 authored Sep 27, 2023
1 parent 6f302d0 commit 40676f4
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 81 deletions.
12 changes: 6 additions & 6 deletions client/hospital.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ local function putPlayerInBed(hospitalName, bedIndex, isRevive, skipOpenCheck)
if IsInHospitalBed then return end
if not skipOpenCheck then
if lib.callback.await('qbx-ambulancejob:server:isBedTaken', false, hospitalName, bedIndex) then
QBCore.Functions.Notify(Lang:t('error.beds_taken'), 'error')
QBX.Functions.Notify(Lang:t('error.beds_taken'), 'error')
return
end
end
Expand All @@ -65,7 +65,7 @@ local function putPlayerInBed(hospitalName, bedIndex, isRevive, skipOpenCheck)
CreateThread(function()
Wait(5)
if isRevive then
QBCore.Functions.Notify(Lang:t('success.being_helped'), 'success')
QBX.Functions.Notify(Lang:t('success.being_helped'), 'success')
Wait(Config.AIHealTimer * 1000)
TriggerEvent("hospital:client:Revive")
else
Expand Down Expand Up @@ -103,14 +103,14 @@ local function checkIn(hospitalName)
--- ask server for first non taken bed
local bedIndex = lib.callback.await('qbx-ambulancejob:server:getOpenBed', false, hospitalName)
if not bedIndex then
QBCore.Functions.Notify(Lang:t('error.beds_taken'), 'error')
QBX.Functions.Notify(Lang:t('error.beds_taken'), 'error')
return
end

putPlayerInBed(hospitalName, bedIndex, true, true)
else
exports.scully_emotemenu:cancelEmote()
QBCore.Functions.Notify(Lang:t('error.canceled'), 'error')
QBX.Functions.Notify(Lang:t('error.canceled'), 'error')
end
end

Expand Down Expand Up @@ -253,8 +253,8 @@ local function leaveBed()
bedOccupyingData = nil
IsInHospitalBed = false

if PlayerData.metadata.injail <= 0 then return end
TriggerEvent("prison:client:Enter", PlayerData.metadata.injail)
if QBX.PlayerData.metadata.injail <= 0 then return end
TriggerEvent("prison:client:Enter", QBX.PlayerData.metadata.injail)
end

---shows player option to press key to leave bed when available.
Expand Down
50 changes: 25 additions & 25 deletions client/job.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ end
---@param vehiclePlatePrefix string
---@param coords vector4
local function showGarageMenu(vehicles, vehiclePlatePrefix, coords)
local authorizedVehicles = vehicles[PlayerData.job.grade.level]
local authorizedVehicles = vehicles[QBX.PlayerData.job.grade.level]
local optionsMenu = {}
for veh, label in pairs(authorizedVehicles) do
optionsMenu[#optionsMenu + 1] = {
Expand Down Expand Up @@ -77,23 +77,23 @@ end
RegisterNetEvent('hospital:client:CheckStatus', function()
local player, distance = GetClosestPlayer()
if player == -1 or distance > 5.0 then
QBCore.Functions.Notify(Lang:t('error.no_player'), 'error')
QBX.Functions.Notify(Lang:t('error.no_player'), 'error')
return
end
local playerId = GetPlayerServerId(player)

---@param damage PlayerDamage
local damage = lib.callback.await('hospital:GetPlayerStatus', false, playerId)
if not damage or (damage.bleedLevel == 0 and #damage.damagedBodyParts == 0 and #damage.weaponWounds == 0) then
QBCore.Functions.Notify(Lang:t('success.healthy_player'), 'success')
QBX.Functions.Notify(Lang:t('success.healthy_player'), 'success')
return
end

for _, hash in pairs(damage.weaponWounds) do
TriggerEvent('chat:addMessage', {
color = { 255, 0, 0 },
multiline = false,
args = { Lang:t('info.status'), QBCore.Shared.Weapons[hash].damagereason }
args = { Lang:t('info.status'), QBX.Shared.Weapons[hash].damagereason }
})
end

Expand All @@ -112,14 +112,14 @@ end)
---Use first aid on nearest player to revive them.
---Intended to be invoked by client or server.
RegisterNetEvent('hospital:client:RevivePlayer', function()
if not QBCore.Functions.HasItem('firstaid') then
QBCore.Functions.Notify(Lang:t('error.no_firstaid'), 'error')
if not QBX.Functions.HasItem('firstaid') then
QBX.Functions.Notify(Lang:t('error.no_firstaid'), 'error')
return
end

local player, distance = GetClosestPlayer()
if player == -1 or distance >= 5.0 then
QBCore.Functions.Notify(Lang:t('error.no_player'), 'error')
QBX.Functions.Notify(Lang:t('error.no_player'), 'error')
return
end

Expand All @@ -142,25 +142,25 @@ RegisterNetEvent('hospital:client:RevivePlayer', function()
})
then
StopAnimTask(cache.ped, HealAnimDict, "exit", 1.0)
QBCore.Functions.Notify(Lang:t('success.revived'), 'success')
QBX.Functions.Notify(Lang:t('success.revived'), 'success')
TriggerServerEvent("hospital:server:RevivePlayer", GetPlayerServerId(player))
else
StopAnimTask(cache.ped, HealAnimDict, "exit", 1.0)
QBCore.Functions.Notify(Lang:t('error.canceled'), 'error')
QBX.Functions.Notify(Lang:t('error.canceled'), 'error')
end
end)

---Use bandage on nearest player to treat their wounds.
---Intended to be invoked by client or server.
RegisterNetEvent('hospital:client:TreatWounds', function()
if not QBCore.Functions.HasItem('bandage') then
QBCore.Functions.Notify(Lang:t('error.no_bandage'), 'error')
if not QBX.Functions.HasItem('bandage') then
QBX.Functions.Notify(Lang:t('error.no_bandage'), 'error')
return
end

local player, distance = GetClosestPlayer()
if player == -1 or distance >= 5.0 then
QBCore.Functions.Notify(Lang:t('error.no_player'), 'error')
QBX.Functions.Notify(Lang:t('error.no_player'), 'error')
return
end

Expand All @@ -183,24 +183,24 @@ RegisterNetEvent('hospital:client:TreatWounds', function()
})
then
StopAnimTask(cache.ped, HealAnimDict, "exit", 1.0)
QBCore.Functions.Notify(Lang:t('success.helped_player'), 'success')
QBX.Functions.Notify(Lang:t('success.helped_player'), 'success')
TriggerServerEvent("hospital:server:TreatWounds", GetPlayerServerId(player))
else
StopAnimTask(cache.ped, HealAnimDict, "exit", 1.0)
QBCore.Functions.Notify(Lang:t('error.canceled'), 'error')
QBX.Functions.Notify(Lang:t('error.canceled'), 'error')
end
end)

---Opens the hospital stash.
local function openStash()
if not PlayerData.job.onduty then return end
TriggerServerEvent("inventory:server:OpenInventory", "stash", "ambulancestash_" .. QBCore.Functions.GetPlayerData().citizenid)
TriggerEvent("inventory:client:SetCurrentStash", "ambulancestash_" .. QBCore.Functions.GetPlayerData().citizenid)
if not QBX.PlayerData.job.onduty then return end
TriggerServerEvent("inventory:server:OpenInventory", "stash", "ambulancestash_" .. QBX.PlayerData.citizenid)
TriggerEvent("inventory:client:SetCurrentStash", "ambulancestash_" .. QBX.PlayerData.citizenid)
end

---Opens the hospital armory.
local function openArmory()
if PlayerData.job.onduty then
if QBX.PlayerData.job.onduty then
TriggerServerEvent("inventory:server:OpenInventory", "shop", "hospital", Config.Items)
end
end
Expand All @@ -217,7 +217,7 @@ local function checkGarageAction(vehicles, vehiclePlatePrefix, coords)
exports['qbx-core']:KeyPressed(38)
checkVehicle = false
if cache.vehicle then
QBCore.Functions.DeleteVehicle(cache.vehicle)
QBX.Functions.DeleteVehicle(cache.vehicle)
else
showGarageMenu(vehicles, vehiclePlatePrefix, coords)
end
Expand Down Expand Up @@ -267,7 +267,7 @@ end
local function createGarage(vehicles, vehiclePlatePrefix, coords)

local function inVehicleZone()
if PlayerData.job.name == "ambulance" and PlayerData.job.onduty then
if QBX.PlayerData.job.name == "ambulance" and QBX.PlayerData.job.onduty then
lib.showTextUI(Lang:t('text.veh_button'))
checkGarageAction(vehicles, vehiclePlatePrefix, coords)
else
Expand Down Expand Up @@ -401,7 +401,7 @@ else
CreateThread(function()
for i = 1, #Config.Locations.duty do
local function enteredSignInZone()
if not PlayerData.job.onduty then
if not QBX.PlayerData.job.onduty then
lib.showTextUI(Lang:t('text.onduty_button'))
else
lib.showTextUI(Lang:t('text.offduty_button'))
Expand Down Expand Up @@ -429,7 +429,7 @@ else

for i = 1, #Config.Locations.stash do
local function enteredStashZone()
if PlayerData.job.onduty then
if QBX.PlayerData.job.onduty then
lib.showTextUI(Lang:t('text.pstash_button'))
end
end
Expand All @@ -455,7 +455,7 @@ else

for i = 1, #Config.Locations.armory do
local function enteredArmoryZone()
if PlayerData.job.onduty then
if QBX.PlayerData.job.onduty then
lib.showTextUI(Lang:t('text.armory_button'))
end
end
Expand All @@ -480,7 +480,7 @@ else
end

local function enteredRoofZone()
if PlayerData.job.onduty then
if QBX.PlayerData.job.onduty then
lib.showTextUI(Lang:t('text.elevator_main'))
else
lib.showTextUI(Lang:t('error.not_ems'))
Expand All @@ -506,7 +506,7 @@ else
})

local function enteredMainZone()
if PlayerData.job.onduty then
if QBX.PlayerData.job.onduty then
lib.showTextUI(Lang:t('text.elevator_roof'))
else
lib.showTextUI(Lang:t('error.not_ems'))
Expand Down
6 changes: 3 additions & 3 deletions client/laststand.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ end)
---use first aid pack on nearest player.
lib.callback.register('hospital:client:UseFirstAid', function()
if isEscorting then
QBCore.Functions.Notify(Lang:t('error.impossible'), 'error')
QBX.Functions.Notify(Lang:t('error.impossible'), 'error')
return
end

Expand Down Expand Up @@ -47,10 +47,10 @@ RegisterNetEvent('hospital:client:HelpPerson', function(targetId)
})
then
ClearPedTasks(ped)
QBCore.Functions.Notify(Lang:t('success.revived'), 'success')
QBX.Functions.Notify(Lang:t('success.revived'), 'success')
TriggerServerEvent("hospital:server:RevivePlayer", targetId)
else
ClearPedTasks(ped)
QBCore.Functions.Notify(Lang:t('error.canceled'), 'error')
QBX.Functions.Notify(Lang:t('error.canceled'), 'error')
end
end)
16 changes: 3 additions & 13 deletions client/main.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
QBCore = exports['qbx-core']:GetCoreObject()

InBedDict = "anim@gangops@morgue@table@"
InBedAnim = "body_search"
IsInHospitalBed = false
Expand All @@ -8,14 +6,6 @@ HealAnim = "cpr_pumpchest"
EmsNotified = false
CanLeaveBed = true
OnPainKillers = false
PlayerData = {
job = nil
}

RegisterNetEvent('QBCore:Player:SetPlayerData', function(data)
if GetInvokingResource() then return end
PlayerData = data
end)

-- Events

Expand All @@ -27,7 +17,7 @@ RegisterNetEvent('hospital:client:ambulanceAlert', function(coords, text)
local street1, street2 = GetStreetNameAtCoord(coords.x, coords.y, coords.z)
local street1name = GetStreetNameFromHashKey(street1)
local street2name = GetStreetNameFromHashKey(street2)
QBCore.Functions.Notify({ title = Lang:t('text.alert'), description = text .. ' | ' .. street1name .. ' ' .. street2name, type = 'inform' })
QBX.Functions.Notify({ title = Lang:t('text.alert'), description = text .. ' | ' .. street1name .. ' ' .. street2name, type = 'inform' })
PlaySound(-1, "Lose_1st", "GTAO_FM_Events_Soundset", 0, 0, 1)
local transG = 250
local blip = AddBlipForCoord(coords.x, coords.y, coords.z)
Expand Down Expand Up @@ -80,7 +70,7 @@ end)
RegisterNetEvent('hospital:client:SendBillEmail', function(amount)
if GetInvokingResource() then return end
SetTimeout(math.random(2500, 4000), function()
local charInfo = PlayerData.charinfo
local charInfo = QBX.PlayerData.charinfo
local gender = charInfo.gender == 1 and Lang:t('info.mrs') or Lang:t('info.mr')
TriggerServerEvent('qb-phone:server:sendNewMail', {
sender = Lang:t('mail.sender'),
Expand Down Expand Up @@ -109,7 +99,7 @@ end)

function GetClosestPlayer()
local coords = GetEntityCoords(cache.ped)
return QBCore.Functions.GetClosestPlayer(coords)
return QBX.Functions.GetClosestPlayer(coords)
end

function OnKeyPress(cb)
Expand Down
12 changes: 6 additions & 6 deletions client/wounding.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ lib.callback.register('hospital:client:UseIfaks', function()
})
then
StopAnimTask(ped, "mp_suicide", "pill", 1.0)
TriggerEvent("inventory:client:ItemBox", QBCore.Shared.Items["ifaks"], "remove")
TriggerEvent("inventory:client:ItemBox", QBX.Shared.Items["ifaks"], "remove")
TriggerServerEvent('hud:server:RelieveStress', math.random(12, 24))
SetEntityHealth(ped, GetEntityHealth(ped) + 10)
OnPainKillers = true
Expand All @@ -36,7 +36,7 @@ lib.callback.register('hospital:client:UseIfaks', function()
return true
else
StopAnimTask(ped, "mp_suicide", "pill", 1.0)
QBCore.Functions.Notify(Lang:t('error.canceled'), 'error')
QBX.Functions.Notify(Lang:t('error.canceled'), 'error')
return false
end
end)
Expand All @@ -62,7 +62,7 @@ lib.callback.register('hospital:client:UseBandage', function()
})
then
StopAnimTask(ped, "anim@amb@business@weed@weed_inspecting_high_dry@", "weed_inspecting_high_base_inspector", 1.0)
TriggerEvent("inventory:client:ItemBox", QBCore.Shared.Items["bandage"], "remove")
TriggerEvent("inventory:client:ItemBox", QBX.Shared.Items["bandage"], "remove")
SetEntityHealth(ped, GetEntityHealth(ped) + 10)
if math.random(1, 100) < 50 then
exports['qbx-medical']:removeBleed(1)
Expand All @@ -73,7 +73,7 @@ lib.callback.register('hospital:client:UseBandage', function()
return true
else
StopAnimTask(ped, "anim@amb@business@weed@weed_inspecting_high_dry@", "weed_inspecting_high_base_inspector", 1.0)
QBCore.Functions.Notify(Lang:t('error.canceled'), 'error')
QBX.Functions.Notify(Lang:t('error.canceled'), 'error')
return false
end
end)
Expand All @@ -99,15 +99,15 @@ lib.callback.register('hospital:client:UsePainkillers', function()
})
then
StopAnimTask(ped, "mp_suicide", "pill", 1.0)
TriggerEvent("inventory:client:ItemBox", QBCore.Shared.Items["painkillers"], "remove")
TriggerEvent("inventory:client:ItemBox", QBX.Shared.Items["painkillers"], "remove")
OnPainKillers = true
if painkillerAmount < 3 then
painkillerAmount += 1
end
return true
else
StopAnimTask(ped, "mp_suicide", "pill", 1.0)
QBCore.Functions.Notify(Lang:t('error.canceled'), 'error')
QBX.Functions.Notify(Lang:t('error.canceled'), 'error')
return false
end
end)
Expand Down
14 changes: 8 additions & 6 deletions fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ description 'https://github.com/QBCore-Remastered'
version '1.0.0'

modules {
'qbx-core:utils'
'qbx_core:core',
'qbx_core:playerdata',
'qbx_core:utils'
}

shared_scripts {
'@qbx-core/shared/locale.lua',
'@ox_lib/init.lua',
'@qbx_core/import.lua',
'@qbx_core/shared/locale.lua',
'locales/en.lua',
'locales/*.lua',
'config.lua',
'@ox_lib/init.lua',
'@qbx-core/import.lua',
'config.lua'
}

client_scripts {
Expand All @@ -35,7 +37,7 @@ dependencies {
'ox_lib',
'ox_target',
'ox_inventory',
'qbx-core',
'qbx_core',
'qbx-policejob',
'qbx-management',
'qbx-medical',
Expand Down
Loading

0 comments on commit 40676f4

Please sign in to comment.