RedM documentation

Murphy's Craft

Advanced Usage

Exports and Events


Complete documentation of available exports and events to integrate murphy_craft with other scripts.

Table of Contents


Client Exports

OpenCraftMenu(categories?)

Opens the crafting menu.

lua
-- Open with all categories
exports['murphy_craft']:OpenCraftMenu()
-- Open with specific categories
exports['murphy_craft']:OpenCraftMenu({'cuisinier', 'food'})

CloseCraftMenu()

Closes the crafting menu.

lua
exports['murphy_craft']:CloseCraftMenu()

OpenCraftStation(stationIndex)

Opens a crafting station by its config index.

lua
exports['murphy_craft']:OpenCraftStation(1)

Player Data

GetSpecialisationState()

Returns the complete state of player specialisations.

lua
local state = exports['murphy_craft']:GetSpecialisationState()
--[[
Returns:
{
["docteur"] = {
SelectedSpecialisation = true,
AvailablePoints = 3,
TotalPoints = 5,
xp = 150
},
...
}
]]

GetUnlockedRecipes()

Returns all unlocked recipes.

lua
local recipes = exports['murphy_craft']:GetUnlockedRecipes()
--[[
Returns:
{
["docteur"] = {
["root"] = true,
["node1"] = true,
["node2"] = true
},
...
}
]]

HasRecipeUnlocked(category, recipeId)

Checks if a recipe is unlocked.

lua
local unlocked = exports['murphy_craft']:HasRecipeUnlocked('docteur', 'node1')
-- Returns: true/false

GetSpecialisationXP(specialisationId)

Returns the player's XP for a specialisation.

lua
local xp = exports['murphy_craft']:GetSpecialisationXP('docteur')
-- Returns: 150

GetSpecialisationPoints(specialisationId)

Returns available points.

lua
local points = exports['murphy_craft']:GetSpecialisationPoints('docteur')
-- Returns: 3

GetSpecialisationTotalPoints(specialisationId)

Returns total earned points.

lua
local total = exports['murphy_craft']:GetSpecialisationTotalPoints('docteur')
-- Returns: 5

Utilities

GetNearbyCraftingCategories()

Returns accessible categories nearby.

lua
local categories = exports['murphy_craft']:GetNearbyCraftingCategories()
-- Returns: {"cuisinier", "food", "basic"}

GetNearbyCraftingStation(callback)

Checks if the player is near a station.

lua
exports['murphy_craft']:GetNearbyCraftingStation(function(station)
if station then
print("Near station: " .. station.name)
else
print("No station nearby")
end
end)

GetAllCraftCategories()

Returns all available crafting categories.

lua
local categories = exports['murphy_craft']:GetAllCraftCategories()
-- Returns: {"cuisinier", "docteur", "bricoleur", "food", ...}

GetCategoryRecipes(category)

Returns recipes for a category.

lua
local recipes = exports['murphy_craft']:GetCategoryRecipes('food')

RefreshSpecialisationData(callback?)

Reloads specialisation data from the server.

lua
exports['murphy_craft']:RefreshSpecialisationData(function()
print("Data reloaded!")
end)

ClearCraftingData()

Clears crafting data (useful for character switching).

lua
exports['murphy_craft']:ClearCraftingData()

GetLocalSpecialisationProgress(specialisationId)

Returns local progression for a specialisation.

lua
local progress = exports['murphy_craft']:GetLocalSpecialisationProgress('docteur')
--[[
Returns:
{
xp = 150,
level = 3,
totalPoints = 5,
availablePoints = 3
}
]]

Server Exports

Player Data

GetPlayerCraftData(source)

Returns all crafting data for a player.

lua
local data = exports['murphy_craft']:GetPlayerCraftData(source)
--[[
Returns:
{
spestate = { ... },
unlocked_recipes = { ... }
}
]]

GetPlayerSpecialisationXP(source, specialisationId)

Returns a player's XP for a specialisation.

lua
local xp = exports['murphy_craft']:GetPlayerSpecialisationXP(source, 'docteur')

AddPlayerSpecialisationXP(source, specialisationId, amount)

Adds XP to a player.

lua
local success = exports['murphy_craft']:AddPlayerSpecialisationXP(source, 'docteur', 50)

SetPlayerSpecialisationXP(source, specialisationId, amount)

Sets a player's XP.

lua
local success = exports['murphy_craft']:SetPlayerSpecialisationXP(source, 'docteur', 100)

AddPlayerSpecialisationPoints(source, specialisationId, amount)

Adds specialisation points.

lua
local success = exports['murphy_craft']:AddPlayerSpecialisationPoints(source, 'bricoleur', 2)

Recipes

HasPlayerRecipeUnlocked(source, category, recipeId)

Checks if a player has unlocked a recipe.

lua
local unlocked = exports['murphy_craft']:HasPlayerRecipeUnlocked(source, 'docteur', 'node1')

