Skip to content

Server Exports

Horde Mission provides server-side exports for managing games programmatically, querying player data, and integrating with other scripts.

IsPlayerInHorde

Check if a specific player is in a horde game.

Syntax

lua
local inGame, game, gameId = exports['sd-horde']:IsPlayerInHorde(source)
ParameterTypeDescription
sourcenumberThe player's server ID
ReturnTypeDescription
inGamebooleanWhether the player is in a game
gametable?The game session data table
gameIdstring?The game ID string

Example

lua
local inGame, game, gameId = exports['sd-horde']:IsPlayerInHorde(source)
if inGame then
    print('Player is in game ' .. gameId)
    print('Map: ' .. game.map .. ', Round: ' .. game.currentRound)
else
    print('Player is not in a horde game')
end

StartHordeGame

Start a horde game for a player (or their group). Creates a pending game and shows the entry location.

Syntax

lua
local gameId = exports['sd-horde']:StartHordeGame(source, mapName, difficultyId)
ParameterTypeDescription
sourcenumberPlayer server ID (host)
mapNamestringMap ID from config (e.g. "server_farm")
difficultyIdstringDifficulty ID (e.g. "easy", "normal", "hard", "nightmare")
ReturnTypeDescription
gameIdstring?The created game ID, or nil on failure

Example

lua
local gameId = exports['sd-horde']:StartHordeGame(source, 'server_farm', 'normal')
if gameId then
    print('Game created: ' .. gameId .. ' — player must walk to entry point')
else
    print('Failed to create game')
end

ForceStartHordeGame

Force start a horde game immediately, skipping the entry location walkup. Same parameters as StartHordeGame.

Syntax

lua
local gameId = exports['sd-horde']:ForceStartHordeGame(source, mapName, difficultyId)
ReturnTypeDescription
gameIdstring?The created game ID, or nil on failure

Example

lua
local gameId = exports['sd-horde']:ForceStartHordeGame(source, 'cayo_estate', 'hard')
if gameId then
    print('Game started immediately: ' .. gameId)
end

StartHordeWithPlayers

The most flexible way to start a horde game. Pass any list of players in various formats.

Syntax

lua
local gameId, error = exports['sd-horde']:StartHordeWithPlayers(players, mapName, difficultyId, options)
ParameterTypeDescription
playerstableArray of players — {1, 2, 3}, { {source = 1} }, or { {serverId = 1, name = "Player1"} }
mapNamestringMap ID
difficultyIdstringDifficulty ID
optionstable?Optional settings (see below)
OptionTypeDefaultDescription
skipEntrybooleanfalseSkip entry location, start immediately
hostnumberFirst playerWhich player is the host
ReturnTypeDescription
gameIdstring?The created game ID, or nil on failure
errorstring?Error message on failure

Example

lua
local gameId, err = exports['sd-horde']:StartHordeWithPlayers(
    {1, 2, 3},
    'server_farm',
    'easy',
    { skipEntry = true, host = 1 }
)
if gameId then
    print('Game started with 3 players: ' .. gameId)
else
    print('Failed to start: ' .. err)
end

ForceEndGame

Force end a player's current game.

Syntax

lua
local success = exports['sd-horde']:ForceEndGame(source)
ParameterTypeDescription
sourcenumberPlayer server ID
ReturnTypeDescription
successbooleanWhether the game was ended

Example

lua
local success = exports['sd-horde']:ForceEndGame(source)
if success then
    print('Game ended for player ' .. source)
end

GetActiveGames

Get a list of all currently active horde games.

Syntax

lua
local games = exports['sd-horde']:GetActiveGames()
ReturnTypeDescription
gamestableArray of game info tables

Each game table contains:

FieldTypeDescription
gameIdstringUnique game session ID
mapstringMap identifier
difficultystringDifficulty identifier
playerCountnumberNumber of players in game
playerstableArray of player server IDs
currentRoundnumberCurrent round number
statestringCurrent game state
moneynumberCurrent team money/coins

Example

