RedM documentation

Murphy's Doctor

Developers

Framework adapters


Everything murphy_doctor needs from a framework goes through a small set of global functions defined by an adapter: one file on the server (server/adapters/<Name>Adapter.lua) and one on the client (client/adapters/<Name>Adapter.lua). The rest of the script only calls these globals, never the framework directly.

Both adapter folders and shared/framework.lua are outside the escrow (escrow_ignore): premium and open source buyers can read, edit and add adapters. This page describes the contract and how to adapt the script to a forked or custom framework. For the behaviour of the shipped adapters on a live server, see Frameworks.

How an adapter is selected

  1. shared/config.lua loads first and sets Config.framework.

  2. shared/framework.lua (loaded next, on both sides) turns that value into one canonical key, Config.FrameworkResolved: "REDEMRP2k23", "vorp" or "rsg". With "auto", it probes the resources listed in PROBES and takes the first one started. Explicit values go through the ALIASES table. It also defines IsFramework(key).

  3. Every adapter file is wrapped in a guard:

    if Config.FrameworkResolved == "vorp" then
        -- functions
    end
    

    Only the adapter whose key matches defines its functions.

The manifest loads shared/**/*.lua, client/**/*.lua and server/**/*.lua in alphabetical order: server/adapters/ loads before the other server files, and the client files whose name starts with _ load before client/adapters/. A new adapter file dropped in either folder is loaded without any manifest change.

The shipped files:

Key Server Client
REDEMRP2k23 server/adapters/REDEMRP2k23Adapter.lua client/adapters/REDEMRP2k23Adapter.lua
vorp server/adapters/VORPAdapter.lua client/adapters/VORPAdapter.lua
rsg server/adapters/RSGAdapter.lua client/adapters/RSGAdapter.lua

Server adapter

src, targetID and targetSrc are always a player server id.

Required

Missing any of these is reported by doc_selftest as [FAIL] adapter functions missing: ....

Function Returns Contract
GetCharIdentifier(src) string or nil The character id, the key of every murphy_doctor_* row. nil while no character is loaded. Must stay the same for the whole life of that character (cache it per src if the lookup is costly, and clear the cache when the player drops or switches character)
GetCharFirstname(src) string First name. Return "Unknown" when not found
GetCharLastname(src) string Last name. Return "Unknown" when not found
GetCharGroup(src) string or nil Staff group, compared with Config.AdminGroups
GetCharJob(src) string or nil Job name, compared with Config.DoctorJobs, Config.Incidents.LawJobs and Config.Autopsy.LawJobs
GetPlayerMoney(src) number Cash the player carries
AddMoneyToPlayer(src, amount) boolean Give cash. true on success
RemoveMoneyFromPlayer(src, amount) boolean Take cash. Must return false, without taking anything, when the player cannot afford it
GiveItem(src, item, amount, meta) truthy / falsy Add an item. meta is an optional metadata table (the poison payload, or { description = ... })
RemoveItem(src, item, amount, meta) truthy / falsy Remove an item. When meta is given, remove from the stack carrying that metadata (a poisoned item), not from any stack
GetItemAmount(src, item) number Total count of the item, every stack included (0 when none)
FrameworkRegisterUsableItem(itemName, cb) - Make the item usable. When the player uses it, call cb(src, usedItem) with usedItem = { name = itemName, meta = <metadata of the used stack, or nil> }

Also called

These are called without an existence check by the script: implement them too.

Function Returns Contract
FrameworkCloseInventory(src) - Close the player's inventory screen (an item that opens a menu or starts an animation)
GetPlayerInventory(src) table (array) The items the player carries with a count above 0, each as { name, amount, quantity, label, image, metadata } (slot optional). image must be a URL the interface can load, such as nui://<inventory>/html/.... Used by the treatment form (medication stock) and the poison menu
GetItemMeta(src, item) table or nil Metadata of a stack of that item. Used to read and write the poison mark
getItemLabel(name) string Display label of an item, the item name as fallback

Optional

Each call site checks that the function exists.

