ESX AI Script Generator
Built for ESX Legacy, with v1-final support on request. Real xPlayer methods, correct event names, and the inventory system your server actually runs.
ESX has real edges we generate for them
ESX looks simple from the outside: get xPlayer, call a method. In practice, the framework has two active versions, a split inventory landscape (ESX-default, ox_inventory, sometimes qs-inventory), and a lot of community patterns that diverge from the docs. A generic AI throws all of this into one bucket and emits code that calls functions which do not exist on your build.
SwisserAI is scoped to your ESX setup. Legacy by default, v1-final when asked. xPlayer signatures match your branch. Inventory calls match your resource. Events match the names your server actually broadcasts.
ESX coverage
xPlayer methods
xPlayer.getMoney, addMoney, removeMoney, getJob, setJob, showNotification called with the right signatures on ESX Legacy.
ESX callbacks and events
ESX.RegisterServerCallback, ESX.TriggerServerCallback, ESX:playerLoaded and the full standard event surface.
Player lookup patterns
ESX.GetPlayerFromId, ESX.GetPlayerFromIdentifier, ESX.GetExtendedPlayers picked based on whether you need by source or identifier.
Job and society accounts
Job grades, salary, duty state, and society money via TriggerEvent("esx_addonaccount:getSharedAccount", ...).
Inventory: ESX-default or ox_inventory
xPlayer.addInventoryItem/removeInventoryItem for ESX-default, exports.ox_inventory calls if your server runs it.
Database with oxmysql or MySQL-Async
Prepared-statement queries on modern oxmysql, or MySQL.Async for older ESX Legacy builds. SwisserAI picks based on your project.
What the output looks like
Snippets a SwisserAI ESX generation would produce on ESX Legacy with ox_inventory.
Server callback
Checks whether a player has enough bank money to buy something.
ESX = exports['es_extended']:getSharedObject()
ESX.RegisterServerCallback('swisser:server:canAfford', function(source, cb, price)
local xPlayer = ESX.GetPlayerFromId(source)
if not xPlayer then return cb(false) end
local bank = xPlayer.getAccount('bank').money
cb(bank >= price)
end)Money + inventory
Removes cash and gives the player an item via ox_inventory on ESX.
RegisterNetEvent('swisser:server:buyRadio', function()
local src = source
local xPlayer = ESX.GetPlayerFromId(src)
if not xPlayer then return end
local price = 2500
if xPlayer.getMoney() < price then
xPlayer.showNotification('Not enough cash')
return
end
xPlayer.removeMoney(price, 'radio-purchase')
exports.ox_inventory:AddItem(src, 'radio', 1)
xPlayer.showNotification('Radio acquired')
end)Job-gated command
Restricts a command to the police job using xPlayer.getJob().
RegisterCommand('clockin', function(source)
local xPlayer = ESX.GetPlayerFromId(source)
if not xPlayer then return end
if xPlayer.getJob().name ~= 'police' then
xPlayer.showNotification('You are not on the force')
return
end
TriggerClientEvent('swisser:client:onDuty', source, true)
xPlayer.showNotification('You are now on duty')
end, false)Society account deposit
Adds $500 to the mechanic society via esx_addonaccount.
TriggerEvent('esx_addonaccount:getSharedAccount', 'society_mechanic', function(account)
if not account then return end
account.addMoney(500)
end)ESX vs QBCore vs Qbox quick guide
Same task, three frameworks. Used to decide where to start new servers.
| Task | ESX Legacy | QBCore | Qbox |
|---|---|---|---|
| Get player | ESX.GetPlayerFromId(src) | QBCore.Functions.GetPlayer(src) | exports.qbx_core:GetPlayer(src) |
| Remove money | xPlayer.removeMoney(500) | Player.Functions.RemoveMoney('cash', 500) | exports.qbx_core:RemoveMoney(src, 'cash', 500) |
| Server callback | ESX.RegisterServerCallback | QBCore.Functions.CreateCallback | lib.callback.register |
| Notify | xPlayer.showNotification | QBCore:Notify event | lib.notify |
Common ESX AI mistakes we prevent
Patterns generic models keep producing in ESX resources.
Mixing QBCore syntax
QBCore.Functions.GetPlayer inside an ESX resource is the classic broken AI output. SwisserAI stays in the ESX lane when you generate ESX.
Wrong money accounts
xPlayer.addMoney() when you meant xPlayer.addAccountMoney("bank", ...) they behave differently. We emit the right account call.
ESX vs ESX Legacy drift
Older ESX builds used getPlayerFromId differently and had no ox_inventory bridge. We scope to Legacy by default and support older builds on request.
Forgetting ESX = nil initialization
Resources that forget the local ESX handle assignment fail silently at startup. SwisserAI includes the correct initialization for your chosen ESX version.
Frequently Asked Questions
Generate ESX resources that actually run
250 free credits to start. No card. Pick ESX, describe the resource, ship it.