qb-ambulancejob

Notification to EMS

The following code detects the current property, and when a player sends a death message inside the property, it transmits the coordinates of the house entrance.

qb-ambulancejob/server/main.lua
RegisterNetEvent('hospital:server:ambulanceAlert', function(text)
    local src = source
    local ped = GetPlayerPed(src)
    local coords = GetEntityCoords(ped)
    local players = QBCore.Functions.GetQBPlayers()
    
    local playerProperty = exports['vms_housing']:GetPlayerCurrentProperty(source)
    if playerProperty then
        local property = exports['vms_housing']:GetProperty(playerProperty)
        if property.object_id then
            local building = exports['vms_housing']:GetProperty(property.object_id)
            if building.type == 'building' then
                property = building
            end
        end
        if property.metadata?.exit then
            coords = property.metadata.exit
        end
    end
    
    for _, v in pairs(players) do
        if v.PlayerData.job.name == 'ambulance' and v.PlayerData.job.onduty then
            TriggerClientEvent('hospital:client:ambulanceAlert', v.PlayerData.source, coords, text)
        end
    end
end)

Kicking a player out of the property after respawning

qb-ambulancejob/server/main.lua
RegisterNetEvent('hospital:server:RespawnAtHospital', function(hospitalIndex)
    local src = source
    local Player = QBCore.Functions.GetPlayer(src)

    exports['vms_housing']:DropPlayerFromProperty(src)

    -- Rest of the code
end)

Last updated

Was this helpful?