UnlockPlayerRecipe(source, category, recipeId)

Unlocks a recipe for a player.

lua
local success = exports['murphy_craft']:UnlockPlayerRecipe(source, 'docteur', 'node1')

LockPlayerRecipe(source, category, recipeId)

Locks a recipe for a player.

lua
local success = exports['murphy_craft']:LockPlayerRecipe(source, 'docteur', 'node1')

GetPlayerUnlockedRecipes(source, category)

Returns unlocked recipes for a category.

lua
local recipes = exports['murphy_craft']:GetPlayerUnlockedRecipes(source, 'docteur')
-- Returns: {"root", "node1", "node2"}

Stations

GetStationData(uniqueId)

Returns station data.

lua
local data = exports['murphy_craft']:GetStationData('forge_strawberry')

GetAllActiveStations()

Returns all active stations.

lua
local stations = exports['murphy_craft']:GetAllActiveStations()

Utilities

ForceSaveCraftData()

Forces saving all data.

lua
exports['murphy_craft']:ForceSaveCraftData()

GetSpecialisations()

Returns specialisation configuration.

lua
local specialisations = exports['murphy_craft']:GetSpecialisations()

GetCraftCategories()

Returns crafting categories configuration.

lua
local categories = exports['murphy_craft']:GetCraftCategories()

ResetPlayerSpecialisation(source, specialisationId?)

Resets one or all player specialisations.

lua
-- Reset one specialisation
exports['murphy_craft']:ResetPlayerSpecialisation(source, 'docteur')
-- Reset all specialisations
exports['murphy_craft']:ResetPlayerSpecialisation(source, nil)

Specialisation & XP API

Server Events

These events allow manipulating specialisations from other server scripts.

murphy_craft:AddXP

Adds XP and automatically recalculates level.

lua
TriggerEvent('murphy_craft:AddXP', source, 'docteur', 50)

murphy_craft:SetXP

Sets a specialisation's XP.

lua
TriggerEvent('murphy_craft:SetXP', source, 'bricoleur', 100)

murphy_craft:AddPoints

Adds specialisation points.

lua
TriggerEvent('murphy_craft:AddPoints', source, 'cuisinier', 2)

murphy_craft:UnlockRecipe

Unlocks a recipe.

lua
TriggerEvent('murphy_craft:UnlockRecipe', source, 'docteur', 'node1')

murphy_craft:LockRecipe

Locks a recipe.

lua
TriggerEvent('murphy_craft:LockRecipe', source, 'docteur', 'node1')

murphy_craft:ResetSpecialisation

Resets a specialisation.

lua
-- Single one
TriggerEvent('murphy_craft:ResetSpecialisation', source, 'docteur')
-- All
TriggerEvent('murphy_craft:ResetSpecialisation', source, nil)

Specialisation Exports

GetPlayerSpecialisationLevel(source, specialisationId)

Returns current level (calculated from XP).

lua
local level = exports['murphy_craft']:GetPlayerSpecialisationLevel(source, 'docteur')
-- Returns: 3

GetPlayerSpecialisationProgress(source, specialisationId)

Returns complete progression information.

lua
local progress = exports['murphy_craft']:GetPlayerSpecialisationProgress(source, 'docteur')
--[[
Returns:
{
xp = 150,
level = 3,
xpForNextLevel = 50, -- XP remaining for next level
totalXPForNextLevel = 200, -- Total XP required for next level
totalPoints = 5,
availablePoints = 3,
isMaxLevel = false
}
]]

GetPlayerAllSpecialisations(source)

Returns all specialisations with their progression.

lua
local all = exports['murphy_craft']:GetPlayerAllSpecialisations(source)
--[[
Returns:
{
["docteur"] = {
name = "Doctor",
id = "docteur",
progress = { ... },
unlockedRecipes = {"root", "node1"}
},
...
}
]]

IsPlayerMaxLevel(source, specialisationId)

Checks if the player has reached maximum level.

lua
local isMax = exports['murphy_craft']:IsPlayerMaxLevel(source, 'docteur')

GetXPForLevel(specialisationId, level)

Returns XP required to reach a level.

lua
local xpRequired = exports['murphy_craft']:GetXPForLevel('docteur', 5)
-- Returns: 100

GetMaxLevel(specialisationId)

Returns the maximum level for a specialisation.

lua
local maxLevel = exports['murphy_craft']:GetMaxLevel('docteur')
-- Returns: 11

Client Events (Listeners)

These events are triggered client-side to react to changes.

murphy_craft:OnXPGained

Triggered when the player gains XP.

lua
AddEventHandler('murphy_craft:OnXPGained', function(specialisationId, amount, newTotal, pointsGained)
print("+" .. amount .. " XP in " .. specialisationId)
print("Total: " .. newTotal .. " XP")
if pointsGained > 0 then
print("+" .. pointsGained .. " points!")
end
end)

