[RELEASE][ESX] KASHacters Multi Character

Thanks! I will test when i get home

1 Like

Thanks for your help! I think it works perfect now! :smiley:

No problem, glad to help:)

1 Like

@Loffe Any help on the esx_datastore duplication issue randomly? Seems to be the only random issue occurring for my server.

JaroSounds post

I never saw a fix come out to this post which explained the issue exactly as I am experiencing.

i got you, after a week working on it i finaly got a fix, 2 sec

1 Like

esx_datastore/server/main.lua
add this at the bottom:

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)
6 Likes

have been running it for 2 days whithout any complaints or issues, so im pretty sure this is it

Will try it out right now! This also make each char have own property inventory?

if you got these in kashacters server then yeah the saved outfits and properties will work fine:)

{table = "datastore_data", column = "owner"},
{table = "addon_account_data", column = "owner"},
{table = "addon_inventory_items", column = "owner"},
1 Like

addon_account_data :man_facepalming:

if you want to be able to put any money there it will be needed or what do u mean?

I forgot it :slightly_frowning_face:

ah okey yeah you’ll probably want that :wink:

@Loffe Thanks for the duplicated fix. I really appreciate that you shared this fix with us.

I tried to understand the fix for the error that we get on the screen character selection. But i failed to understand what you and @Malvia did.

So this is what i did but i still get the error.
In ambulance

AddEventHandler('playerSpawned', function()
	IsDead = false

	if FirstSpawn then
		exports.spawnmanager:setAutoSpawn(false) -- disable respawn
		FirstSpawn = false

		ESX.TriggerServerCallback('esx_ambulancejob:getDeathStatus', function(isDead)
			if isDead and Config.AntiCombatLog then
				while not PlayerLoaded do
					Citizen.Wait(1000)
				end

				ESX.ShowNotification(_U('combatlog_message'))
				RemoveItemsAfterRPDeath()
			end
		end)
	end
end)

RegisterNetEvent('esx_ambulancejob:multicharacter')
AddEventHandler('esx_ambulancejob:multicharacter', function()
	IsDead = false

		exports.spawnmanager:setAutoSpawn(false) -- disable respawn

		ESX.TriggerServerCallback('esx_ambulancejob:getDeathStatus', function(isDead)
			if isDead and Config.AntiCombatLog then
				ESX.ShowNotification(_U('combatlog_message'))
				RemoveItemsAfterRPDeath()
			end
		end)
end)

Then in kashacters

RegisterNetEvent('kashactersC:SpawnCharacter')
AddEventHandler('kashactersC:SpawnCharacter', function(spawn, isnew)
    TriggerServerEvent('es:firstJoinProper')
    TriggerEvent('es:allowedToSpawn')

    SetTimecycleModifier('default')
    local pos = spawn
    SetEntityCoords(GetPlayerPed(-1), pos.x, pos.y, pos.z)
    DoScreenFadeIn(500)
    Citizen.Wait(500)
    cam2 = CreateCamWithParams("DEFAULT_SCRIPTED_CAMERA", -1355.93,-1487.78,520.75, 300.00,0.00,0.00, 100.00, false, 0)
    PointCamAtCoord(cam2, pos.x,pos.y,pos.z+200)
    SetCamActiveWithInterp(cam2, cam, 900, true, true)
    Citizen.Wait(900)
    exports.spawnmanager:setAutoSpawn(false)
    TriggerEvent('esx_ambulancejob:multicharacter', source)
	
 if isnew then
	TriggerEvent('esx_identity:showRegisterIdentity')
 end

    cam = CreateCamWithParams("DEFAULT_SCRIPTED_CAMERA", pos.x,pos.y,pos.z+200, 300.00,0.00,0.00, 100.00, false, 0)
    PointCamAtCoord(cam, pos.x,pos.y,pos.z+2)
    SetCamActiveWithInterp(cam, cam2, 3700, true, true)
    Citizen.Wait(3700)
    PlaySoundFrontend(-1, "Zoom_Out", "DLC_HEIST_PLANNING_BOARD_SOUNDS", 1)
    RenderScriptCams(false, true, 500, true, true)
    PlaySoundFrontend(-1, "CAR_BIKE_WHOOSH", "MP_LOBBY_SOUNDS", 1)
    FreezeEntityPosition(GetPlayerPed(-1), false)
    Citizen.Wait(500)
    SetCamActive(cam, false)
    DestroyCam(cam, true)
    IsChoosing = false
    DisplayHud(true)
    DisplayRadar(true)
end)

Could you please assist me with this. I would really appreciate this. Thank you!
If not it’s all good :slight_smile:

1 Like

remove the playerspawned function and just save the muticharacter event. you can also remove : exports.spawnmanager:setAutoSpawn(false) from the multicharacter event when you have it in esx_kashacters too

1 Like

OMG Thank you Thank you! This worked like a charm. You rock. :smiley:

thanks, glad to help:)

1 Like

Did that fix the error from if a new player spawns?

maybe, there are a few other scripts that you need to do the smae with because otherwise the server try to execute them to early (befor choosing a character) which results in a error

I am going to test your fix today, we now have a issue with if you make a 2nd character your property inventorty is empty on your main character.