Files
esx_core/mysql-async/lib/MySQL.lua
T
EbenSantuy 5b591a94b5 This I made for people who cant configure the esx_kashacters and to fix all the issue ! thanks to KASH to make this nice Feature
Thanks You KASH (github.com/KASHZIN)Who The Original Develop This ESX_KASHACTERS RELEASE And To for the tutorial XxFri3ndlyxX (github.com/XxFri3ndlyxX)

this tutorial i made little bit use XxFri3ndlyxX tutorial

1.Step One [ essentialmode\client\main.lua ]

Delete Or Replace This !
--[[Citizen.CreateThread(function()
	while true do
		Citizen.Wait(0)

		if NetworkIsSessionStarted() then
			TriggerServerEvent('es:firstJoinProper')
			TriggerEvent('es:allowedToSpawn')
			return
		end
	end
end)]]--

2.Step Two [ es_extended [ LINE : 457 ] client/main.lua ]
This To Fix Cant Open Inventory When You Die And Get Revived

Change You Menu interactions to this !
``` ---Menu interactions
Citizen.CreateThread(function()
	while true do
		
		Citizen.Wait(0)

		if IsControlJustReleased(0, 289) and IsInputDisabled(0) and not ESX.UI.Menu.IsOpen('default', 'es_extended', 'inventory') then
			ESX.ShowInventory()
		end

	end
end)```

3. Step Three 
To Get Your esx_kashacters work you need do this on your database

SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME = 'owner'
And This
SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME = 'indentifier'
Credit @Xnubil

6. Step Six [Fix Datastore]
Duplicate Your esx_datastore or add This line on your esx_datastore server\main.lua

-- Fix was taken from this link --
-- https://forum.fivem.net/t/release-esx-kashacters-multi-character/251613/448?u=xxfri3ndlyxx --
AddEventHandler('esx:playerLoaded', function(source)

  local result = MySQL.Sync.fetchAll('SELECT * FROM datastore')

	for i=1, #result, 1 do
		local name   = result[i].name
		local label  = result[i].label
		local shared = result[i].shared

		local result2 = MySQL.Sync.fetchAll('SELECT * FROM datastore_data WHERE name = @name', {
			['@name'] = name
		})

		if shared == 0 then

			table.insert(DataStoresIndex, name)
			DataStores[name] = {}

			for j=1, #result2, 1 do
				local storeName  = result2[j].name
				local storeOwner = result2[j].owner
				local storeData  = (result2[j].data == nil and {} or json.decode(result2[j].data))
				local dataStore  = CreateDataStore(storeName, storeOwner, storeData)

				table.insert(DataStores[name], dataStore)
			end
		end
	end

	local _source = source
	local xPlayer = ESX.GetPlayerFromId(_source)
  	local dataStores = {}
  
	for i=1, #DataStoresIndex, 1 do
		local name      = DataStoresIndex[i]
		local dataStore = GetDataStore(name, xPlayer.identifier)

		if dataStore == nil then
			MySQL.Async.execute('INSERT INTO datastore_data (name, owner, data) VALUES (@name, @owner, @data)',
			{
				['@name']  = name,
				['@owner'] = xPlayer.identifier,
				['@data']  = '{}'
			})

			dataStore = CreateDataStore(name, xPlayer.identifier, {})
			table.insert(DataStores[name], dataStore)
		end

		table.insert(dataStores, dataStore)
	end

	xPlayer.set('dataStores', dataStores)
end)

Download Link : https://github.com/XxFri3ndlyxX/esx_datastore
Credits : https://github.com/XxFri3ndlyxX

5. Step Five [ Fix Ambulance ]
This To Fix Die Tele And When Your Get Revived You Cant Open any Menu only F2

Download My File the esx_ambulancejob (or download the lastest version esx_ambulancejob :v)

6. Step Six [ Fix your esx_kashacters identifier ]
Download My mysql-async And start on your server.cfg

7. Step Seven [ Fix Your Identifier And Spawn] 
Download My esx_kashacters Modified And start on your server.cfg
Thats All Identifier [esx_kashacters\server\main.lua] maybe thats all
you need in Roleplay Server if you wan to change just change it 

===--------------------------------------------------------------------===

Okey Thats All Make My esx_kashacters work properly if you wanna ask
My Discord : Blue.#5108

Thank you Again to KASH And XxFri3ndlyxX ! :)
ENJOY YOUR ESX_KASHACTERS
2019-07-17 15:26:07 +07:00

213 lines
5.3 KiB
Lua

