Skip to content

Commit

Permalink
chore: calling core exports (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
Manason authored Sep 28, 2023
1 parent 40676f4 commit ec42987
Show file tree
Hide file tree
Showing 11 changed files with 94 additions and 102 deletions.
2 changes: 1 addition & 1 deletion .github/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ Before creating enhancement suggestions, please check [this list](#before-submit

* **Make sure it doesn't already exist.** Sounds silly, but there's a lot of features built in to Qbox that people don't realize so take a look through the docs and stuff to make sure it's not already there.
* **Check if there's already PR which provides that enhancement.**
* **Determine which resource the enhancement should be suggested in.** Whichever resource the suggestion is about, is where it should go. If the suggestion is about Qbox as a whole, make the suggestion in the qbx-core repository.
* **Determine which resource the enhancement should be suggested in.** Whichever resource the suggestion is about, is where it should go. If the suggestion is about Qbox as a whole, make the suggestion in the qbx_core repository.
* **Perform a [cursory search](https://github.com/search?q=is%3Aissue+user%3Aqbox-project++&type=issues&state=open)** to see if the enhancement has already been suggested. If it has, add a comment to the existing issue instead of opening a new one.

#### How Do I Submit A (Good) Enhancement Suggestion?
Expand Down
9 changes: 1 addition & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
# qb-ambulancejob
EMS Job and Death/Wound Logic for QB-Core Framework :ambulance:

## Dependencies
- [qb-core](https://github.com/QBCore-Remastered/qb-core) (Required)
- [qb-phone](https://github.com/QBCore-Remastered/qb-phone) (Required)
- [ox-target](https://github.com/overextended/ox_target) (Required)
- [ox_lib](https://github.com/overextended/ox_lib) (Required)

EMS Job. See qbx_medical for medical system

# Server.cfg Convar Update
- Global DrawTextUi Option
Expand Down
4 changes: 2 additions & 2 deletions client/damage/damage.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---Checks the player for damage, applies injuries, and damage effects
CreateThread(function()
while true do
exports['qbx-medical']:checkForDamageDeprecated()
exports.qbx_medical:checkForDamageDeprecated()
if not OnPainKillers and not IsInHospitalBed then
exports['qbx-medical']:applyDamageEffectsDeprecated()
exports.qbx_medical:applyDamageEffectsDeprecated()
end
Wait(100)
end
Expand Down
28 changes: 14 additions & 14 deletions client/hospital.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ end
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
QBX.Functions.Notify(Lang:t('error.beds_taken'), 'error')
if lib.callback.await('qbx_ambulancejob:server:isBedTaken', false, hospitalName, bedIndex) then
exports.qbx_core:Notify(Lang:t('error.beds_taken'), 'error')
return
end
end
Expand All @@ -59,29 +59,29 @@ local function putPlayerInBed(hospitalName, bedIndex, isRevive, skipOpenCheck)
bedIndexOccupying = bedIndex
bedOccupyingData = Config.Locations.hospitals[hospitalName].beds[bedIndex]
IsInHospitalBed = true
exports['qbx-medical']:disableRespawn()
exports.qbx_medical:disableRespawn()
CanLeaveBed = false
setBedCam()
CreateThread(function()
Wait(5)
if isRevive then
QBX.Functions.Notify(Lang:t('success.being_helped'), 'success')
exports.qbx_core:Notify(Lang:t('success.being_helped'), 'success')
Wait(Config.AIHealTimer * 1000)
TriggerEvent("hospital:client:Revive")
else
CanLeaveBed = true
end
end)
TriggerServerEvent('qbx-ambulancejob:server:playerEnteredBed', hospitalName, bedIndex)
TriggerServerEvent('qbx_ambulancejob:server:playerEnteredBed', hospitalName, bedIndex)
end

RegisterNetEvent('qbx-ambulancejob:client:onPlayerRespawn', function(hospitalName, bedIndex)
RegisterNetEvent('qbx_ambulancejob:client:onPlayerRespawn', function(hospitalName, bedIndex)
putPlayerInBed(hospitalName, bedIndex, true, true)
end)

---Notifies doctors, and puts player in a hospital bed.
local function checkIn(hospitalName)
local canCheckIn = lib.callback.await('qbx-ambulancejob:server:onCheckIn')
local canCheckIn = lib.callback.await('qbx_ambulancejob:server:onCheckIn')
if not canCheckIn then return end

exports.scully_emotemenu:playEmoteByCommand('notepad')
Expand All @@ -101,16 +101,16 @@ local function checkIn(hospitalName)
then
exports.scully_emotemenu:cancelEmote()
--- ask server for first non taken bed
local bedIndex = lib.callback.await('qbx-ambulancejob:server:getOpenBed', false, hospitalName)
local bedIndex = lib.callback.await('qbx_ambulancejob:server:getOpenBed', false, hospitalName)
if not bedIndex then
QBX.Functions.Notify(Lang:t('error.beds_taken'), 'error')
exports.qbx_core:Notify(Lang:t('error.beds_taken'), 'error')
return
end

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

Expand Down Expand Up @@ -180,7 +180,7 @@ else

local function insideCheckInZone()
if IsControlJustPressed(0, 38) then
exports['qbx-core']:KeyPressed(38)
lib.hideTextUI()
checkIn(hospitalName)
end
end
Expand Down Expand Up @@ -210,7 +210,7 @@ else

local function insideBedZone()
if IsControlJustPressed(0, 38) then
exports['qbx-core']:KeyPressed(38)
lib.hideTextUI()
putPlayerInBed(hospitalName, i, false)
end
end
Expand Down Expand Up @@ -242,7 +242,7 @@ local function leaveBed()
TaskPlayAnim(ped, getOutDict, getOutAnim, 100.0, 1.0, -1, 8, -1, false, false, false)
Wait(4000)
ClearPedTasks(ped)
TriggerServerEvent('qbx-ambulancejob:server:playerLeftBed', hospitalOccupying, bedIndexOccupying)
TriggerServerEvent('qbx_ambulancejob:server:playerLeftBed', hospitalOccupying, bedIndexOccupying)
FreezeEntityPosition(bedObject, true)
RenderScriptCams(false, true, 200, true, true)
DestroyCam(cam, false)
Expand Down Expand Up @@ -276,7 +276,7 @@ end)
---reset player settings that the server is storing
local function onPlayerUnloaded()
if bedIndexOccupying then
TriggerServerEvent('qbx-ambulancejob:server:playerLeftBed', hospitalOccupying, bedIndexOccupying)
TriggerServerEvent('qbx_ambulancejob:server:playerLeftBed', hospitalOccupying, bedIndexOccupying)
end
end

Expand Down
36 changes: 18 additions & 18 deletions client/job.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ local checkVehicle = false
---Configures and spawns a vehicle and teleports player to the driver seat.
---@param data { vehicleName: string, vehiclePlatePrefix: string, coords: vector4}
local function takeOutVehicle(data)
local netId = lib.callback.await('qbx-ambulancejob:server:spawnVehicle', false, data.vehicleName, data.coords)
local netId = lib.callback.await('qbx_ambulancejob:server:spawnVehicle', false, data.vehicleName, data.coords)
local timeout = 100
while not NetworkDoesEntityExistWithNetworkId(netId) and timeout > 0 do
Wait(10)
Expand Down Expand Up @@ -77,49 +77,49 @@ end
RegisterNetEvent('hospital:client:CheckStatus', function()
local player, distance = GetClosestPlayer()
if player == -1 or distance > 5.0 then
QBX.Functions.Notify(Lang:t('error.no_player'), 'error')
exports.qbx_core: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
QBX.Functions.Notify(Lang:t('success.healthy_player'), 'success')
exports.qbx_core: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'), QBX.Shared.Weapons[hash].damagereason }
args = { Lang:t('info.status'), exports.qbx_core:GetWeapons()[hash].damagereason }
})
end

if damage.bleedLevel > 0 then
TriggerEvent('chat:addMessage', {
color = { 255, 0, 0 },
multiline = false,
args = { Lang:t('info.status'), Lang:t('info.is_status', { status = exports['qbx-medical']:getBleedStateLabelDeprecated(damage.bleedLevel)}) }
args = { Lang:t('info.status'), Lang:t('info.is_status', { status = exports.qbx_medical:getBleedStateLabelDeprecated(damage.bleedLevel)}) }
})
end

local status = exports['qbx-medical']:getPatientStatus(damage.damagedBodyParts)
local status = exports.qbx_medical:getPatientStatus(damage.damagedBodyParts)
showTreatmentMenu(status)
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 QBX.Functions.HasItem('firstaid') then
QBX.Functions.Notify(Lang:t('error.no_firstaid'), 'error')
if not exports.qbx_core:HasItem('firstaid') then
exports.qbx_core:Notify(Lang:t('error.no_firstaid'), 'error')
return
end

local player, distance = GetClosestPlayer()
if player == -1 or distance >= 5.0 then
QBX.Functions.Notify(Lang:t('error.no_player'), 'error')
exports.qbx_core: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)
QBX.Functions.Notify(Lang:t('success.revived'), 'success')
exports.qbx_core:Notify(Lang:t('success.revived'), 'success')
TriggerServerEvent("hospital:server:RevivePlayer", GetPlayerServerId(player))
else
StopAnimTask(cache.ped, HealAnimDict, "exit", 1.0)
QBX.Functions.Notify(Lang:t('error.canceled'), 'error')
exports.qbx_core: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 QBX.Functions.HasItem('bandage') then
QBX.Functions.Notify(Lang:t('error.no_bandage'), 'error')
if not exports.qbx_core:HasItem('bandage') then
exports.qbx_core:Notify(Lang:t('error.no_bandage'), 'error')
return
end

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

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

Expand All @@ -214,10 +214,10 @@ local function checkGarageAction(vehicles, vehiclePlatePrefix, coords)
CreateThread(function()
while checkVehicle do
if IsControlJustPressed(0, 38) then
exports['qbx-core']:KeyPressed(38)
lib.hideTextUI()
checkVehicle = false
if cache.vehicle then
QBX.Functions.DeleteVehicle(cache.vehicle)
exports.qbx_core:DeleteVehicle(cache.vehicle)
else
showGarageMenu(vehicles, vehiclePlatePrefix, coords)
end
Expand Down
8 changes: 4 additions & 4 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
QBX.Functions.Notify(Lang:t('error.impossible'), 'error')
exports.qbx_core:Notify(Lang:t('error.impossible'), 'error')
return
end

Expand All @@ -21,7 +21,7 @@ lib.callback.register('hospital:client:UseFirstAid', function()
end)

lib.callback.register('hospital:client:canHelp', function()
return exports['qbx-medical']:getLaststand() and exports['qbx-medical']:getLaststandTime() <= 300
return exports.qbx_medical:getLaststand() and exports.qbx_medical:getLaststandTime() <= 300
end)

---@param targetId number playerId
Expand All @@ -47,10 +47,10 @@ RegisterNetEvent('hospital:client:HelpPerson', function(targetId)
})
then
ClearPedTasks(ped)
QBX.Functions.Notify(Lang:t('success.revived'), 'success')
exports.qbx_core:Notify(Lang:t('success.revived'), 'success')
TriggerServerEvent("hospital:server:RevivePlayer", targetId)
else
ClearPedTasks(ped)
QBX.Functions.Notify(Lang:t('error.canceled'), 'error')
exports.qbx_core:Notify(Lang:t('error.canceled'), 'error')
end
end)
6 changes: 3 additions & 3 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,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)
QBX.Functions.Notify({ title = Lang:t('text.alert'), description = text .. ' | ' .. street1name .. ' ' .. street2name, type = 'inform' })
exports.qbx_core: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 @@ -99,12 +99,12 @@ end)

function GetClosestPlayer()
local coords = GetEntityCoords(cache.ped)
return QBX.Functions.GetClosestPlayer(coords)
return exports.qbx_core:GetClosestPlayer(coords)
end

function OnKeyPress(cb)
if IsControlJustPressed(0, 38) then
exports['qbx-core']:KeyPressed(38)
lib.hideTextUI()
cb()
end
end
14 changes: 7 additions & 7 deletions client/setdownedstate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ local function getDoctorCount()
end

local function displayRespawnText()
local deathTime = exports['qbx-medical']:getDeathTime()
local deathTime = exports.qbx_medical:getDeathTime()
if deathTime > 0 and doctorCount > 0 then
DrawText2D(Lang:t('info.respawn_txt', { deathtime = math.ceil(deathTime) }), vec2(1.0, 1.44), 1.0, 1.0, 0.6, 4, 255, 255, 255, 255)
else
DrawText2D(Lang:t('info.respawn_revive', { holdtime = exports['qbx-medical']:getRespawnHoldTimeDeprecated(), cost = Config.BillCost }), vec2(1.0, 1.44), 1.0, 1.0, 0.6, 4, 255, 255, 255, 255)
DrawText2D(Lang:t('info.respawn_revive', { holdtime = exports.qbx_medical:getRespawnHoldTimeDeprecated(), cost = Config.BillCost }), vec2(1.0, 1.44), 1.0, 1.0, 0.6, 4, 255, 255, 255, 255)
end
end

Expand All @@ -21,7 +21,7 @@ local function playDeadAnimation(ped)
TaskPlayAnim(ped, InBedDict, InBedAnim, 1.0, 1.0, -1, 1, 0, false, false, false)
end
else
exports['qbx-medical']:playDeadAnimation()
exports.qbx_medical:playDeadAnimation()
end
end

Expand Down Expand Up @@ -49,7 +49,7 @@ local function handleRequestingEms()
end

local function handleLastStand()
local laststandTime = exports['qbx-medical']:getLaststandTime()
local laststandTime = exports.qbx_medical:getLaststandTime()
if laststandTime > Config.LaststandMinimumRevive then
DrawText2D(Lang:t('info.bleed_out', { time = math.ceil(laststandTime) }), vec2(1.0, 1.44), 1.0, 1.0, 0.6, 4, 255, 255, 255, 255)
elseif doctorCount == 0 then
Expand All @@ -59,7 +59,7 @@ local function handleLastStand()
handleRequestingEms()
end

exports['qbx-medical']:playLastStandAnimationDeprecated()
exports.qbx_medical:playLastStandAnimationDeprecated()
end

local function disableControls()
Expand All @@ -80,8 +80,8 @@ end
---Set dead and last stand states.
CreateThread(function()
while true do
local isDead = exports['qbx-medical']:isDead()
local inLaststand = exports['qbx-medical']:getLaststand()
local isDead = exports.qbx_medical:isDead()
local inLaststand = exports.qbx_medical:getLaststand()
if isDead or inLaststand then
disableControls()
if isDead then
Expand Down
Loading

0 comments on commit ec42987

Please sign in to comment.