Function Returns Used for
GetCharJobDuty(src) boolean or nil On-duty flag of the job, for Config.Interactions.DoctorJobRequireDuty. Return false only when the player is known to be off duty. When the function does not exist and the option is on, a console line says the restriction is ignored
FrameworkSetDead(src, isDead) - Mirror the coma into the framework's own dead flag (called on coma entry, restore and exit)
FrameworkIsDead(src) boolean or nil Read that flag back, for the debug command doc_frameworkdead
FrameworkRefreshInventory(src) - Resend the inventory to the client after a removal targeted by metadata, for inventories that do not do it themselves
getItemDefs() table Item definitions keyed by name. doc_selftest uses it to check that the configured items exist; return {} if your inventory cannot list them

Defined by the shipped adapters, not called

GetCharJobGrade(src), getItemPrice(name) and ResolveIdentifierByName(firstName, lastName) (and GetAllItemsOfName on REDEM:RP) exist in the shipped adapters but are not called by version 1.0.1. You may leave them out of a new adapter.

Framework events to handle in the server adapter

Situation What to do
The player switches character during a session Clear any identifier cache for that src (the VORP adapter listens to vorp:SelectedCharacter, the RSG one to RSGCore:Server:OnPlayerLoaded)
The player drops Clear the cache (playerDropped)
An admin or another script revives a player through the framework Call AuthorizeComaExit(target) before that revive reaches the client, so the server accepts the early coma exit (Config.Coma.ServerExitCheck). The VORP adapter does it on vorp_core:Server:OnPlayerRevive, the RSG one on rsg-adminmenu:server:playerrevive after checking the admin's permission

How the shipped adapters fill the contract

Function REDEM:RP VORP RSG
GetCharIdentifier user.citizenid character.charIdentifier (as text) PlayerData.citizenid
GetCharGroup user.group Account group if listed in Config.AdminGroups, else character group Permission probe, then the command ACE, else "user"
GetCharJob user.job character.job PlayerData.job.name
GetCharJobDuty not defined always nil PlayerData.job.onduty
Money user.money, addMoney, removeMoney character.money, addCurrency(0, ...), removeCurrency(0, ...) money.cash, AddMoney('cash', ...), RemoveMoney('cash', ...)
Items redemrp_inventory item object (getItem, AddItem, RemoveItem) exports.vorp_inventory (addItem, subItem, getItemCount, getItem, getUserInventoryItems) exports['rsg-inventory'] (AddItem, RemoveItem, GetItemCount, GetItemByName)
FrameworkRegisterUsableItem Local event RegisterUsableItem:<name> exports.vorp_inventory:registerUsableItem RSGCore.Functions.CreateUseableItem
getItemDefs exports.redemrp_inventory:GetItemsList() Lookup table: Config.Items first, then exports.vorp_inventory:getItemDB(name) on access RSGCore.Shared.Items
FrameworkSetDead no-op character.setDead or the vorp:ImDead relay SetMetaData('isdead', ...)
FrameworkRefreshInventory yes not defined not defined
FrameworkIsDead not defined character.isdead not defined

Client adapter

Function Required Contract
FrameworkRevivePlayer() yes Resurrect the local ped where it lies when the player gets up after the coma (or is revived by a doctor): NetworkResurrectLocalPlayer at the current position and heading, restore health and cores, clear tasks and blood. Do not teleport, do not reload the skin. Tell the framework the player is alive if it keeps a flag
FrameworkNotifyLeft(title, message, dict, icon, duration) no Show a notification with the framework's own system, used when Config.NotifyStyle = "framework". dict and icon are a texture dictionary and texture name of the game. Without it, the game's own notification is used