murphy_craft:OnLevelUp

Triggered when the player levels up.

lua
AddEventHandler('murphy_craft:OnLevelUp', function(specialisationId, newLevel, pointsGained, totalPoints)
print("Level up! " .. specialisationId .. " level " .. newLevel)
print("+" .. pointsGained .. " points (total: " .. totalPoints .. ")")
end)

murphy_craft:OnXPSet

Triggered when XP is directly modified.

lua
AddEventHandler('murphy_craft:OnXPSet', function(specialisationId, amount)
print("XP set to " .. amount .. " for " .. specialisationId)
end)

murphy_craft:OnPointsAdded

Triggered when points are added.

lua
AddEventHandler('murphy_craft:OnPointsAdded', function(specialisationId, amount, newAvailable)
print("+" .. amount .. " points for " .. specialisationId)
print("Available points: " .. newAvailable)
end)

murphy_craft:OnRecipeUnlocked

Triggered when a recipe is unlocked.

lua
AddEventHandler('murphy_craft:OnRecipeUnlocked', function(specialisationId, recipeId)
print("Recipe unlocked: " .. recipeId .. " in " .. specialisationId)
end)

murphy_craft:OnRecipeLocked

Triggered when a recipe is locked.

lua
AddEventHandler('murphy_craft:OnRecipeLocked', function(specialisationId, recipeId)
print("Recipe locked: " .. recipeId)
end)

murphy_craft:OnSpecialisationReset

Triggered when a specialisation is reset.

lua
AddEventHandler('murphy_craft:OnSpecialisationReset', function(specialisationId)
print("Specialisation " .. specialisationId .. " reset")
end)

murphy_craft:OnAllSpecialisationsReset

Triggered when all specialisations are reset.

lua
AddEventHandler('murphy_craft:OnAllSpecialisationsReset', function()
print("All specialisations have been reset")
end)

Usage Examples

Give XP when player harvests

lua
-- In a harvesting script (server)
RegisterNetEvent('harvest:onHarvest', function(resourceType)
local source = source
if resourceType == 'herbs' then
TriggerEvent('murphy_craft:AddXP', source, 'docteur', 5)
elseif resourceType == 'ore' then
TriggerEvent('murphy_craft:AddXP', source, 'bricoleur', 10)
end
end)

Check level before an action

lua
-- Server
RegisterNetEvent('myScript:doAdvancedAction', function()
local source = source
local level = exports['murphy_craft']:GetPlayerSpecialisationLevel(source, 'bricoleur')
if level >= 5 then
-- Allow advanced action
TriggerClientEvent('myScript:actionAllowed', source)
else
TriggerClientEvent('myScript:actionDenied', source, 5 - level)
end
end)

Display progression in a menu

lua
-- Client
local function showProgressMenu()
local progress = exports['murphy_craft']:GetLocalSpecialisationProgress('docteur')
local text = string.format(
"Doctor - Level %d\nXP: %d/%d\nAvailable points: %d",
progress.level,
progress.xp,
progress.totalXPForNextLevel or "MAX",
progress.availablePoints
)
-- Display in your menu system
end

Quest reward with recipe unlock

lua
-- Server
RegisterNetEvent('quest:complete', function(questId)
local source = source
if questId == 'doctor_training' then
-- Give XP
TriggerEvent('murphy_craft:AddXP', source, 'docteur', 100)
-- Unlock a special recipe
TriggerEvent('murphy_craft:UnlockRecipe', source, 'docteur', 'special_node')
-- Notify the player
TriggerClientEvent('notify', source, "Quest completed! New recipe unlocked!")
end
end)

Temporary XP bonus system

lua
-- Server
local xpMultipliers = {}
RegisterCommand('xpboost', function(source, args)
local targetId = tonumber(args[1])
local multiplier = tonumber(args[2]) or 2
local duration = tonumber(args[3]) or 3600 -- 1 hour by default
xpMultipliers[targetId] = multiplier
SetTimeout(duration * 1000, function()
xpMultipliers[targetId] = nil
end)
end, true)
-- Hook on XP event to apply multiplier
AddEventHandler('murphy_craft:AddXP', function(source, speId, amount)
if xpMultipliers[source] then
local bonus = amount * (xpMultipliers[source] - 1)
TriggerEvent('murphy_craft:AddXP', source, speId, bonus)
end
end)

Important Notes

  1. Thread Safety: Server exports are thread-safe and can be called from any thread.

  2. Performance: Data is cached server-side. Exports do not make direct SQL queries.

  3. Saving: Modifications are automatically saved according to Config.SaveInterval. Use ForceSaveCraftData() for immediate saving.

  4. Validation: The murphy_craft:RequestAddXP API on client-side is server-validated (max 1000 XP per request) to prevent abuse.

  5. Synchronization: After modifying server data, the client automatically receives update events.


Last updated: January 19, 2026