local ESX = exports.esextended:getSharedObject()…
- User
local ESX = exports.es_extended:getSharedObject()
ESX.RegisterServerCallback('mGang:GetAllJobs', function(source, cb) MySQL.Async.fetchAll('SELECT name FROM jobs', {}, function(jobs) local jobList = {} for _, job in ipairs(jobs) do jobList[job.name] = true end cb(jobList) end) end)
ESX.RegisterServerCallback('mGang:GetGangOutfits', function(source, cb, jobName) MySQL.Async.fetchAll('SELECT * FROM gang_outfits WHERE gang = @gang', { ['@gang'] = jobName }, function(outfits) cb(outfits) end) end)
ESX.RegisterServerCallback('mGang:SaveOutfit', function(source, cb, jobName, clothes, outfitName) MySQL.Async.execute('INSERT INTO gang_outfits (gang, outfitName, clothes) VALUES (@gang, @name, @clothes)', { ['@gang'] = jobName, ['@name'] = outfitName, ['@clothes'] = json.encode(clothes) }, function(rowsChanged) cb(rowsChanged > 0) end) end)
ESX.RegisterServerCallback('mGang:UpdateOutfit', function(source, cb, jobName, outfitId, outfitName) MySQL.Async.execute('UPDATE gang_outfits SET outfitName = @name WHERE id = @id AND gang = @gang', { ['@id'] = outfitId, ['@name'] = outfitName, ['@gang'] = jobName }, function(rowsChanged) cb(rowsChanged > 0) end) end)
ESX.RegisterServerCallback('mGang:DeleteOutfit', function(source, cb, jobName, outfitId) MySQL.Async.execute('DELETE FROM gang_outfits WHERE id = @id AND gang = @gang', { ['@id'] = outfitId, ['@gang'] = jobName }, function(rowsChanged) cb(rowsChanged > 0) end) end)
napravi sql
- Assistant
To create the SQL tables you'll need for the provided Lua code, here are the SQL statements that define the structure for the
jobsandgang_outfitstables. This will ensure everything works as expected with the ESX framework in your environment.SQL Table Definitions
1. Create the
jobstableThis table should hold the job names for gangs.
CREATE TABLE IF NOT EXISTS jobs ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255) NOT NULL UNIQUE );2. Create the
gang_outfitstableThis table stores the outfits associated with each gang. It contains fields for the gang name, outfit name, and the clothing data.
CREATE TABLE IF NOT EXISTS gang_outfits ( id INT AUTO_INCREMENT PRIMARY KEY, gang VARCHAR(255) NOT NULL, outfitName VARCHAR(255) NOT NULL, clothes TEXT NOT NULL, FOREIGN KEY (gang) REFERENCES jobs(name) ON DELETE CASCADE );