These exports are available to server scripts. See Developer overview for how to call them from Lua, JavaScript and C#. In the signatures below, ? marks an optional parameter.
| Export | Purpose |
|---|---|
punishPlayer | Raise your own detection and punish through AstroShield. |
allowPlayer | Allow a legitimate action of one player for a short time. |
whitelistEntity / removeWhitelist | Allow spawning a model on purpose. |
getConfig | Read the configuration that AstroShield received from the dashboard. |
getStatus | Read the connection and license state. |
shouldDetect, isPlayerAdmin, isTxAdminWhitelistEnabled | Ask who is exempt from detections. |
isPlayerAcReady / waitForPlayerAcReady | Wait until a player is fully checked. |
isEventProtected | Ask whether the event protection covers an event. |
checkPlayerName | Reject players whose name contains a blacklisted word. |
getPlayers, getPlayer, getPlayerCount, getPlayerPositions, getPlayerFrameworkStatus | Player data as the dashboard shows it. |
getLocalRecords, getRecords | Read bans. |
getHeartbeatStatus, getServerResources | Diagnostics. |
Punish and allow#
punishPlayer#
Punishes a player through the normal AstroShield flow, exactly like a built-in detection would. Use it for your own detections, for example an exploit in one of your scripts.
exports.AstroShield:punishPlayer(playerId, detection, data?, action?) --> boolean| Parameter | Type | Description |
|---|---|---|
playerId | number | Server ID of the player. The player must be connected. |
detection | string | A name for your detection, for example myShop:priceExploit. It is stored with the ban and shown as the Detection. Use a name that is easy to recognize. |
data | string or table | A string is used as the reason. A table can carry a reason key, and the whole table is stored with the ban as detection data. Reasons are cut to 250 characters. |
action | string | ban, kick, warn, log or none. Without it the detection's configured action is used, and ban if there is none. |
Returns true when a punishment was started, and false when it was not. That happens when:
- the player is not connected, or is already being banned,
- the player is an admin excluded by the txAdmin whitelist,
- Dev Mode is on, in which case the detection is only logged,
- the action is
logornone, or the detection is configured as no-punishment.
What happens next depends on the action. A ban isolates the player, requests a video clip, stores the ban and drops the player with your ban message. See Punishments. AstroShield also fires astroshield:player:punished.
RegisterNetEvent('myShop:buy', function(item, price)
local src = source
if price < 0 then
exports.AstroShield:punishPlayer(src, 'myShop:priceExploit', {
reason = 'Sent a negative price to the shop',
item = item,
price = price,
})
return
end
-- ...
end)Another resource can also trigger the detection with the local server event astroshield:detection:trigger, which calls punishPlayer for it. See Events.
allowPlayer#
Tells AstroShield that something about a player is about to change legitimately, so neither the server nor the client checks punish it.
exports.AstroShield:allowPlayer(playerId, kind, ms?) --> boolean| Parameter | Type | Description |
|---|---|---|
playerId | number | Server ID of the player. |
kind | string | One of the server-side kinds below. |
ms | number | How long the allowance lasts. Default 5000, maximum 60000. |
The allowed kind values are teleport, revive, fade, attach, warpVehicle, superJump, playerSwitch, screenFade, camera, health and armour. Any other value makes the call return false.
Returns true when the allowance was applied. The player's client is told as well, so its own checks stay quiet.
-- Teleport a player to a hospital, legitimately
exports.AstroShield:allowPlayer(src, 'teleport', 5000)
SetEntityCoords(GetPlayerPed(src), 340.0, -1396.0, 32.5)The full list of kinds, including the ones that only exist on the client, is in Allowances.
whitelistEntity#
Allows a model to be spawned on purpose, so AstroShield does not treat it as a spoofed or spam spawn.
exports.AstroShield:whitelistEntity(modelHash, playerId?) --> boolean| Parameter | Type | Description |
|---|---|---|
modelHash | number or string | The model hash or the model name, like 'adder'. |
playerId | number | Optional. Allow it only for this player. Without it the model is allowed for everyone. |
Returns true when added and false when the model is not valid. A model that is on a blacklist is still blocked, whitelisting does not override a blacklist.
removeWhitelist#
Removes an entry added with whitelistEntity. Use the same arguments.
exports.AstroShield:removeWhitelist(modelHash, playerId?) --> booleanState and configuration#
getConfig#
Returns the configuration table that AstroShield received from the dashboard, or nil while it has not arrived yet. getAnticheatConfig is the same function under its older name.
local config = exports.AstroShield:getConfig()
if config and config.Settings and config.Settings.general.devMode then
print('AstroShield is in Dev Mode')
endThe server-side configuration contains your webhook URLs. Never send it to a client and never print it to a shared log.
getStatus#
Returns the connection and license state of the resource.
local status = exports.AstroShield:getStatus()| Field | Type | Meaning |
|---|---|---|
connected | boolean | A WebSocket connection to the backend is open. |
authenticated | boolean | The license was accepted. |
serverId | string or nil | The license ID of this server. |
serverName | string | Your sv_hostname. |
players, maxPlayers | number | Current players and sv_maxclients. |
version | string | The installed version of the resource. |
configLoaded | boolean | The configuration from the dashboard has arrived. |
activeModules | number | Number of JavaScript modules running. |
records | table | Counts of bans, warns and kicks the resource knows about. |
uptime | number | Seconds since the server started. |
resourceName | string | Normally AstroShield. |
licenseKey | boolean | true when a .key file was found. The key itself is never returned. |
expiresOn, plan | string or nil | Expiry date and plan of the license. |
Use it to check that protection is live, for example to show a warning in your admin tools when authenticated is false.
shouldDetect#
exports.AstroShield:shouldDetect(playerId) --> booleanReturns false when the player is exempt from detections because the txAdmin Whitelist is on and the player counts as an admin, and true otherwise. Use it before you run your own punishments, so you treat admins the same way AstroShield does.
isPlayerAdmin#
exports.AstroShield:isPlayerAdmin(playerId) --> booleanReturns true when AstroShield counts the player as an admin. See Permissions and whitelisting for what that means. The answer does not depend on the whitelist setting.
isTxAdminWhitelistEnabled#
exports.AstroShield:isTxAdminWhitelistEnabled() --> booleanReturns whether txAdmin Whitelist is switched on.
isPlayerAcReady#
exports.AstroShield:isPlayerAcReady(playerId) --> booleanReturns true once the player has spawned and a short grace period is over. Until then AstroShield does not run its checks on them.
waitForPlayerAcReady#
exports.AstroShield:waitForPlayerAcReady(playerId, timeoutMs?) --> booleanWaits, in the calling thread, until the player is ready and then returns true. It returns false if the player leaves or the time runs out. timeoutMs defaults to 60000 and is limited to 300000. Call it from a thread or an event handler, because it yields.
CreateThread(function()
if exports.AstroShield:waitForPlayerAcReady(src, 30000) then
-- safe to run actions that look suspicious during loading
end
end)isEventProtected#
exports.AstroShield:isEventProtected(eventName) --> booleanReturns false when the event protection is switched off, or when eventName is on the ignore list, and true otherwise. Useful to find out why an event of yours is or is not guarded.
checkPlayerName#
Rejects players whose name contains a word from the Anti Blacklisted Names list. Call it when a player connects.
exports.AstroShield:checkPlayerName(source, playerName, deferrals) --> booleanIt returns true when the name is fine. Otherwise it ends the connection with a message that names the word, through deferrals.done, and returns false. AstroShield already applies this check to every connection, so you only need this export if you handle the connection yourself.
Players#
These return the same data the dashboard shows.
exports.AstroShield:getPlayers() --> { { id, name, ping, role, vehicle, identifiers }, ... }
exports.AstroShield:getPlayer(playerId) --> { id, name, ping, identifiers } or nil
exports.AstroShield:getPlayerCount() --> number
exports.AstroShield:getPlayerPositions() --> { { id, name, coords = { x, y, z } }, ... }
exports.AstroShield:getPlayerFrameworkStatus(id) --> { success, data } or { success = false, error }identifiersis a table withlicense,license2,steam,discord,fivem,xbl,liveandip, as far as the player has them.vehicleistruewhile the player is in a vehicle.getPlayerFrameworkStatusreads health, armor and, when ESX, QBCore, Qbox or ox_core is running, hunger, thirst, job, money and inventory. See Frameworks.
Bans#
getLocalRecords#
Returns the bans that this server currently knows, as last sent by the backend. Expired timed bans are left out.
local bans = exports.AstroShield:getLocalRecords('bans')
for _, ban in ipairs(bans) do
print(ban.id, ban.username, ban.detection)
endOnly 'bans' is stored by the backend. 'warns' and 'kicks' return empty lists.
getRecords#
Asks the backend for the current bans. It waits for the answer, so call it from a thread or an event handler.
local result = exports.AstroShield:getRecords('bans', nil, 5000)
if result.success then
print(#result.data .. ' bans')
else
-- the backend did not answer, `result.data` is the last known list
print('using cached list:', result.cached, result.error)
end| Parameter | Description |
|---|---|
kind | 'bans'. |
serverId | Leave it nil. The backend uses your license. |
timeoutMs | How long to wait. Default 5000. |
See Ban records for the fields of a ban and the events that tell you when it changes.
Heartbeat and diagnostics#
exports.AstroShield:getHeartbeatStatus(playerId?) --> table
exports.AstroShield:getServerResources() --> { [resourceName] = started }
exports.AstroShield:validateExecution() --> truegetHeartbeatStatus(playerId)returns{ lastSeen, seq, started, alerted }for one player: when AstroShield's client part last reported in, how many reports it sent, which monitored resources it saw running and whether an alert was already raised. Without an argument it returns a table of all players keyed by server ID, andnilfor an unknown player.getServerResources()returns every resource and whether it is started.validateExecution()always returnstrue. It exists so that older resources that call it keep working.
Other exports you may see
These exist because the dashboard bridge and AstroShield's own scripts use them. They are not supported for your own use and can change without notice:
getRulesCatalog, getRulesSummary, setRules, inspectResource, sendCommand, reportGameEvent, reportRuleTriggered, reportReplayResult, sendStreamOffer, sendStreamIce, createRecord, deleteRecord, checkAdminPermission, getEmbedUrl, updateAnticheatConfig, registerModule, startModule, stopModule, forceHeartbeatCheck.
To remove a ban from a script, run the console command astroshield unban <id> through ExecuteCommand. See the recipes.