Browse docs
Insurance
Reference for Insurance in ambulancejob.
Insurance
Read and write access to the health-insurance system used by the ambulance billing flow. Read exports let other resources check coverage, calculate co-pays, and enumerate providers. Write exports let admin menus, hospital welcome flows, or custom integrations grant, remove, or extend coverage without charging the player (the in-game /insurance command remains the normal purchase flow).
isInsuranceEnabled()
- Purpose: Reports whether the insurance subsystem is enabled in
Config.HealthInsurance. - Returns:
boolean—truewhen enabled.
if exports["sky_ambulancejob"]:isInsuranceEnabled() then
-- insurance features are available
end
hasInsurance(playerId)
- Purpose: Quick check whether a player currently has active insurance coverage.
- Arguments:
playerId(number): The server ID of the player.
- Returns:
boolean—truewhen insured,falseotherwise (alsofalsewhen insurance is disabled).
local insured = exports["sky_ambulancejob"]:hasInsurance(playerId)
getCoverage(playerId)
- Purpose: Returns a compact summary of the player's current coverage.
- Arguments:
playerId(number): The server ID of the player.
- Returns:
table | nil:providerId(string) — Provider ID (e.g."standard_care").label(string) — Display name (e.g."Standard Care").copayPercent(number) — Patient co-pay percentage.price(number) — Configured base premium.expiresAt(number) — Unix timestamp when coverage expires;0when no expiration.
local coverage = exports["sky_ambulancejob"]:getCoverage(playerId)
if coverage then
print(coverage.label, coverage.copayPercent, coverage.expiresAt)
end
getProvider(playerId)
- Purpose: Returns the full provider record (including
description) assigned to the player. - Arguments:
playerId(number): The server ID of the player.
- Returns:
table | nil—{ id, label, description, price, copayPercent }.
local provider = exports["sky_ambulancejob"]:getProvider(playerId)
getCopayPercent(playerId)
- Purpose: Returns the percentage the player will pay on a medical bill.
- Arguments:
playerId(number): The server ID of the player.
- Returns:
number— Co-pay percentage (100when uninsured or insurance disabled).
local percent = exports["sky_ambulancejob"]:getCopayPercent(playerId)
getExpiresAt(playerId)
- Purpose: Returns the Unix timestamp at which the player's coverage expires.
- Arguments:
playerId(number): The server ID of the player.
- Returns:
number— Unix timestamp;0when coverage has no expiration or the player is uninsured.
local expiresAt = exports["sky_ambulancejob"]:getExpiresAt(playerId)
calculateCopay(playerId, billAmount)
- Purpose: Calculates how much a patient would pay for a given bill amount, taking their active health insurance into account. If the player has no insurance or insurance is disabled, the full bill amount is returned.
- Arguments:
playerId(number): The server ID of the player whose insurance should be checked.billAmount(number): The original bill amount in dollars.
- Returns:
tablewith:copayAmount(number) — The amount the patient pays after insurance.originalAmount(number) — The original bill amount passed in.hasInsurance(boolean) — Whether the player has active insurance.provider(table?) — Insurance provider details (only when insured):id(string) — Provider ID (e.g."standard_care").label(string) — Display name (e.g."Standard Care").copayPercent(number) — The percentage the patient pays (e.g.30).
-- Example: Patient with "Standard Care" (30% copay) and a $900 bill
local result = exports["sky_ambulancejob"]:calculateCopay(playerId, 900)
print(result.copayAmount) -- 270 (patient pays 30%)
print(result.originalAmount) -- 900
print(result.hasInsurance) -- true
print(result.provider.label) -- "Standard Care"
-- Example: Patient without insurance
local result = exports["sky_ambulancejob"]:calculateCopay(playerId, 900)
print(result.copayAmount) -- 900 (full amount)
print(result.hasInsurance) -- false
calculateInsuranceCopay(playerId, billAmount)
- Purpose: Alias for
calculateCopay, kept for backward compatibility. Returns identical results.
local result = exports["sky_ambulancejob"]:calculateInsuranceCopay(playerId, 900)
getAllProviders()
- Purpose: Returns every insurance provider configured in
Config.HealthInsurance.providers, sorted alphabetically by label. - Returns:
table— array of{ id, label, description, price, copayPercent }entries (cloned, safe to mutate).
for _, provider in ipairs(exports["sky_ambulancejob"]:getAllProviders()) do
print(provider.id, provider.label, provider.price)
end
getProviderById(providerId)
- Purpose: Returns a single configured provider by its
id. - Arguments:
providerId(string): The provider identifier (e.g."basic_care").
- Returns:
table | nil.
local provider = exports["sky_ambulancejob"]:getProviderById("basic_care")
getInsuranceConfig()
- Purpose: Returns a read-only snapshot of the high-level insurance configuration.
- Returns:
table:enabled(boolean)command(string) — Chat command used to open the UI.account(string) — Account premiums are charged from.expirationOptions(table) — Sorted array of validdurationDaysvalues.
local cfg = exports["sky_ambulancejob"]:getInsuranceConfig()
print(cfg.command, cfg.account)
The following write exports do not charge the player. They are integration hooks intended for admin menus, hospital welcome flows, or custom scripts. Use the in-game
/insurance command for the normal player-purchase flow.setInsurance(playerId, providerId, durationDays?)
- Purpose: Assigns or refreshes coverage for the player. When called with the same provider that the player already holds, the duration is appended to the existing expiration (mirrors the in-game purchase flow).
- Arguments:
playerId(number): The server ID of the player.providerId(string): One of the configured provider IDs.durationDays(number?): Number of days the coverage lasts. Must be one ofConfig.HealthInsurance.expiration.availableDays. Defaults to the configured default duration when omitted.
- Returns:
boolean, string?—trueon success, otherwisefalseand one of:"disabled"— insurance is disabled in config."invalid_provider"— unknownproviderId."invalid_player"— player not online."invalid_identifier"— could not resolve identifier."invalid_duration"— duration not inavailableDays.
local ok, err = exports["sky_ambulancejob"]:setInsurance(playerId, "basic_care", 7)
if not ok then
print("setInsurance failed:", err)
end
removeInsurance(playerId)
- Purpose: Removes the player's coverage and clears the cache.
- Arguments:
playerId(number): The server ID of the player.
- Returns:
boolean—truewhen a coverage row was removed,falsewhen the player had no coverage.
exports["sky_ambulancejob"]:removeInsurance(playerId)
extendInsurance(playerId, additionalDays)
- Purpose: Extends an existing coverage's expiration by the given number of days. Base is the later of
nowand the currentexpiresAt. - Arguments:
playerId(number): The server ID of the player.additionalDays(number): Days to add (must be> 0).
- Returns:
boolean, string?—trueon success, otherwisefalseand one of:"disabled"— insurance is disabled in config."invalid_player"— player not online."invalid_duration"—additionalDaysis missing or non-positive."not_insured"— player has no active coverage.
local ok, err = exports["sky_ambulancejob"]:extendInsurance(playerId, 3)