esx_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.

esx_ambulancejob/server/main.lua
RegisterNetEvent('esx_ambulancejob:onPlayerDistress')
AddEventHandler('esx_ambulancejob:onPlayerDistress', function()
    local source = source
    local injuredPed = GetPlayerPed(source)
    local injuredCoords = GetEntityCoords(injuredPed)
    
    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
            injuredCoords = property.metadata.exit
        end
    end
    
    if deadPlayers[source] then
        deadPlayers[source] = 'distress'
        local Ambulance = ESX.GetExtendedPlayers("job", "ambulance")
        for _, xPlayer in pairs(Ambulance) do
            xPlayer.triggerEvent('esx_ambulancejob:PlayerDistressed', source, injuredCoords)
        end
    end
end)

Kicking a player out of the property after respawning

esx_ambulancejob/server/main.lua
ESX.RegisterServerCallback('esx_ambulancejob:removeItemsAfterRPDeath', function(source, cb)
    local xPlayer = ESX.GetPlayerFromId(source)
    
    exports['vms_housing']:DropPlayerFromProperty(source)

    -- Rest of the code
end)

Last updated

Was this helpful?