Below are practical examples of how to use Glitch Abstraction's most common functions. These examples demonstrate framework-agnostic code that works across ESX, QBCore, and QBox, as well as with suppo
Get the library and wait for it#
The library table is the same on the client and the server. Check IsReady first, then listen for the event. The event fires only once, about a second after the library starts.
local GA = exports['glitch-abstraction']:getAbstraction()
CreateThread(function()
while not GA.IsReady do Wait(100) end
print('framework:', GA.Framework.Type, 'inventory:', GA.Inventory.Type)
end)
AddEventHandler('GlitchAbst:ready', function(ready)
if not ready then return end
-- GA.Framework, GA.Inventory, GA.Target, GA.UI, GA.Notifications, GA.DoorLock, GA.Progression
end)
Declare it in your manifest so the start order is right:
dependency 'glitch-abstraction'
Notifications (client)#
GA.Notifications.Success('Saved', 'Your changes were stored.')
GA.Notifications.Show({ title = 'Heads up', description = 'Something happened.', type = 'info', duration = 6000 })
Input dialog and context menu (client, ox_lib)#
local result = GA.UI.Input('Enter info', {
GA.UI.Inputs.Text('Name', { required = true }),
GA.UI.Inputs.Number('Age', { min = 18, max = 100 }),
})
if result then print(result[1], result[2]) end
GA.UI.RegisterContext({
id = 'example_menu',
title = 'Example menu',
options = {
{ title = 'Option 1', icon = 'star' },
{ title = 'Option 2', icon = 'user' },
},
})
GA.UI.ShowContext('example_menu')
Progress bar (client)#
GA.UI.ProgressBar({ label = 'Working...', duration = 3000, canCancel = true })
Items (server)#
GA.Inventory.AddItem(source, 'bread', 2)
GA.Inventory.RemoveItem(source, 'water', 1)
-- Works on every inventory. The callback receives (source, itemData).
GA.Framework.RegisterUsableItem('lockpick', function(source, item)
TriggerClientEvent('myresource:lockpickUsed', source)
end)
Callbacks#
Same handler shape as QBCore: function(source, respond, ...). Callbacks run on lib.callback, and a handler that never answers is dropped after 15 seconds.
-- server
GA.Framework.RegisterCallback('myresource:getData', function(source, respond, arg)
respond({ foo = 'bar', arg = arg })
end)
-- client
GA.Framework.TriggerCallback('myresource:getData', function(data)
print(data.foo)
end, 'hello')
Money and jobs (server)#
Money helpers accept (source, amount) or (source, account, amount). Amounts must be finite numbers and are rounded down.
GA.Framework.AddMoney(source, 500)
GA.Framework.RemoveMoney(source, 'bank', 250)
local job = GA.Framework.GetJob(source) -- { name, label, grade, grade_name, ... }
Targets (client)#
GA.Target.AddSphereZone('shop', vec3(25.7, -1347.3, 29.5), 1.5, {}, {
{ label = 'Open shop', icon = 'fa-solid fa-store', onSelect = function() end },
})
Zones, global options and hooks added this way are removed automatically when your resource stops.
Inventory hooks (server, ox_inventory)#
local id = GA.Inventory.RegisterHook('swapItems', function(payload)
return true
end)
Door locks (server)#
if not GA.DoorLock.GetDoorState(doorId) then
GA.DoorLock.LockDoor(doorId)
end
XP (server)#
The category name comes second, then the amount.
GA.Progression.AddXP(source, 'mining', 25)
local level = GA.Progression.GetLevel(source, 'mining')
Scaleforms (client)#
GA.Scaleform.ShowMessageBox('Title', 'Subtitle', 'Footer')
Play a cutscene on a player (server, optional tool)#
local ok, message, info = exports['glitch-abstraction']:PlayCutsceneFor(targetId, 'mp_intro_concat', { by = source })