mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-09-04 16:23:21 +00:00
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
This commit is contained in:
@@ -0,0 +1,139 @@
|
||||
const mysql = require('mysql');
|
||||
|
||||
let config = {};
|
||||
let debug = 0;
|
||||
let pool;
|
||||
|
||||
function prepareQuery(query, parameters) {
|
||||
let sql = query;
|
||||
if (parameters !== null && typeof parameters === 'object') {
|
||||
sql = query.replace(/@(\w+)/g, (txt, key) => {
|
||||
if (parameters.hasOwnProperty(key)) {
|
||||
return mysql.escape(parameters[key]);
|
||||
} else if (parameters.hasOwnProperty(`@${key}`)) {
|
||||
return mysql.escape(parameters[`@${key}`]);
|
||||
}
|
||||
return txt;
|
||||
});
|
||||
}
|
||||
return sql;
|
||||
}
|
||||
|
||||
function writeDebug(time, sql, error) {
|
||||
if (error) console.log(`[ERROR] [MySQL] An error happens on MySQL for query "${sql}": ${error.message}`)
|
||||
if (debug) console.log(`[MySQL] [${(time[0]*1e3+time[1]*1e-6).toFixed()}ms] ${sql}`);
|
||||
}
|
||||
|
||||
async function safeInvoke(callback, args) {
|
||||
if (typeof callback === 'function') setImmediate(() => {
|
||||
callback(args);
|
||||
});
|
||||
}
|
||||
|
||||
// transform tinyint(1) to boolean
|
||||
function useBoolean(fields, results) {
|
||||
if (fields) {
|
||||
fields.forEach(field => {
|
||||
// found a column with tinyint(1)
|
||||
if (field.type === 1 && field.length === 1) {
|
||||
results.forEach((_, index) => {
|
||||
results[index][field.name] = (results[index][field.name] !== 0);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
global.exports('mysql_execute', (query, parameters, callback) => {
|
||||
let sql = prepareQuery(query, parameters);
|
||||
let start = process.hrtime();
|
||||
pool.query(sql, (error, results) => {
|
||||
writeDebug(process.hrtime(start), sql, error);
|
||||
safeInvoke(callback, (results) ? results.affectedRows : 0);
|
||||
});
|
||||
});
|
||||
|
||||
global.exports('mysql_fetch_all', (query, parameters, callback) => {
|
||||
let sql = prepareQuery(query, parameters);
|
||||
let start = process.hrtime();
|
||||
pool.query(sql, (error, results, fields) => {
|
||||
writeDebug(process.hrtime(start), sql, error);
|
||||
results = useBoolean(fields, results);
|
||||
safeInvoke(callback, results);
|
||||
});
|
||||
});
|
||||
|
||||
global.exports('mysql_fetch_scalar', (query, parameters, callback) => {
|
||||
let sql = prepareQuery(query, parameters);
|
||||
let start = process.hrtime();
|
||||
pool.query(sql, (error, results, fields) => {
|
||||
writeDebug(process.hrtime(start), sql, error);
|
||||
results = useBoolean(fields, results);
|
||||
safeInvoke(callback, (results) ? Object.values(results[0])[0] : null);
|
||||
});
|
||||
});
|
||||
|
||||
global.exports('mysql_insert', (query, parameters, callback) => {
|
||||
let sql = prepareQuery(query, parameters);
|
||||
let start = process.hrtime();
|
||||
pool.query(sql, (error, results) => {
|
||||
writeDebug(process.hrtime(start), sql, error);
|
||||
safeInvoke(callback, (results) ? results.insertId : 0);
|
||||
});
|
||||
});
|
||||
|
||||
function parseOptions(config, options) {
|
||||
const cfg = config;
|
||||
const opts = options.split('&');
|
||||
opts.forEach((o) => {
|
||||
const keyValue = o.split('=');
|
||||
cfg[keyValue[0]] = keyValue[1];
|
||||
});
|
||||
return cfg;
|
||||
}
|
||||
|
||||
function parseConnectingString(connectionString) {
|
||||
if(/(?:database|initial\scatalog)=(?:(.*?);|(.*))/gi.test(connectionString)) {
|
||||
|
||||
let matches = (/(?:host|server|data\s?source|addr(?:ess)?)=(?:(.*?);|(.*))/gi.exec(connectionString));
|
||||
const host = (matches) ? matches[1] || matches[2] : 'localhost';
|
||||
matches = (/(?:Port)=(?:(.*?);|(.*))/gi.exec(connectionString));
|
||||
const port = (matches) ? matches[1] || matches[2] : 3306;
|
||||
matches = (/(?:user\s?(?:id|name)?|uid)=(?:(.*?);|(.*))/gi.exec(connectionString));
|
||||
const user = (matches) ? matches[1] || matches[2] : 'root';
|
||||
matches = (/(?:password|pwd)=(?:(.*?);|(.*))/gi.exec(connectionString));
|
||||
const password = (matches) ? matches[1] || matches[2] : '';
|
||||
matches = (/(?:database|initial\scatalog)=(?:(.*?);|(.*))/gi.exec(connectionString));
|
||||
const database = (matches) ? matches[1] || matches[2] : '';
|
||||
return { host, port, user, password, database, dateStrings: true };
|
||||
|
||||
} else if(/mysql:\/\//gi.test(connectionString)) {
|
||||
|
||||
let matches = /mysql:\/\/(.*?)(?::|@)(?:(.*)@)?(.*?)(?::(\d{1,5}))?\/(.*?)\?(.*)/gi.exec(connectionString);
|
||||
const host = (matches[3]) ? matches[3] : 'localhost';
|
||||
const port = (matches[4]) ? matches[4] : 3306;
|
||||
const user = (matches[1]) ? matches[1] : 'root';
|
||||
const password = (matches[2]) ? matches[2] : '';
|
||||
const database = (matches[5]) ? matches[5] : '';
|
||||
const config = { host, port, user, password, database };
|
||||
const options = matches[6];
|
||||
return parseOptions(config, options);
|
||||
|
||||
} else throw new Error('No valid connection string found');
|
||||
}
|
||||
|
||||
let isReady = false;
|
||||
global.on('onServerResourceStart', (resourcename) => {
|
||||
if (resourcename == 'mysql-async') {
|
||||
const connectionString = global.GetConvar('mysql_connection_string', 'mysql://localhost/');
|
||||
config = parseConnectingString(connectionString);
|
||||
debug = global.GetConvarInt('mysql_debug', 0);
|
||||
pool = mysql.createPool(config);
|
||||
global.emit('onMySQLReady'); // avoid ESX bugs
|
||||
isReady = true;
|
||||
}
|
||||
if (isReady) {
|
||||
global.emit('MySQLReady'); // avoid ESX bugs
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "mysql-async",
|
||||
"version": "3.0.1",
|
||||
"description": "fivem-mysql-async",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"build": "webpack"
|
||||
},
|
||||
"contributors": [
|
||||
"Joel Wurtz",
|
||||
"Matthias Mandelartz"
|
||||
],
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"mysql": "^2.16.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^5.6.0",
|
||||
"webpack": "^4.19.0",
|
||||
"webpack-cli": "^3.1.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
const path = require('path');
|
||||
|
||||
module.exports = {
|
||||
entry: './mysql.js',
|
||||
target: 'node',
|
||||
mode: 'production',
|
||||
output: {
|
||||
filename: 'mysql-async.js',
|
||||
path: path.resolve(__dirname, '..'),
|
||||
},
|
||||
optimization: {
|
||||
minimize: false,
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user