Skip to main content

Client API

Every export below is client-side. Apart from the three headset exports, they live in API.lua inside the resource. That file is in escrow_ignore, so you can read the source of everything from Panels down. The one server-side export, registerRoadVrGame, is documented in the Game SDK.

Headset

isRoadVrActive

Is RoadVR running for this player?
boolean
true whenever the state is anything but off — including while the headset is still booting or already shutting down. Test getRoadVrState() for 'passthrough' if you need to know the player can act right now.

getRoadVrState

The state machine, as a string.
string
off, booting, passthrough, focus or shutdown — and a few more that hold the cursor while a feature runs: widgets (the widget editor), beat, minigolf, shooter and game. More may be added.passthrough is windows floating while the player moves normally. focus is the mode in which the mouse is free and the player can click.

putVisorOn

Puts the visor on another ped’s head.
number
required
The ped handle to fit the visor to.
table | nil
A handle you keep for takeVisorOff. nil when nothing was possible on that ped.
This exists for scene work — actors who should be wearing the headset without the calling resource having to know anything about head bones, offsets or addon clothing. It does not start a session for that ped.

takeVisorOff

table
required
The handle putVisorOn returned.

Notifications

showRoadVrNotification

Shows a notification card in the headset — the same card RoadVR’s own messages use, collected in the Control Centre.
table
required
boolean
true when the headset took the notification. false when nobody is wearing one, the headset is still booting or shutting down, or there is no text — show your normal notification then.
Text is plain. GTA colour codes such as ~r~ and HTML tags are removed; ~n~ and <br> become line breaks. Over-long text is cut at the limit.

Panels

openRoadVrPanel

Opens a window for a registered app.
string
required
A registered app id — one of RoadVR’s own, or one you registered yourself.
table
string | nil
nil when the headset is off. If the same app is already open, that window is closed and the new one gets a new id. At Config.MaxPanels the oldest window is closed to make room.

closeRoadVrPanel

string
required
The id openRoadVrPanel returned.

Custom apps

Full guide: Custom Apps.

registerRoadVrApp

table
required
boolean
false when the id already belongs to another resource or is refused. Registering again from your own resource replaces your earlier definition.
string
'definition is not a table', 'missing id', 'missing page', 'reserved built-in id' or 'id "<id>" already belongs to <resource>'.

unregisterRoadVrApp

Removes the app and closes its window if it is open. Not needed on resource stop — that is cleaned up on its own.
boolean
false when the id is not yours.

sendToRoadVrApp

Sends data into your app’s window. It arrives as a message event carrying { source: 'roadvr', ...payload }.
boolean
true when the id is yours, false when it is not. A message to a closed window is dropped quietly — normal, not an error. Your resource has no idea whether the player has your app open.

Custom widgets

Full guide: Custom Widgets.

registerRoadVrWidget

table
required
boolean
false when the id already belongs to another resource.
string
Why it failed, when it did.

unregisterRoadVrWidget

Widgets already hanging are left on the wall. They are in the player’s profile, and a resource going away is not a reason to clear somebody’s room — they fall back to an unavailable plate until it returns.
boolean
false when the kind is not yours.

sendToRoadVrWidget

Reaches every widget of this kind that is currently drawn. Arrives as { source: 'roadvr', widget: '<id>', ...payload }.
boolean
false when the kind is not yours.

getRoadVrWidgetInstances

Which widgets of your kind are on a wall right now.
table
A list of instance ids. An empty table is a normal answer — the player may simply not have hung one.

World markers

Full guide: Custom Markers. Markers do not survive a RoadVR restart — add them again in onClientResourceStart for roadvr.

addRoadVrMarker

table
required
string | nil
The marker’s handle, or nil with a reason as the second value.

updateRoadVrMarker

Patches any field except kind. A patch follows the same rules as a definition and fails with the same kind of reason.
boolean
false for an unknown handle — normal after a RoadVR restart — or a patch that breaks a rule, with the reason as the second value.

removeRoadVrMarker

boolean
false for an unknown handle, quietly.

clearRoadVrMarkers

Removes all markers of your resource. Not needed on resource stop.
number
How many were removed.

Talking to a page from inside the frame

Everything above is Lua. The other half — a page asking RoadVR about the theme, its window, or the fact that it is closing — is the JavaScript SDK.

JavaScript SDK

ready(), the context object, the events, applyTheme(), watch(), setActions() and close()