From f01d89abf2a5dc3315703a5c7002a90b95757a9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20N=27gadi?= Date: Sat, 9 Sep 2017 16:33:23 +0200 Subject: [PATCH] Add per-society garage support --- server/main.lua | 81 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/server/main.lua b/server/main.lua index 9460a9a0..e8e47b71 100644 --- a/server/main.lua +++ b/server/main.lua @@ -3,6 +3,18 @@ Jobs = {} TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) +function stringsplit(inputstr, sep) + if sep == nil then + sep = "%s" + end + local t={} ; i=1 + for str in string.gmatch(inputstr, "([^"..sep.."]+)") do + t[i] = str + i = i + 1 + end + return t +end + AddEventHandler('onMySQLReady', function() local result = MySQL.Sync.fetchAll('SELECT * FROM jobs', {}) @@ -20,6 +32,35 @@ AddEventHandler('onMySQLReady', function() end) +AddEventHandler('esx_society:getSocieties', function(cb) + + MySQL.Async.fetchAll( + 'SELECT * FROM addon_account WHERE name LIKE "%society_%"', + {}, + function(results) + + local societies = {} + + for i=1, #results, 1 do + + local buff = stringsplit(results[i].name, '_') + local society = buff[2] + + table.insert(societies, { + name = society, + label = results[i].label + }) + + end + + cb(societies) + + end + ) + +end) + + RegisterServerEvent('esx_society:withdrawMoney') AddEventHandler('esx_society:withdrawMoney', function(society, amount) @@ -90,6 +131,37 @@ AddEventHandler('esx_society:washMoney', function(society, amount) end) +RegisterServerEvent('esx_society:putVehicleInGarage') +AddEventHandler('esx_society:putVehicleInGarage', function(society, vehicle) + + TriggerEvent('esx_datastore:getSharedDataStore', 'society_' .. society, function(store) + local garage = store.get('garage') or {} + table.insert(garage, vehicle) + store.set('garage', garage) + end) + +end) + +RegisterServerEvent('esx_society:removeVehicleFromGarage') +AddEventHandler('esx_society:removeVehicleFromGarage', function(society, vehicle) + + TriggerEvent('esx_datastore:getSharedDataStore', 'society_' .. society, function(store) + + local garage = store.get('garage') or {} + + for i=1, #garage, 1 do + if garage[i].plate == vehicle.plate then + table.remove(garage, i) + break + end + end + + store.set('garage', garage) + + end) + +end) + ESX.RegisterServerCallback('esx_society:getAccountMoney', function(source, cb, account) TriggerEvent('esx_addonaccount:getSharedAccount', account, function(account) cb(account.money) @@ -232,6 +304,15 @@ ESX.RegisterServerCallback('esx_society:getOnlinePlayers', function(source, cb) end) +ESX.RegisterServerCallback('esx_society:getVehiclesInGarage', function(source, cb, society) + + TriggerEvent('esx_datastore:getSharedDataStore', 'society_' .. society, function(store) + local garage = store.get('garage') or {} + cb(garage) + end) + +end) + function WashMoneyCRON(d, h, m) MySQL.Async.fetchAll(