The DPS service layer, for Qbox servers on FiveM for GTAV Enhanced.
A DPS resource often needs something another script provides: a dispatch board, vehicle keys, the inventory, fuel. If each resource names that script itself, then changing the script means changing every resource.
dps_core is the one place that names them. A resource asks dps_core, and dps_core asks
whichever script is underneath.
-- Instead of naming an MDT, a keys script, an inventory and a fuel script:
exports.dps_core:Dispatch({ code = '10-31', type = 'Store robbery', priority = 2, coords = coords })
exports.dps_core:GiveKeys(source, vehicle)
exports.dps_core:AddItem(source, 'water', 2)
local fuel = exports.dps_core:GetFuel(vehicle)It is not a framework. The framework is Qbox. This sits on top.
| Service | Script underneath | If that script is not running |
|---|---|---|
| Dispatch | sd-phone, its MDT call board | The call is dropped. Dispatch returns nil. |
| Vehicle keys | qbx_vehiclekeys | Returns false |
| Items | ox_inventory | Returns false, or 0 for a count |
| Fuel | ox_fuel | Still works. Fuel is a number kept on the vehicle. |
| Injuries | dps_medical, or the Qbox qbx_medical it is a port of |
Returns nil |
| Postal codes | Nothing. dps_core does this itself, from data/postals.json. |
Returns nil if that file is missing |
Every service is optional. A resource never breaks because a server chose not to run one.
- Put this folder in your server's
resources. ensure dps_coreafterqbx_core, and before the DPS resources that use it.- Look for this line in the console. It tells you which services have a script behind them:
[dps_core] v0.2.0 ready: dispatch on (sd-phone), keys on (qbx_vehiclekeys), items on (ox_inventory), fuel on (ox_fuel), injuries on (qbx_medical)
Needs ox_lib and qbx_core. If you run
dps_hud, start it before this.
A screen that takes the keyboard can fail. Then a player cannot move, type or open the pause menu. This is the way out, and it does not depend on that screen working.
| How | What it does |
|---|---|
| F10 | Gives the keyboard and the mouse back, and unfreezes the player |
/unstick |
The same. It can be typed in the F8 console, which works even while a screen holds the keyboard. |
A player can change the key in Settings, Key Bindings, FiveM.
Esc belongs to the open screen. While any screen holds the keyboard, Esc never opens the pause menu behind it.
For a DPS script that takes the keyboard. Keyboard focus belongs to the script that took it.
One script cannot take it off another. So a script that ever calls SetNuiFocus(true, ...) must
listen for this, and let go:
AddEventHandler('dps_core:unstick', function()
SetNuiFocus(false, false)
-- and close your screen
end)A script can also free the player itself, when its own screen fails:
exports.dps_core:Unstick()A screen from a script that does not listen for the event keeps its focus. For those, F10 still closes the ox_lib screens and unfreezes the player.
One way for every DPS script and screen to say what it is doing, so a fault can be read and not guessed at. A line goes to two places: the player's F8 console, and the server log.
It is off until you turn it on. In server.cfg, or typed in the server console while the
server runs:
setr dps:log 1 # on: every line is written
setr dps:log 0 # off, the default: only warnings and errors are written
While it is on, dps_core also logs every time any screen takes the keyboard, and when it is
given back, with how long it was held. It asks the game, so this covers every script, not only
DPS ones.
[dps_core] a screen took the keyboard (in a vehicle: yes, pause menu: closed)
[dps_core] the keyboard was given back after 4.2 s
In the server log the same line shows which player it came from:
[log] player 1 [dps_core] a screen took the keyboard (in a vehicle: yes, pause menu: closed)
/dpsstate prints who holds the keyboard right now and the last 25 lines. It can be typed
in the F8 console while a screen holds the keyboard. It only prints. It changes nothing.
For a script. On a player's game or on the server:
exports.dps_core:Log('the garage menu opened')
exports.dps_core:Log('no parking spots came back', 'warn')
exports.dps_core:Log('could not read the vehicle list', 'error')- The script's name is added by
dps_core. A script cannot write under another script's name. - A line is cut to 300 plain characters.
- The server takes at most 20 lines in ten seconds from one player, so a fault that repeats every frame cannot flood the server log. The F8 console still gets every line.
| Call | Returns | What it does |
|---|---|---|
Dispatch(call) |
call id, or nil |
Raises a call on the dispatch board |
CleanText(text, limit?) |
text, or nil |
Cuts text down to plain characters, the way Dispatch does |
GiveKeys(source, vehicle, quiet?) |
true or false |
Gives a player the keys to a vehicle |
RemoveKeys(source, vehicle, quiet?) |
true or false |
Takes them away |
HasKeys(source, vehicle) |
true or false |
Does the player hold the keys? |
AddItem(source, item, count?, metadata?) |
true or false |
Gives an item. false if they cannot carry it. |
RemoveItem(source, item, count?, metadata?) |
true or false |
Takes an item |
CountItem(source, item) |
a number | How many they hold |
GetFuel(vehicle) |
0 to 100 | A vehicle's fuel |
SetFuel(vehicle, amount) |
true or false |
Sets it |
GetInjuries(source) |
a table, or nil |
What is wrong with a player. Read only. |
Report(kind, data?) |
true or false |
Says that something happened. See "Reports". |
RecentReports(kind?, limit?) |
a list | The latest reports, newest last |
AccountAdd(name, amount, reason?, by?) |
true or false |
Pays money into a department's account |
AccountRemove(name, amount, reason?, by?) |
true or false |
Takes money out. false if it does not hold that much. |
AccountBalance(name) |
a number, or nil |
What an account holds |
HudFor(target, slot, id, values) |
how many players | Puts something on one player's HUD, or several players' |
HudClearFor(target, slot, id) |
how many players | Takes it away |
Services() |
a table | Which services have a script behind them |
vehicle is always the vehicle entity.
The HUD. A script puts something on the screen by saying what is true. It never names the HUD resource, and it never sends a colour, a size or a position.
-- Server: a tracker for a whole crew, in one call.
exports.dps_core:HudFor(crew, 'tracker', 'job', { text = 'Tow the Sultan RS to Davis lot' })
-- A player's own game: its own screen only.
exports.dps_core:Hud('warning', 'hook', { text = 'Hook not attached', level = 'look' })
exports.dps_core:HudClear('warning', 'hook')There are four slots: dial, readout, tracker and warning. What each one takes, the
clocks, the glyph names and the rules are in the
dps_hud README.
targetis one player or a list. Only the server can set another player's screen.- What a script sets belongs to it. It cannot change or clear another script's.
- While dps_hud is not running, these calls show
nothing.
dps_corestill starts, because the way out lives here and must not go down with the HUD.
Accounts. Money that belongs to a department or a business, not to a person: the police account that fines are paid into, a hospital's, a city's.
exports.dps_core:AccountAdd('police', 250, 'Fine: speeding', officerCitizenId)nameis lower case letters, digits and underscores. A job name fits. An account is made the first time money is paid into it.amountis whole money, from 1 to 10,000,000.- Taking money out checks the balance and takes it in one step in the database, so two calls at once cannot both succeed.
- Every movement is written to a ledger,
dps_account_ledger, with the reason, who caused it and which resource asked. It is also reported asaccount.depositoraccount.withdraw. - It is for a server script, about money it has already checked and taken. A player's game cannot reach it.
- It needs
oxmysql. Without it every call returnsfalseand nothing else happens. - The balance is kept here, in
dps_accounts. A server that later runs a banking script changes one file in this resource, and every script that pays a department carries on.
Reports. A resource says what happened, once, and does not care who listens:
exports.dps_core:Report('police.fine', { officer = 'ABC12345', citizen = 'XYZ98765', amount = 250, reason = 'Speeding' })Anything that wants to know listens on the server:
AddEventHandler('dps_core:report', function(report)
-- report.kind 'police.fine'
-- report.at when, as os.time()
-- report.from the resource that reported it
-- report.data the details
end)kindisarea.eventin lower case. Anything else is refused.datais a flat table of text, numbers, true or false, and positions. Text is cleaned the wayDispatchcleans it. Anything else is dropped. At most 24 fields.- It is a plain server event. A player's game cannot fire it.
- The last 200 reports are kept in memory, for a script that starts late. A restart clears them. Nothing is written to the database: a script that wants a lasting record listens and keeps its own.
Reportis for a server script, about something it has already checked and done.
A dispatch call:
| Field | Meaning |
|---|---|
code |
A short code for the board, for example '10-31' |
type |
What happened, in a few words |
priority |
1 is the most urgent |
location |
Street or place name |
coords |
Where it is. A vector or a plain table. |
suspect, weapon |
Optional detail |
domain |
'ems' for the medical board. Anything else goes to the police board. |
Dispatch is for alerts a server script decides on by itself. If a client asked for the alert,
check it in your own script first: who is asking, how often, and where they really are.
Text is cleaned for you. Every text field is cut down to letters, digits, spaces and plain
punctuation, and to a set length, before it reaches the board. Text on a call often began in a
player's game, such as a street name or a typed message, and ends on a dispatcher's screen. Use
CleanText when you show the same words somewhere else too.
| Call | Returns | What it does |
|---|---|---|
HasKeys(vehicle) |
true or false |
Does this player hold the keys? |
GetFuel(vehicle) |
0 to 100 | A vehicle's fuel |
SetFuel(vehicle, amount) |
true or false |
Sets it, for a vehicle this player controls |
Hud(slot, id, values) |
true or false |
Puts something on this player's own HUD, or updates it |
HudClear(slot, id) |
true or false |
Takes it away |
| GetInjuries() | a table, or nil | What is wrong with this player |
| Unstick() | nothing | Gives the keyboard and the mouse back, and unfreezes the player. See "The way out". |
Keys, items and dispatch can only be changed from the server, on purpose.
What GetInjuries returns:
{
state = 'alive', -- 'alive', 'laststand' or 'dead'
bleed = 2, -- 0 is none, 4 is heavy
parts = { LLEG = 3 }, -- body part -> how bad, 1 is sore, 4 is severe. Unhurt parts are absent.
count = 1, -- how many parts are hurt
}Body parts: HEAD, NECK, SPINE, UPPER_BODY, LOWER_BODY, LARM, LHAND, LFINGER, LLEG,
LFOOT, RARM, RHAND, RFINGER, RLEG, RFOOT.
A client script that draws injuries can listen and not keep asking:
AddEventHandler('dps_core:injuriesChanged', function(injuries)
-- the same table as above, for this player
end)A postal is a short number for a spot on the map, such as 8094. Police, EMS and tow drivers call places by it.
dps_core answers "what is the postal here?" by itself. No postal script is needed. It draws
nothing and has no loop: the HUD shows the code under the street, and any script can ask.
| Call | Where | Returns |
|---|---|---|
GetPostal() |
Client | The postal where this player is |
GetPostal(source) |
Server | The postal where that player is |
PostalAt(coords) |
Both | The nearest postal to any place, and how far its point is in metres |
PostalSpot(code) |
Both | Where a postal is, as a vector2, for setting a route to it. nil if there is no such code. |
-- Server: stamp a dispatch call with where it happened.
local postal = exports.dps_core:PostalAt(coords)For players:
| Command | What it does |
|---|---|
/postal 8094 |
Sets the GPS to that postal |
/postal |
Clears it |
It sets the game's own waypoint. So the game draws the route on the minimap, the HUD's waypoint mark points at it, and it clears on arrival. What it says comes as a notification.
The codes are the OCRP set, 865 of them, which is the set drawn on the postal maps most
cities use. To use a different set, replace data/postals.json with a file of the same shape:
[{ "code": "8094", "x": 1.0, "y": 2.0 }]Credit. The list of points comes from nearest-postal by DevBlocky, MIT licence, copyright 2019 BlockBa5her. The OCRP postals were made by the OCRP community. Only the data is used. None of that script's code or on-screen text is.
GTA sends its own police after a player who breaks the law: wanted stars, cruisers, road blocks,
helicopters, SWAT. On a role play server the police are players, so dps_core turns that
response off. The game's ambulance and fire engine still come to a scene. Police cars that drive
around the city as traffic are not changed.
One setting, in server.cfg:
setr dps:aiPolice 0 # no police response and no wanted stars (the default)
setr dps:aiPolice 1 # the game's police respond as in single playerThe setting is applied again every 5 seconds, because the game can switch a service back on.
Open server/main.lua. The table at the top, PROVIDER, names the script for each service.