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)| Hook | Data |
|---|---|
addMoney, removeMoney, setMoney | source, account, amount, reason |
setJob, setGang | source, job/gang, grade, oldJob/oldGang, oldGrade |
setDuty | source, onDuty |
addItem, removeItem | source, item, count, metadata (, slot) |
useItem, giveItem, giveMoney | source, item/target… |
createCharacter, selectCharacter, deleteCharacter | identity or charId |
spawn | source, charId, position, model, firstSpawn (changeable: position, model) |
paycheck | source, account, amount, job, grade |
respawn | source, position |
playerConnecting | lsmpId, name, guest (blocking = refusing the player) |
addLicense, removeLicense | source, license |
addWeapon, removeWeapon | source, weapon (, ammo) |
addVehicle, spawnVehicle | citizenid, model, plate… |
addSocietyMoney, removeSocietyMoney, setSocietyMoney | society, amount, reason |
openStash | source, stash, label (blocking = closed stash: locks, keys…) |
stashDeposit, stashTake | source, stash, item, count (changeable: count) |
jobAction | source, action, target (F6 menu action) |
target | source, option, info (targeting option) |
craft | source, recipe, count, bench |
equipWeapon | source, item, serial, slot |
dropItem | source, item, count, slot |
sleeper | source, citizenid, coords (false: no character asleep) |
vehicleRestore | plate, 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).