MySQL = {
Async = {},
Sync = {},
Threaded = {} -- remove in the next big version
}
local function safeParameters(params)
if nil == params then
return {[''] = ''}
end
assert(type(params) == "table", "A table is expected")
assert(params[1] == nil, "Parameters should not be an array, but a map (key / value pair) instead")
if next(params) == nil then
return {[''] = ''}
end
return params
end
---
-- Execute a query with no result required, sync version
--
-- @param query
-- @param params
--
-- @return int Number of rows updated
--
function MySQL.Sync.execute(query, params)
assert(type(query) == "string", "The SQL Query must be a string")
local res = 0
local finishedQuery = false
exports['mysql-async']:mysql_execute(query, safeParameters(params), function (result)
res = result
finishedQuery = true
end)
repeat Citizen.Wait(0) until finishedQuery == true
return res
end
---
-- Execute a query and fetch all results in an sync way
--
-- @param query
-- @param params
--
-- @return table Query results
--
function MySQL.Sync.fetchAll(query, params)
assert(type(query) == "string", "The SQL Query must be a string")
local res = {}
local finishedQuery = false
exports['mysql-async']:mysql_fetch_all(query, safeParameters(params), function (result)
res = result
finishedQuery = true
end)
repeat Citizen.Wait(0) until finishedQuery == true
return res
end
---
-- Execute a query and fetch the first column of the first row, sync version
-- Useful for count function by example
--
-- @param query
-- @param params
--
-- @return mixed Value of the first column in the first row
--
function MySQL.Sync.fetchScalar(query, params)
assert(type(query) == "string", "The SQL Query must be a string")
local res = ''
local finishedQuery = false
exports['mysql-async']:mysql_fetch_scalar(query, safeParameters(params), function (result)
res = result
finishedQuery = true
end)
repeat Citizen.Wait(0) until finishedQuery == true
return res
end
---
-- Execute a query and retrieve the last id insert, sync version
--
-- @param query
-- @param params
--
-- @return mixed Value of the last insert id
--
function MySQL.Sync.insert(query, params)
assert(type(query) == "string", "The SQL Query must be a string")
local res = 0
local finishedQuery = false
exports['mysql-async']:mysql_insert(query, safeParameters(params), function (result)
res = result
finishedQuery = true
end)
repeat Citizen.Wait(0) until finishedQuery == true
return res
end
---
-- Execute a List of querys and returns bool true when all are executed successfully
--
-- @param querys
-- @param params
--
-- @return bool if the transaction was successful
--
--function MySQL.Sync.transaction(querys, params)
-- assert(type(querys) == "table", "The SQL Query must be a table of strings")
--
-- return exports['mysql-async']:mysql_sync_transaction(querys, safeParameters(params))
--end
---
-- Execute a query with no result required, async version
--
-- @param query
-- @param params
-- @param func(int)
--
function MySQL.Async.execute(query, params, func)
assert(type(query) == "string", "The SQL Query must be a string")
exports['mysql-async']:mysql_execute(query, safeParameters(params), func)
end
---
-- Execute a query and fetch all results in an async way
--
-- @param query
-- @param params
-- @param func(table)
--
function MySQL.Async.fetchAll(query, params, func)
assert(type(query) == "string", "The SQL Query must be a string")
exports['mysql-async']:mysql_fetch_all(query, safeParameters(params), func)
end
---
-- Execute a query and fetch the first column of the first row, async version
-- Useful for count function by example
--
-- @param query
-- @param params
-- @param func(mixed)
--
function MySQL.Async.fetchScalar(query, params, func)
assert(type(query) == "string", "The SQL Query must be a string")
exports['mysql-async']:mysql_fetch_scalar(query, safeParameters(params), func)
end
---
-- Execute a query and retrieve the last id insert, async version
--
-- @param query
-- @param params
-- @param func(string)
--
function MySQL.Async.insert(query, params, func)
assert(type(query) == "string", "The SQL Query must be a string")
exports['mysql-async']:mysql_insert(query, safeParameters(params), func)
end
---
-- Execute a List of querys and returns bool true when all are executed successfully
--
-- @param querys
-- @param params
-- @param func(bool)
--
--function MySQL.Async.transaction(querys, params, func)
-- assert(type(querys) == "table", "The SQL Query must be a table of strings")
--
-- return exports['mysql-async']:mysql_transaction(querys, safeParameters(params), func)
--end
--
-- Remove in the next big update
--
MySQL.Threaded.execute = MySQL.Sync.execute
MySQL.Threaded.fetchAll = MySQL.Sync.fetchAll
MySQL.Threaded.fetchScalar = MySQL.Sync.fetchScalar
MySQL.Threaded.insert = MySQL.Sync.insert
local isReady = false
local callbackDictionary = {}
AddEventHandler('MySQLReady', function ()
isReady = true
for i, cb in ipairs(callbackDictionary) do
callbackDictionary[i] = nil
cb()
end
end)
function MySQL.ready (callback)
if isReady then
callback()
else
table.insert(callbackDictionary, callback)
end
end