A lot of handlers/functions are available to you in cl_open.lua.
Client
AddEventHandler('randol_medical:onPlayerDeath', function() -- gets triggered on death.end)AddEventHandler('randol_medical:onPlayerLastStand', function() -- gets triggered on laststandend)AddEventHandler('randol_medical:onCheckIn', function() -- Triggered when a player checks in/third eyes a bedend)AddEventHandler('randol_medical:onRevive', function() -- gets triggered on reviveend)AddEventHandler('randol_medical:ontargetBedEnter', function()end)RegisterNetEvent('randol_medical:client:onRespawn', function() -- gets triggered when a player is respawned.end)AddEventHandler('randol_medical:onBedExit', function() -- example to force a player with the crutch effect once they exit the bed after checking in/respawning into bed. -- exports.randol_medical:ForceWalk(1) -- 1 being the amount of minutes.end)AddEventHandler('randol_medical:aiMedicCalled', function() -- gets triggered when an ai medical is called.end)-- Local player states which can be called across resourcesifLocalPlayer.state.deadthenprint('do something, player is dead')endifLocalPlayer.state.laststandthenprint('do something, player is in last stand')endifLocalPlayer.state.isInHospitalBedthenprint('player is in hospital bed')endifLocalPlayer.state.knockedOutthenprint('player is knocked tf out')endifLocalPlayer.state.bleeding>0thenprint(LocalPlayer.state.bleeding) -- Prints the player's bleed levelend
-- This handles reviving from the txadmin menu (sv_open.lua)
AddEventHandler('txAdmin:events:healedPlayer', function(eventData)
if GetInvokingResource() ~= 'monitor' or type(eventData) ~= 'table' or type(eventData.id) ~= 'number' then
return
end
TriggerClientEvent('randol_medical:client:revivePlayer', eventData.id)
end)
AddEventHandler('randol_medical:server:death', function(src, state)
-- gets triggered when the statebag gets set. 'state' is a boolean.
end)
AddEventHandler('randol_medical:server:lastStand', function(src, state)
-- gets triggered when the statebag gets set. 'state' is a boolean.
end)
AddEventHandler('randol_medical:server:onRespawn', function(src)
-- gets triggered when a player is respawned.
end)
function PayForRevive(src)
-- You can use this to pay the player or send it to a business account.
local player = GetPlayer(src)
if not player then return end
addMoney(player, 'bank', Server.PayPerRevive.amount)
DoNotification(src, ('You received $%s for treating the patient.'):format(Server.PayPerRevive.amount))
end
RegisterNetEvent('prison:server:SetJailStatus', function(jailTime)
-- [Experimental] Using this qb-prison server event to set player state for in prison so I can tell where to respawn them.
-- May need to adapt to third party prison resources.
-- Would recommend using exports.randol_medical:SetJailState(src, true) for entering instead
-- and exports.randol_medical:SetJailState(src, false) for exiting in your actual prison script.
local src = source
if jailTime > 0 then
Player(src).state:set('jail', true, true)
else
Player(src).state:set('jail', false, true)
end
end)
function AddSocietyFunds(amount, reason)
if amount == 0 then return end
if GetResourceState('Renewed-Banking') == 'started' then
return exports['Renewed-Banking']:addAccountMoney('ambulance', amount)
end
if GetResourceState('qb-banking') == 'started' then
return exports['qb-banking']:AddMoney('ambulance', amount, reason)
end
if GetResourceState('qb-management') == 'started' then
return exports['qb-management']:AddMoney('ambulance', amount)
end
-- local society = exports.esx_society:GetSociety('ambulance')
-- if society then
-- TriggerEvent('esx_addonaccount:getSharedAccount', society.account, function(account)
-- account.addMoney(amount)
-- end)
-- end
lib.print.error('You must add your society funds export for function "AddSocietyFunds".')
end
function AutoBillPlayer(id, job) -- Adjust this yourself, example below.
if not Server.AutoBill.enable then return end
local player = GetPlayer(id)
if not player then return end
RemoveMoney(player, 'bank', Server.AutoBill.amount)
if GetResourceState('Renewed-Banking') == 'started' then
return exports['Renewed-Banking']:addAccountMoney(job, Server.AutoBill.amount)
end
if GetResourceState('qb-banking') == 'started' then
return exports['qb-banking']:AddMoney(job, Server.AutoBill.amount, 'ems-bill')
end
if GetResourceState('qb-management') == 'started' then
return exports['qb-management']:AddMoney(job, Server.AutoBill.amount)
end
-- local society = exports.esx_society:GetSociety('ambulance')
-- if society then
-- TriggerEvent('esx_addonaccount:getSharedAccount', society.account, function(account)
-- account.addMoney(amount)
-- end)
-- end
lib.print.error('You must add your society funds export for function "AutoBillPlayer".')
end
-- This is the revive event that can only be invoked from server side.
TriggerClientEvent('randol_medical:client:revivePlayer', source)
-- I have put the old qb-ambulance revive event in cl_open ('hospital:client:Revive') for compatability although i'd prefer not to use it.
-- Player states:
if Player(source).state.dead then
print('player is dead')
end