Skip to content

Reference

Hooks ​

A hook runs before the action. It can let it happen (return nothing), block it (return false, "reason") or change it (return the modified table).

lua
RLX.AddHook("addMoney", function(data)
  if data.account == "black_money" and data.amount > 50000 then return false, "limit reached" end
end)

RLX.AddHook("paycheck", function(data)   -- double pay on weekends
  local d = os.date("*t")
  if d.wday == 1 or d.wday == 7 then data.amount = data.amount * 2; return data end
end)

RLX.AddHook("spawn", function(data)      -- spawn in their apartment
  if data.firstSpawn then data.position = { x = -269.4, y = -955.3, z = 31.2, heading = 205.0 }; return data end
end)
HookData
addMoney, removeMoney, setMoneysource, account, amount, reason
setJob, setGangsource, job/gang, grade, oldJob/oldGang, oldGrade
setDutysource, onDuty
addItem, removeItemsource, item, count, metadata (, slot)
useItem, giveItem, giveMoneysource, item/target…
createCharacter, selectCharacter, deleteCharacteridentity or charId
spawnsource, charId, position, model, firstSpawn (changeable: position, model)
paychecksource, account, amount, job, grade
respawnsource, position
playerConnectinglsmpId, name, guest (blocking = refusing the player)
addLicense, removeLicensesource, license
addWeapon, removeWeaponsource, weapon (, ammo)
addVehicle, spawnVehiclecitizenid, model, plate…
addSocietyMoney, removeSocietyMoney, setSocietyMoneysociety, amount, reason
openStashsource, stash, label (blocking = closed stash: locks, keys…)
stashDeposit, stashTakesource, stash, item, count (changeable: count)
jobActionsource, action, target (F6 menu action)
targetsource, option, info (targeting option)
craftsource, recipe, count, bench
equipWeaponsource, item, serial, slot
dropItemsource, item, count, slot
sleepersource, citizenid, coords (false: no character asleep)
vehicleRestoreplate, citizenid, model, place (false: not put back)

Your own hooks: any name with : is free. Your resource runs the hook, the others intercept it:

lua
-- garage resource
local data, why = RLX.RunHook("garage:takeOut", { source = source, plate = plate, price = 100 })
if not data then return xPlayer.showNotification(why or "Not possible", "error") end
-- another resource
RLX.AddHook("garage:takeOut", function(d) if d.plate:sub(1, 3) == "VIP" then d.price = 0; return d end end)

Rules: a hook must not wait (no lsmp.wait, no database). It is served during the action. Hooks are for Lua resources (the console shows synchronous bridge OK at start).