323 lines
		
	
	
		
			No EOL
		
	
	
		
			11 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
			
		
		
	
	
			323 lines
		
	
	
		
			No EOL
		
	
	
		
			11 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
| RandomString = function(length, strType)
 | |
|     local characters = ""
 | |
| 
 | |
|     if strType == "A" then
 | |
|         characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
 | |
|     elseif strType == "1" then
 | |
|         characters = "0123456789"
 | |
|     else
 | |
|         return nil
 | |
|     end
 | |
| 
 | |
|     local result = ""
 | |
|     for i = 1, length do
 | |
|         local randomIndex = math.random(1, #characters)
 | |
|         result = result .. characters:sub(randomIndex, randomIndex)
 | |
|     end
 | |
| 
 | |
|     return result
 | |
| end
 | |
| 
 | |
| ExecuteSql = function(query, parameters, cb)
 | |
|     local promise = promise:new()
 | |
|     while isBusy do
 | |
|         Citizen.Wait(0)
 | |
|     end
 | |
|     local isBusy = true
 | |
|     if GetResourceState("oxmysql") == 'started' then
 | |
|         exports.oxmysql:execute(query, parameters, function(data)
 | |
|             promise:resolve(data)
 | |
|             isBusy = false
 | |
| 
 | |
|             if cb then
 | |
|                 cb(data)
 | |
|             end
 | |
|         end)
 | |
|     elseif GetResourceState("ghmattimysql") == 'started' then
 | |
|         exports.ghmattimysql:execute(query, parameters, function(data)
 | |
|             promise:resolve(data)
 | |
|             isBusy = false
 | |
| 
 | |
|             if cb then
 | |
|                 cb(data)
 | |
|             end
 | |
|         end)
 | |
|     elseif GetResourceState("mysql-async") == 'started' then
 | |
|         MySQL.Async.fetchAll(query, parameters, function(data)
 | |
|             promise:resolve(data)
 | |
|             isBusy = false
 | |
|             if cb then
 | |
|                 cb(data)
 | |
|             end
 | |
|         end)
 | |
|     end
 | |
|     return Citizen.Await(promise)
 | |
| end
 | |
| 
 | |
| CheckMoney = function(xPlayer, targetPrice)
 | |
|     if CoreName == 'qb-core' then
 | |
|         if xPlayer.PlayerData.money.cash >= targetPrice then
 | |
|             return true
 | |
|         elseif xPlayer.PlayerData.money.bank >= targetPrice then
 | |
|             return true
 | |
|         else
 | |
|             return false
 | |
|         end
 | |
|     elseif CoreName == 'qbx_core' then
 | |
|         if xPlayer.PlayerData.money.cash >= targetPrice then
 | |
|             return true
 | |
|         elseif xPlayer.PlayerData.money.bank >= targetPrice then
 | |
|             return true
 | |
|         else
 | |
|             return false
 | |
|         end
 | |
|     elseif CoreName == 'es_extended' then
 | |
|         if xPlayer.getMoney() >= targetPrice then
 | |
|             return true
 | |
|         elseif xPlayer.getAccount('bank').money >= targetPrice then
 | |
|             return true
 | |
|         else
 | |
|             return false
 | |
|         end
 | |
|     end
 | |
| end
 | |
| 
 | |
| RemoveMoney = function(xPlayer, targetPrice)
 | |
|     if CoreName == 'qb-core' then
 | |
|         if xPlayer.PlayerData.money.cash >= targetPrice then
 | |
|             xPlayer.Functions.RemoveMoney('cash', targetPrice, '0r-rccar:server:buyCar')
 | |
|             return true
 | |
|         elseif xPlayer.PlayerData.money.bank >= targetPrice then
 | |
|             xPlayer.Functions.RemoveMoney('bank', targetPrice, '0r-rccar:server:buyCar')
 | |
|             return true
 | |
|         end
 | |
|     elseif CoreName == 'qbx_core' then
 | |
|         if xPlayer.PlayerData.money.cash >= targetPrice then
 | |
|             exports.qbx_core:RemoveMoney(xPlayer.PlayerData.citizenid, 'cash', targetPrice, '0r-rccar:server:buyCar')
 | |
|             return true
 | |
|         elseif xPlayer.PlayerData.money.bank >= targetPrice then
 | |
|             exports.qbx_core:RemoveMoney(xPlayer.PlayerData.citizenid, 'bank', targetPrice, '0r-rccar:server:buyCar')
 | |
|             return true
 | |
|         end
 | |
|     elseif CoreName == 'es_extended' then
 | |
|         if xPlayer.getMoney() >= targetPrice then
 | |
|             xPlayer.removeMoney(targetPrice)
 | |
|             return true
 | |
|         elseif xPlayer.getAccount('bank').money >= targetPrice then
 | |
|             xPlayer.removeAccountMoney('bank', targetPrice)
 | |
|             return true
 | |
|         end
 | |
|     end
 | |
| 
 | |
|     return false
 | |
| end
 | |
| 
 | |
| GetItem = function(source, item, metadata)
 | |
|     if Config.Inventory == 'qb-inventory' or Config.Inventory == 'lj-inventory' or Config.Inventory == 'ps-inventory' or Config.Inventory == 'tgiann-inventory' or Config.Inventory == 'codem-inventory' then
 | |
|         local items = exports[Config.Inventory]:GetItemsByName(source, item)
 | |
| 
 | |
|         local itemData = {}
 | |
| 
 | |
|         if #items > 0 then
 | |
|             for _, item in ipairs(items) do
 | |
|                 table.insert(itemData, item)
 | |
|             end
 | |
|         else
 | |
|             return nil
 | |
|         end
 | |
| 
 | |
|         if itemData then
 | |
|             return itemData
 | |
|         else
 | |
|             return nil
 | |
|         end
 | |
|     elseif Config.Inventory == 'ox_inventory' then
 | |
|         local itemData = exports.ox_inventory:GetItem(source, item, metadata, false)
 | |
| 
 | |
|         if itemData then
 | |
|             return itemData
 | |
|         else
 | |
|             return nil
 | |
|         end
 | |
|     end
 | |
| end
 | |
| 
 | |
| AddItem = function(src, item, count, slot, metadata)
 | |
|     if type(item) == 'table' then
 | |
|         for _, v in pairs(item) do
 | |
|             if Config.Inventory == 'qb-inventory' or Config.Inventory == 'lj-inventory' or Config.Inventory == 'ps-inventory' or Config.Inventory == 'tgiann-inventory' or Config.Inventory == 'codem-inventory' then
 | |
|                 exports[Config.Inventory]:AddItem(src, _, v, slot, metadata)
 | |
|             elseif Config.Inventory == 'ox_inventory' then
 | |
|                 exports.ox_inventory:AddItem(src, _, v, metadata, slot)
 | |
|             end
 | |
|         end
 | |
| 
 | |
|         return true
 | |
|     else
 | |
|         if Config.Inventory == 'qb-inventory' or Config.Inventory == 'lj-inventory' or Config.Inventory == 'ps-inventory' or Config.Inventory == 'tgiann-inventory' or Config.Inventory == 'codem-inventory' then
 | |
|             exports[Config.Inventory]:AddItem(src, item, count, slot, metadata)
 | |
|             return true
 | |
|         elseif Config.Inventory == 'ox_inventory' then
 | |
|             exports.ox_inventory:AddItem(src, item, count, metadata, slot)
 | |
|             return true
 | |
|         end
 | |
|     end
 | |
| end
 | |
| 
 | |
| CreateNewVehicle = function(source, item, count)
 | |
|     local function generateSerie()
 | |
|         return RandomString(2, '1') .. RandomString(3, 'A') .. RandomString(1, '1') .. RandomString(2, 'A') .. RandomString(3, '1') .. RandomString(4, 'A')
 | |
|     end
 | |
| 
 | |
|     if count > 1 then
 | |
|         for i = 1, count do
 | |
|             local info = {
 | |
|                 serie = generateSerie()
 | |
|             }
 | |
|             local success = AddItem(source, item, count, nil, info)
 | |
|     
 | |
|             if success then
 | |
|                 ExecuteSql("INSERT INTO 0r_rccar (serieNumber, battery) VALUES ('" .. info.serie .. "', 100)")
 | |
|             else
 | |
|                 return false
 | |
|             end
 | |
|         end
 | |
|         
 | |
|         return true
 | |
|     else
 | |
|         local info = {
 | |
|             serie = generateSerie()
 | |
|         }
 | |
|         local success = AddItem(source, item, count, nil, info)
 | |
| 
 | |
|         if success then
 | |
|             ExecuteSql("INSERT INTO 0r_rccar (serieNumber, battery) VALUES ('" .. info.serie .. "', 100)")
 | |
|             return true
 | |
|         else
 | |
|             return false
 | |
|         end
 | |
|     end
 | |
| 
 | |
| end
 | |
| 
 | |
| exports('CreateNewVehicle', CreateNewVehicle)
 | |
| 
 | |
| RemoveItem = function(src, item, count, slot)
 | |
|     if type(item) == 'table' then
 | |
|         for _, v in pairs(item) do
 | |
|             if Config.Inventory == 'qb-inventory' or Config.Inventory == 'lj-inventory' or Config.Inventory == 'ps-inventory' or Config.Inventory == 'tgiann-inventory' then
 | |
|                 if not exports[Config.Inventory]:HasItem(src, _, v) then
 | |
|                     return false
 | |
|                 end
 | |
|                 exports[Config.Inventory]:RemoveItem(src, _, v)
 | |
|             elseif Config.Inventory == 'ox_inventory' then
 | |
|                 if not exports.ox_inventory:GetItem(src, _, v) then
 | |
|                     return false
 | |
|                 end
 | |
|                 exports.ox_inventory:RemoveItem(src, _, v)
 | |
|             elseif Config.Inventory == 'codem-inventory' then
 | |
|                 if not exports[Config.Inventory]:HasItem(src, _, v) then
 | |
|                     return false
 | |
|                 end
 | |
|                 exports[Config.Inventory]:RemoveItem(src, _, v)
 | |
|             end
 | |
|         end
 | |
|         return true
 | |
|     else
 | |
|         if Config.Inventory == 'qb-inventory' or Config.Inventory == 'lj-inventory' or Config.Inventory == 'ps-inventory' or Config.Inventory == 'tgiann-inventory' then
 | |
|             if exports[Config.Inventory]:HasItem(src, item, count) then
 | |
|                 exports[Config.Inventory]:RemoveItem(src, item, count, slot)
 | |
|                 return true
 | |
|             else
 | |
|                 return false
 | |
|             end
 | |
|         elseif Config.Inventory == 'ox_inventory' then
 | |
|             if exports.ox_inventory:GetItem(src, item, count) then
 | |
|                 exports.ox_inventory:RemoveItem(src, item, count, nil, slot)
 | |
|                 return true
 | |
|             else
 | |
|                 return false
 | |
|             end
 | |
|         elseif Config.Inventory == 'codem-inventory' then
 | |
|             if exports[Config.Inventory]:GetItem(src, item) then
 | |
|                 exports[Config.Inventory]:RemoveItem(src, item, count, slot)
 | |
|                 return true
 | |
|             else
 | |
|                 return false
 | |
|             end
 | |
|         end
 | |
|     end
 | |
| end
 | |
| 
 | |
| GetItemCount = function(source, itemName, targetCount)
 | |
|     if Config.Inventory == 'qb-inventory' or Config.Inventory == 'lj-inventory' or Config.Inventory == 'ps-inventory' or Config.Inventory == 'tgiann-inventory' or Config.Inventory == 'ox_inventory' then
 | |
|         local itemCount = exports[Config.Inventory]:GetItemCount(source, itemName)
 | |
|         if itemCount and itemCount > 0 and itemCount >= targetCount then
 | |
|             return true
 | |
|         else
 | |
|             return false
 | |
|         end
 | |
|     elseif Config.Inventory == 'codem-inventory' then
 | |
|         local itemCount = exports['codem-inventory']:GetItemsTotalAmount(source, itemName)
 | |
| 
 | |
|         if itemCount and itemCount > 0 and itemCount > targetCount then
 | |
|             return true
 | |
|         else
 | |
|             return false
 | |
|         end
 | |
|     end
 | |
| end
 | |
| 
 | |
| GetItemsCount = function(source, itemData, targetCount)
 | |
|     if Config.Inventory == 'qb-inventory' or Config.Inventory == 'lj-inventory' or Config.Inventory == 'ps-inventory' or Config.Inventory == 'tgiann-inventory' or Config.Inventory == 'ox_inventory' then
 | |
|         for k, v in pairs(itemData) do
 | |
|             local itemCount = exports[Config.Inventory]:GetItemCount(source, k)
 | |
|             if not itemCount and not itemCount > 0 and not itemCount >= v then
 | |
|                 return false
 | |
|             end
 | |
|         end
 | |
| 
 | |
|         return true
 | |
|     elseif Config.Inventory == 'codem-inventory' then
 | |
|         for k, v in pairs(itemData) do
 | |
|             local itemCount = exports['codem-inventory']:GetItemsTotalAmount(source, k)
 | |
|             if not itemCount and not itemCount > 0 and not itemCount >= v then
 | |
|                 return false
 | |
|             end
 | |
|         end
 | |
| 
 | |
|         return true
 | |
|     end
 | |
| end
 | |
| 
 | |
| GetItemByName = function(src, item, info)
 | |
|     if Config.Inventory == 'qb-inventory' or Config.Inventory == 'lj-inventory' or Config.Inventory == 'ps-inventory' or Config.Inventory == 'tgiann-inventory' or  Config.Inventory == 'codem-inventory' then
 | |
|         local itemData = exports[Config.Inventory]:GetItemByName(src, item)
 | |
| 
 | |
|         if itemData then
 | |
|             return itemData
 | |
|         else
 | |
|             return nil
 | |
|         end
 | |
|     elseif Config.Inventory == 'ox_inventory' then
 | |
|         local itemData = exports.ox_inventory:GetItem(src, item, info)
 | |
| 
 | |
|         if itemData then
 | |
|             return itemData
 | |
|         else
 | |
|             return nil
 | |
|         end
 | |
|     end
 | |
| end
 | |
| 
 | |
| GetItemsByName = function(src, name)
 | |
|     if Config.Inventory == 'qb-inventory' or Config.Inventory == 'lj-inventory' or Config.Inventory == 'ps-inventory' or Config.Inventory == 'tgiann-inventory' or Config.Inventory == 'codem-inventory' then
 | |
|         local item = exports[Config.Inventory]:GetItemsByName(src, name)
 | |
| 
 | |
|         if item then
 | |
|             return item
 | |
|         else
 | |
|             return nil
 | |
|         end
 | |
|     end
 | |
| end | 
