[RELEASE][ESX] KASHacters Multi Character

esx_ambulancejob combat logger issue after choosing the character wasn’t directly fixed by @officialRobins fix for some reason so i had to just remove one thing. Hope this helps someone!

@officialRobins original fix
RegisterNetEvent('esx_ambulancejob:multicharacter')
AddEventHandler('esx_ambulancejob:multicharacter', 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)

All I did was remove the check for FirstSpawn in the esx_ambulancejob:multicharacter

With esx_ambulancejob:multicharacter being called from esx_kashacters when choosing a char it shouldn’t matter if was FirstSpawn or not (would assume this fix would not work if using the switch characters)

Removed FirstSpawn Check
RegisterNetEvent('esx_ambulancejob:multicharacter')
AddEventHandler('esx_ambulancejob:multicharacter', function()
	IsDead = false
	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)

Loving this Script :heart_eyes::sunglasses:

didn´t add what??

All I did was replace this section of code in esx_ambulancejob client and in esx_kashacters client

stock esx_ambulancejob/client/main.lua lines 43 - 61
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)
Replacement lines 43 - 78 now
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
	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)

make sure you trigger esx_ambulancejob:multicharacter in esx_kashacters/client/main.lua

TriggerEvent('esx_ambulancejob:multicharacter')
Stock esx_kashacters/client/main.lua lines 53 - 81
RegisterNetEvent('kashactersC:SpawnCharacter')
AddEventHandler('kashactersC:SpawnCharacter', function(spawn)
    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)

    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)
Replacement lines 53 - 87 now
RegisterNetEvent('kashactersC:SpawnCharacter')
AddEventHandler('kashactersC:SpawnCharacter', function(spawn, isnew)
    TriggerServerEvent('es:firstJoinProper')
    TriggerEvent('es:allowedToSpawn')
    TriggerEvent('esx_ambulancejob:multicharacter')

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

:warning: RESOURCE WARNING :warning:

This resource seems to make use of flawed logic to initialize itself. We’ve had multiple users come on the FiveM Discord today blaming ‘game updates’ for ‘breaking everything’, and it seems the issue is down to this kashacters resource.

In particular, it seems to expect that NETWORK_IS_SESSION_STARTED will return true within 7 milliseconds from the game initially loading.

This is not always the case, and is dependent on how much native code is executed by the game. I’m not sure where the number 7 came from, but for it to be relevant the user would need to be running at 142.8 FPS, which I doubt anyone is at all.

Correct code for this segment is as follows:

Citizen.CreateThread(function()
    while true do
        Citizen.Wait(0)
        if NetworkIsSessionStarted() then
            Citizen.Wait(100)
            TriggerServerEvent("kashactersS:SetupCharacters")
            TriggerEvent("kashactersC:SetupCharacters")
            return -- break the loop
        end
    end
end)
11 Likes

trying now, will report back

Ok so confirmed it works! but now it loads in a default fivem character then it comes up with the character selection, can we increase the (0) to something so players dont see this?

Try before you die.

1 Like

Working great now thank you for this.

hey, were you ever able to fix the /switch issue?

Not yet unfortunately.

The way esx works I dont think the /switch command is gonna be possible. It will allow you to change the character but with esx_skin the way it loads your character upon loading into the server it will not change your physical players skin.

No errors. Works fine for me but when other people join spawning as random character and no create character menu. wth

Same for me. Dont know what happend. Came from nowhere

With the last fivem update read above to see the fix for the players spawning in as default characters.

Thanks. I’m not sure that’s gonna fix the issue where when a player logs out my car disappears and brings up the old money hud. Tempted to just uninstall this script. Caused more issues than its worth.

ive been running kashacters since it was released and no issues at all…amazing resource…

I’ve found as long as you have all the tables in correctly it works amazing!

Was working great for the last 2 weeks or so since release, then out of nowhere players will join and spawn with a default ped/wont even get a character selection screen anymore…

I’ve the same problem… Do you have update artefact too ?

I got my issue fixed. It was my SQL server basically deciding to kill itself out of no where on my end, i don’t know about your issue if it isn’t sql related then unfortunately.