lua
local games = exports['sd-horde']:GetActiveGames()
print(#games .. ' active games')
for _, game in ipairs(games) do
    print(('  [%s] %s %s — round %d, %d players'):format(
        game.gameId, game.map, game.difficulty,
        game.currentRound, game.playerCount
    ))
end

GetPlayerGameInfo

Get detailed information about a player's current game.

Syntax

lua
local info = exports['sd-horde']:GetPlayerGameInfo(source)
ParameterTypeDescription
sourcenumberPlayer server ID
ReturnTypeDescription
infotable?Game info table, or nil if not in a game

The returned table contains:

FieldTypeDescription
gameIdstringGame session ID
mapstringMap ID
mapLabelstringMap display name
difficultystringDifficulty ID
difficultyLabelstringDifficulty display name
currentRoundnumberCurrent round
maxRoundsnumberMaximum rounds for this difficulty
statestringCurrent game state
moneynumberTeam currency
playerCountnumberPlayer count
playerstableArray of player server IDs
isDeadbooleanWhether this player is dead

Example

lua
local info = exports['sd-horde']:GetPlayerGameInfo(source)
if info then
    print(('Playing %s on %s — round %d/%d'):format(
        info.mapLabel, info.difficultyLabel,
        info.currentRound, info.maxRounds
    ))
    print('Team money: ' .. info.money)
    print('Player is ' .. (info.isDead and 'dead' or 'alive'))
end

GetPlayerStats

Get a player's persistent horde stats.

Syntax

lua
local stats = exports['sd-horde']:GetPlayerStats(source)
ParameterTypeDescription
sourcenumberPlayer server ID
ReturnTypeDescription
statstable?Stats table, or nil if not found

The returned table contains:

FieldTypeDescription
levelnumberCurrent horde level
xpnumberTotal XP earned
statstableDetailed statistics (kills, games, etc.)
completedMapstableMaps and difficulties completed

Example

lua
local stats = exports['sd-horde']:GetPlayerStats(source)
if stats then
    print('Level ' .. stats.level .. ' (' .. stats.xp .. ' XP)')
    print('Total kills: ' .. (stats.stats.kills or 0))
    print('Games played: ' .. (stats.stats.gamesPlayed or 0))
end

AddPlayerXP

Add XP to a player.

Syntax

lua
local success, newLevel = exports['sd-horde']:AddPlayerXP(source, amount)
ParameterTypeDescription
sourcenumberPlayer server ID
amountnumberAmount of XP to add (must be > 0)
ReturnTypeDescription
successbooleanWhether XP was added
newLevelnumber?New level if the player leveled up, otherwise nil

Example

lua
local success, newLevel = exports['sd-horde']:AddPlayerXP(source, 500)
if success and newLevel then
    print('Player leveled up to ' .. newLevel .. '!')
elseif success then
    print('Added 500 XP')
end

SetPlayerLevel

Set a player's level directly.

Syntax

lua
local success = exports['sd-horde']:SetPlayerLevel(source, level)
ParameterTypeDescription
sourcenumberPlayer server ID
levelnumberLevel to set
ReturnTypeDescription
successbooleanWhether the level was set

Example

lua
local success = exports['sd-horde']:SetPlayerLevel(source, 10)
if success then
    print('Player level set to 10')
end

IsPlayerOnCooldown

Check if a player is on cooldown from a recent mission.

Syntax

lua
local onCooldown, remainingSeconds, formattedTime = exports['sd-horde']:IsPlayerOnCooldown(source)
ParameterTypeDescription
sourcenumberPlayer server ID
ReturnTypeDescription
onCooldownbooleanWhether on cooldown
remainingSecondsnumber?Seconds remaining
formattedTimestring?Formatted time string (e.g. "2m 30s")

Example

lua
local onCooldown, _, formattedTime = exports['sd-horde']:IsPlayerOnCooldown(source)
if onCooldown then
    print('Player is on cooldown for ' .. formattedTime)
else
    print('Player can start a new game')
end

SetPlayerCooldown

Set a player's cooldown duration. Pass 0 or nil for minutes to clear the cooldown.

Syntax

lua
local success = exports['sd-horde']:SetPlayerCooldown(source, minutes)
ParameterTypeDescription
sourcenumberPlayer server ID
minutesnumber?Cooldown duration in minutes (0 or nil to clear)
ReturnTypeDescription
successbooleanWhether the cooldown was set

Example

lua
-- Set a 5-minute cooldown
exports['sd-horde']:SetPlayerCooldown(source, 5)

-- Clear the cooldown
exports['sd-horde']:SetPlayerCooldown(source, 0)

ClearPlayerCooldown

Clear a player's cooldown.

Syntax

lua
local success = exports['sd-horde']:ClearPlayerCooldown(source)
ParameterTypeDescription
sourcenumberPlayer server ID
ReturnTypeDescription
successbooleanWhether the cooldown was cleared

Example

lua
local success = exports['sd-horde']:ClearPlayerCooldown(source)
if success then
    print('Cooldown cleared')
end

GetAvailableMaps

Get all available maps and their difficulties.

Syntax

lua
local maps = exports['sd-horde']:GetAvailableMaps()
ReturnTypeDescription
mapstableArray of map info tables

Each map table contains:

FieldTypeDescription
idstringMap identifier
labelstringMap display name
difficultiestableArray of { id, label, maxRounds }

Example

lua
local maps = exports['sd-horde']:GetAvailableMaps()
for _, map in ipairs(maps) do
    print(map.label .. ' (' .. map.id .. ')')
    for _, diff in ipairs(map.difficulties) do
        print('  ' .. diff.label .. ' — ' .. diff.maxRounds .. ' rounds')
    end
end

RemovePlayerFromGame

Remove a specific player from their current game (handles inventory return, bucket reset, etc.).

Syntax

lua
local success = exports['sd-horde']:RemovePlayerFromGame(source)
ParameterTypeDescription
sourcenumberPlayer server ID
ReturnTypeDescription
successbooleanWhether the player was removed

Example

lua
local success = exports['sd-horde']:RemovePlayerFromGame(source)
if success then
    print('Player removed from game safely')
end

Perk Exports

INFO

Server perk exports manage perks across all players in a game session. Perk IDs are strings matching the keys in the VotePerks config (e.g. "double_damage", "speed_demon").

ApplyPerkToAllPlayers

Apply a perk to all players in a specific game session.

Syntax

lua
exports['sd-horde']:ApplyPerkToAllPlayers(gameId, perkId)
ParameterTypeDescription
gameIdstringThe game session ID
perkIdstringThe perk ID to apply

Example

lua
local inGame, _, gameId = exports['sd-horde']:IsPlayerInHorde(source)
if inGame then
    exports['sd-horde']:ApplyPerkToAllPlayers(gameId, 'double_damage')
    print('Applied double damage to all players in game ' .. gameId)
end

ClearAllPerksForAllPlayers

Remove all active perks from every player in a game session.

Syntax

lua
exports['sd-horde']:ClearAllPerksForAllPlayers(gameId)
ParameterTypeDescription
gameIdstringThe game session ID

Example

lua
exports['sd-horde']:ClearAllPerksForAllPlayers(gameId)
print('Cleared all perks for game ' .. gameId)

GetActivePerks

Get the list of active perks for a game session.

Syntax

lua
local perks = exports['sd-horde']:GetActivePerks(gameId)
ParameterTypeDescription
gameIdstringThe game session ID
ReturnTypeDescription
perkstableArray of active perk ID strings

Example

lua
local perks = exports['sd-horde']:GetActivePerks(gameId)
print(#perks .. ' perks active in game ' .. gameId)
for _, perkId in ipairs(perks) do
    print('  - ' .. perkId)
end

ProcessWinningPerk

Process the result of a perk vote — applies the winning perk to all players in the game.

Syntax

lua
exports['sd-horde']:ProcessWinningPerk(gameId, perkId)
ParameterTypeDescription
gameIdstringThe game session ID
perkIdstringThe winning perk ID from the vote

GetServerLootValueMultiplier

Get the server-side loot value multiplier for a game session, accounting for all active perks.

Syntax

lua
local multiplier = exports['sd-horde']:GetServerLootValueMultiplier(gameId)
ParameterTypeDescription
gameIdstringThe game session ID
ReturnTypeDescription
multipliernumberCombined loot value multiplier (1.0 = no change)

Example

lua
local mult = exports['sd-horde']:GetServerLootValueMultiplier(gameId)
print('Loot in this game is worth ' .. (mult * 100) .. '% of base value')

Mystery Box Exports

CleanupMysteryBoxForGame

Remove all mystery boxes associated with a game session. Called automatically when a game ends, but available for manual cleanup.

Syntax

lua
exports['sd-horde']:CleanupMysteryBoxForGame(gameId)
ParameterTypeDescription
gameIdstringThe game session ID

Example

lua
exports['sd-horde']:CleanupMysteryBoxForGame(gameId)
print('Mystery boxes cleaned up for game ' .. gameId)