The client adapter must also wire two framework signals:

  1. Character loaded. Each time a character enters the world (first spawn and character switch), fire the local event playerSpawned or murphy_doctor:playerSpawned. The script then confirms with the server that GetCharIdentifier returns a value, loads that character's health and restores a saved coma. On REDEM:RP the character selection already fires playerSpawned; the VORP adapter relays vorp:SelectedCharacter, the RSG one RSGCore:Client:OnPlayerLoaded.

    RegisterNetEvent("myframework:client:characterLoaded")
    AddEventHandler("myframework:client:characterLoaded", function()
        TriggerEvent("playerSpawned")
    end)
    
  2. Revived by something else. When the framework, an admin tool or another script revives the player, close the coma state:

    RegisterNetEvent("myframework:client:revived")
    AddEventHandler("myframework:client:revived", function()
        if IsInComa and IsInComa() then CleanupComaState() end
    end)
    

Globals available to client adapters: Config, dbg(...), L(key, ...), IsInComa(), CleanupComaState(), NativeNotify(title, message, kind, duration). On the server: Config, dbg, L, MySQL (oxmysql) and AuthorizeComaExit(src).

Adapting the script

A fork with the same API under another resource name

If your framework is a fork of a supported one (same functions, but the core resource has another name), keep the existing key and only change names:

  1. Set Config.framework to the matching key ("vorp", "rsg" or "REDEMRP2k23"), so the automatic probe is not needed. Or add your resource name to PROBES in shared/framework.lua, pointing to that key:

    local PROBES = {
        { resource = "redem_roleplay", key = "REDEMRP2k23" },
        { resource = "vorp_core",      key = "vorp" },
        { resource = "my_vorp_fork",   key = "vorp" },
        { resource = "rsg-core",       key = "rsg" },
    }
    
  2. In the adapter of that key, replace the export names (exports.vorp_core, exports.vorp_inventory, exports['rsg-core']...) and any event name that differs.

Keeping an existing key keeps every behaviour tied to it: the startup install check, and the cleanup of deleted characters, which reads the framework's own character table for the three shipped keys (characters.citizenid, characters.charidentifier, players.citizenid).

Another inventory

To use an inventory other than the framework's default one, edit only the inventory functions of your framework's server adapter: GiveItem, RemoveItem, GetItemAmount, GetItemMeta, GetPlayerInventory, FrameworkRegisterUsableItem, FrameworkCloseInventory, getItemLabel, getItemDefs (and FrameworkRefreshInventory if your inventory does not refresh itself). Keep the return formats of the tables above, in particular:

  • GetItemAmount counts every stack, with or without metadata;
  • RemoveItem with a meta table removes from the stack carrying that metadata;
  • the cb of FrameworkRegisterUsableItem receives the metadata of the used stack, which is how a poisoned item is recognised.

Remove the usable item registrations of other scripts for the same item names, or both scripts react to the item.

A new framework

  1. Key. In shared/framework.lua, add your key to ALIASES (lowercase config value to key) and to PROBES (resource to detect, key):

    local ALIASES = {
        -- existing entries...
        ["myframework"] = "myframework",
    }
    local PROBES = {
        -- existing entries...
        { resource = "my_core", key = "myframework" },
    }
    
  2. Files. Copy the pair of adapters closest to your framework, for example server/adapters/VORPAdapter.lua to server/adapters/MyFrameworkAdapter.lua and the same on the client. Change the guard on the first line of each to if Config.FrameworkResolved == "myframework" then.

  3. Functions. Rewrite each function of the contract for your framework's API. Start with the required ones, then the "also called" ones.

  4. Signals. In the client adapter, fire playerSpawned when a character loads and call CleanupComaState() on external revives. In the server adapter, call AuthorizeComaExit on framework revives, and clear identifier caches on character switch.

  5. Death handling. Turn off your framework's own death screen and respawn timer, as for the supported frameworks.

  6. Test. Start the server with Config.framework = "myframework" (or "auto") and run doc_selftest <yourServerId> in the server console. It lists missing adapter functions, tables and item names, and shows your character id and staff status. Then check the startup line Usable items registered ... and try a bandage, a revive and a treatment in game.

With a new key, the startup install check has nothing to test and the cleanup of deleted characters does not run (set Config.CleanDeletedCharacters = false to make that explicit). Everything else works the same.

Skeleton:

