# Server: CreateOilSpill(payload, creator, options)

> Reference for Server: CreateOilSpill(payload, creator, options) in firejob.

[All exports](/docs/jobs/firejob/reference/exports)

**Optional developer integration.** Call this export from a **server script** in your own resource after `sky_firejob` has started. For normal installation and gameplay, use [Installation](/docs/jobs/firejob/setup/installation).

## Server Exports

### `CreateOilSpill(payload, creator, options)`

Creates an active oil spill and synchronizes it to clients. Firejob assigns the spill ID; you do not generate or supply it.

**This export returns two values.** On success, the second value is a table containing the new ID at **spill.id**. On failure, the second value is an error string.

<table>
<thead>
  <tr>
    <th>
      Argument / payload field
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Required / default
    </th>
    
    <th>
      Meaning
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        payload
      </code>
    </td>
    
    <td>
      <code>
        table
      </code>
    </td>
    
    <td>
      Required
    </td>
    
    <td>
      Spill creation data
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        payload.coords
      </code>
    </td>
    
    <td>
      <code>
        { x, y, z }
      </code>
      
       or <code>
        vector3
      </code>
    </td>
    
    <td>
      Required
    </td>
    
    <td>
      World position with numeric coordinates
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        payload.radius
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      Configured slip radius, normally <code>
        1.25
      </code>
    </td>
    
    <td>
      Spill radius; clamped to <code>
        0.25
      </code>
      
      –<code>
        5.0
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        payload.intensity
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      Configured default, normally <code>
        1.0
      </code>
    </td>
    
    <td>
      Intensity from <code>
        0.0
      </code>
      
       to <code>
        1.0
      </code>
      
      ; <code>
        1.0
      </code>
      
       is full intensity
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        payload.source
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        "vehicle"
      </code>
      
       in the spill record
    </td>
    
    <td>
      Origin tag, such as <code>
        "my_incident_resource"
      </code>
      
      ; useful when finding your spills later
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        payload.sourcePart
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        "engine_oil"
      </code>
    </td>
    
    <td>
      Originating fluid/component, for example <code>
        "engine_oil"
      </code>
      
       or <code>
        "transmission_fluid"
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        payload.sourceVehicleNetId
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      <code>
        0
      </code>
    </td>
    
    <td>
      Optional originating vehicle network ID; separate from the new spill ID
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        payload.sourcePlate
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        ""
      </code>
    </td>
    
    <td>
      Optional plate metadata
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        payload.canSpread
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
    </td>
    
    <td>
      <code>
        true
      </code>
    </td>
    
    <td>
      Whether vehicles may spread this spill
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        payload.state
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        "fresh"
      </code>
    </td>
    
    <td>
      Use <code>
        "bound"
      </code>
      
       to create a spill that is already treated with absorbent
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        creator
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      Optional
    </td>
    
    <td>
      Player server ID associated with the request; use <code>
        0
      </code>
      
       for a scripted incident
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        options
      </code>
    </td>
    
    <td>
      <code>
        table
      </code>
    </td>
    
    <td>
      Optional
    </td>
    
    <td>
      Source grouping and explicit limit overrides, described below
    </td>
  </tr>
</tbody>
</table>

#### Create, keep the ID, and remove the spill later

This complete server-side example creates a spill, saves its ID, and removes that same spill after one minute. Replace the coordinates with your incident location. In a real incident system, keep the ID in your own incident state and remove it when that incident ends.

```lua
-- server.lua
local ok, spill_or_error = exports["sky_firejob"]:CreateOilSpill({
    coords = { x = 215.0, y = -810.0, z = 30.0 },
    source = "my_incident_resource",
    radius = 1.5,
    intensity = 0.9
}, 0)

if not ok then
    print(("Could not create oil spill: %s"):format(spill_or_error))
    return
end

local spill_id = spill_or_error.id -- e.g. "17"; this is the ID to save.
print(("Created oil spill %s"):format(spill_id))

SetTimeout(60000, function()
    local removed = exports["sky_firejob"]:RemoveOilSpill(spill_id, "incident_finished")
    if removed then
        print(("Removed oil spill %s"):format(spill_id))
    else
        print(("Oil spill %s could not be removed; it may already be gone."):format(spill_id))
    end
end)
```

For example, a successful call returns `true` followed by a table with these fields:

<table>
<thead>
  <tr>
    <th>
      Field
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Meaning
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        id
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      Assigned spill ID, for example <code>
        "17"
      </code>
      
      ; pass this to <code>
        RemoveOilSpill
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        coords
      </code>
    </td>
    
    <td>
      <code>
        { x, y, z }
      </code>
    </td>
    
    <td>
      Spill position
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        radius
      </code>
      
      , <code>
        intensity
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      Effective values after defaults and clamping
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        state
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        "fresh"
      </code>
      
       or <code>
        "bound"
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        source
      </code>
      
      , <code>
        sourcePart
      </code>
      
      , <code>
        sourcePlate
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      Origin metadata
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        sourceVehicleNetId
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      Originating vehicle network ID, or <code>
        0
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        canSpread
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
    </td>
    
    <td>
      Whether the spill may spread
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        boundBy
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
      
       or absent
    </td>
    
    <td>
      Player server ID associated with binding, if recorded
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        createdAtMs
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      Creation time relative to the current server runtime; not a Unix timestamp
    </td>
  </tr>
</tbody>
</table>

A failed call returns `false, error`:

<table>
<thead>
  <tr>
    <th>
      Error
    </th>
    
    <th>
      Meaning
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        disabled
      </code>
    </td>
    
    <td>
      The oil spill system is disabled
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        invalid_payload
      </code>
    </td>
    
    <td>
      <code>
        payload
      </code>
      
       is not a table
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        invalid_coords
      </code>
    </td>
    
    <td>
      Coordinates are missing or invalid
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        cooldown
      </code>
    </td>
    
    <td>
      The same source group created a spill too recently
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        too_close
      </code>
    </td>
    
    <td>
      The position is too close to the last spill created by that source group
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        vehicle_limit
      </code>
    </td>
    
    <td>
      The originating vehicle has reached its active-spill limit
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        resetting_ids
      </code>
    </td>
    
    <td>
      An oil-spill ID reset is currently in progress
    </td>
  </tr>
</tbody>
</table>

Only read `.id` after checking `ok`. `local spill = CreateOilSpill(...)` would capture the first return value, a boolean, instead of the spill table.

#### Source grouping and limits

By default, calls from the same calling resource and the same `payload.source` share a cooldown and minimum-distance record. When `payload.source` is omitted, the export uses `"external"` for this grouping. Changing `creator` or `sourceVehicleNetId` alone does not create a separate source group.

For independent vehicle trails, set `options.sourceKey` to a stable key unique to your resource and that vehicle, such as `"my_incident_resource:vehicle:123"` for vehicle network ID `123`. `sourceKey` groups creation limits; it is not a spill ID and is not included in `GetOilSpills()` results.

The shipped defaults are a **5-second cooldown**, **6-metre spacing**, **12 active spills per vehicle**, and **80 active spills overall**. Exceeding the overall limit removes the oldest spill to make room. The effective configuration can change these limits. Removing a spill does not clear its source group's last creation time or position, so immediately repeating the example may return `cooldown` or `too_close`.

<table>
<thead>
  <tr>
    <th>
      <code>
        options
      </code>
      
       field
    </th>
    
    <th>
      Type / default
    </th>
    
    <th>
      Effect
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        sourceKey
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
      
      , automatic grouping
    </td>
    
    <td>
      Explicit shared key for cooldown and spacing
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        ignoreSourceCooldown
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
      
      , <code>
        false
      </code>
    </td>
    
    <td>
      Skip the source cooldown check for this creation
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        ignoreSourceMinDistance
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
      
      , <code>
        false
      </code>
    </td>
    
    <td>
      Skip minimum spacing for this creation
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        ignoreVehicleLimit
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
      
      , <code>
        false
      </code>
    </td>
    
    <td>
      Skip the per-vehicle limit for this creation
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        ignoreEnabled
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
      
      , <code>
        false
      </code>
    </td>
    
    <td>
      Allow this creation even when the oil spill system is disabled
    </td>
  </tr>
</tbody>
</table>

Use overrides deliberately for scripted scenes that need them. These server exports do not run cleanup job, duty, or item checks for the calling resource.

#### Lifetime and saved IDs

Spills can disappear through cleanup, expiry, spreading, capacity limits, or explicit removal. The shipped lifetime is 90 minutes. Firejob attempts to save spills to its database; a successful creation return confirms an active synchronized spill, not a database-write acknowledgement. Database failures are logged separately.

**Delete on restart** is enabled by default. Disable it to restore unexpired saved spills after a resource restart. An explicit ID reset renumbers active spills, and cleared IDs may be reused later. Treat saved IDs as references to the current incident, not permanent identifiers. Use `GetOilSpills()` and your origin metadata when rebuilding an integration's state.
