# esx\_ambulancejob

{% hint style="info" %}
**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.
{% endhint %}

<pre class="language-lua" data-title="esx_ambulancejob/server/main.lua"><code class="lang-lua">RegisterNetEvent('esx_ambulancejob:onPlayerDistress')
AddEventHandler('esx_ambulancejob:onPlayerDistress', function()
    local source = source
    local injuredPed = GetPlayerPed(source)
    local injuredCoords = GetEntityCoords(injuredPed)
    
<strong>    local playerProperty = exports['vms_housing']:GetPlayerCurrentProperty(source)
</strong><strong>    if playerProperty then
</strong><strong>        local property = exports['vms_housing']:GetProperty(playerProperty)
</strong><strong>        if property.object_id then
</strong><strong>            local building = exports['vms_housing']:GetProperty(property.object_id)
</strong><strong>            if building.type == 'building' then
</strong><strong>                property = building
</strong><strong>            end
</strong><strong>        end
</strong><strong>        if property.metadata?.exit then
</strong><strong>            injuredCoords = property.metadata.exit
</strong><strong>        end
</strong><strong>    end
</strong>    
    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)
</code></pre>

{% hint style="info" %}
**Kicking a player out of the property after respawning**
{% endhint %}

<pre class="language-lua" data-title="esx_ambulancejob/server/main.lua"><code class="lang-lua">ESX.RegisterServerCallback('esx_ambulancejob:removeItemsAfterRPDeath', function(source, cb)
    local xPlayer = ESX.GetPlayerFromId(source)
    
<strong>    exports['vms_housing']:DropPlayerFromProperty(source)
</strong>
    -- Rest of the code
end)
</code></pre>