lua
-- server/adapters/MyFrameworkAdapter.lua
if Config.FrameworkResolved == "myframework" then
local Core = exports["my_core"]:GetCore() -- your framework's API
local idCache = {}
function GetCharIdentifier(src)
src = tonumber(src)
if not src then return nil end
if idCache[src] then return idCache[src] end
local player = Core.GetPlayer(src)
if player and player.charId then
idCache[src] = tostring(player.charId)
return idCache[src]
end
return nil
end
AddEventHandler("playerDropped", function() idCache[tonumber(source)] = nil end)
function GetCharFirstname(src) local p = Core.GetPlayer(src) return p and p.firstname or "Unknown" end
function GetCharLastname(src) local p = Core.GetPlayer(src) return p and p.lastname or "Unknown" end
function GetCharGroup(src) local p = Core.GetPlayer(src) return p and p.group or nil end
function GetCharJob(src) local p = Core.GetPlayer(src) return p and p.job or nil end
function GetPlayerMoney(src) local p = Core.GetPlayer(src) return p and p.cash or 0 end
function AddMoneyToPlayer(src, amount)
local p = Core.GetPlayer(src)
if not p then return false end
p.addCash(amount)
return true
end
function RemoveMoneyFromPlayer(src, amount)
local p = Core.GetPlayer(src)
if not p or (p.cash or 0) < amount then return false end
p.removeCash(amount)
return true
end
function GiveItem(src, item, amount, meta) return exports["my_inventory"]:AddItem(src, item, amount, meta) end
function RemoveItem(src, item, amount, meta) return exports["my_inventory"]:RemoveItem(src, item, amount, meta) end
function GetItemAmount(src, item) return tonumber(exports["my_inventory"]:Count(src, item)) or 0 end
function GetItemMeta(src, item) local it = exports["my_inventory"]:GetItem(src, item) return it and it.metadata end
function GetPlayerInventory(src)
local out = {}
for _, it in ipairs(exports["my_inventory"]:GetItems(src) or {}) do
if (it.count or 0) > 0 then
out[#out + 1] = { name = it.name, amount = it.count, quantity = it.count, label = it.label,
image = "nui://my_inventory/html/images/" .. it.name .. ".png", metadata = it.metadata or {} }
end
end
return out
end
function getItemLabel(name) return exports["my_inventory"]:GetLabel(name) or tostring(name) end
function getItemDefs() return {} end
function FrameworkRegisterUsableItem(itemName, cb)
exports["my_inventory"]:RegisterUsable(itemName, function(src, it)
cb(src, { name = itemName, meta = it and it.metadata or nil })
end)
end
function FrameworkCloseInventory(src) TriggerClientEvent("my_inventory:close", src) end
end
lua
-- client/adapters/MyFrameworkAdapter.lua
if Config.FrameworkResolved == "myframework" then
function FrameworkRevivePlayer()
local ped = PlayerPedId()
local c = GetEntityCoords(ped)
DoScreenFadeOut(500) Wait(500)
NetworkResurrectLocalPlayer(c.x, c.y, c.z, GetEntityHeading(ped), true, false)
ped = PlayerPedId()
ClearPedTasksImmediately(ped)
ClearPedBloodDamage(ped)
SetEntityHealth(ped, GetEntityMaxHealth(ped))
Wait(500) DoScreenFadeIn(500)
end
RegisterNetEvent("my_core:client:characterLoaded", function() TriggerEvent("playerSpawned") end)
RegisterNetEvent("my_core:client:revived", function()
if IsInComa and IsInComa() then CleanupComaState() end
end)
end

The names my_core, my_inventory and their functions are placeholders: replace them with your framework's real API.

Debug helpers

With Config.Debug = true, these staff commands help test an adapter from the server console (they need a staff group or the console):

Command Effect
doc_giveitem <serverId> <item> [count] [description] Calls GiveItem (with a description metadata when given) and prints the result
doc_itemcount <serverId> <item> Prints GetItemAmount
doc_useitem <serverId> <item> Runs the consumable flow for that item, as if the player used it
doc_frameworkdead <serverId> Prints FrameworkIsDead

doc_selftest is available without Config.Debug.


Last updated: November 20, 2026