start_ac

Summary

Well most of the servers are using some scripts like

  • multi-character

  • location selector (like qb-spawn)

so it means before the player gets loaded to the ground some actions might happen like:

  • noclip

  • godmode

  • teleport

  • invisibility

  • speedhack

  • freecam

the reason is that these scripts need to do that for the performance so we expect the anti-cheat to get started at the right time maybe after the player selected his character and got loaded on the ground

first, we need to find the script that loads the player on the ground the script must be the last script that handles spawning the player

it can be any script when you found it then you need to add the below code somewhere on the client file of the script

exports['HUNK-AC']:PlayerIsReady()

Here are Some Examples

esx_multicharacter

inside the client/main.lua find this part this is just an example check where I added the exports['HUNK-AC']:PlayerIsReady()

RegisterNetEvent('esx:playerLoaded')
AddEventHandler('esx:playerLoaded', function(playerData, isNew, skin)
	local spawn = playerData.coords or Config.Spawn
	if isNew or not skin or #skin == 1 then
		local finished = false
		local sex = skin.sex or 0
		if sex == 0 then model = `mp_m_freemode_01` else model = `mp_f_freemode_01` end
		RequestModel(model)
		while not HasModelLoaded(model) do
			RequestModel(model)
			Citizen.Wait(0)
		end
		SetPlayerModel(PlayerId(), model)
		SetModelAsNoLongerNeeded(model)
		skin = Config.Default
		skin.sex = sex
		TriggerEvent('skinchanger:loadSkin', skin, function()
			playerPed = PlayerPedId()
			SetPedAoBlobRendering(playerPed, true)
			ResetEntityAlpha(playerPed)
			TriggerEvent('esx_skin:openSaveableMenu', function()
				finished = true end, function() finished = true
			end)
		end)
		repeat Citizen.Wait(200) until finished
	end
	DoScreenFadeOut(100)

	SetCamActive(cam, false)
	RenderScriptCams(false, false, 0, true, true)
	cam = nil
	local playerPed = PlayerPedId()
	FreezeEntityPosition(playerPed, true)
	SetEntityCoordsNoOffset(playerPed, spawn.x, spawn.y, spawn.z, false, false, false, true)
	SetEntityHeading(playerPed, spawn.heading)
	if not isNew then TriggerEvent('skinchanger:loadSkin', skin or Characters[spawned].skin) end
	Citizen.Wait(400)
	DoScreenFadeIn(400)
	repeat Citizen.Wait(200) until not IsScreenFadedOut()
	TriggerServerEvent('esx:onPlayerSpawn')
	TriggerEvent('esx:onPlayerSpawn')
	TriggerEvent('playerSpawned')
	TriggerEvent('esx:restoreLoadout')
	Characters, hidePlayers = {}, false

	-- added part for export
	Wait(1000)
	exports['HUNK-AC']:PlayerIsReady()
end)
es_extended (if using esx without multi character)

inside the client/main.lua find this part this is just an example check where I added the exports['HUNK-AC']:PlayerIsReady()

RegisterNetEvent('esx:playerLoaded')
AddEventHandler('esx:playerLoaded', function(xPlayer, isNew, skin)
	ESX.PlayerData = xPlayer

	if Config.Multichar then
		Wait(3000)
	else
		exports.spawnmanager:spawnPlayer({
			x = ESX.PlayerData.coords.x,
			y = ESX.PlayerData.coords.y,
			z = ESX.PlayerData.coords.z + 0.25,
			heading = ESX.PlayerData.coords.heading,
			model = `mp_m_freemode_01`,
			skipFade = false
		}, function()
			TriggerServerEvent('esx:onPlayerSpawn')
			TriggerEvent('esx:onPlayerSpawn')
			TriggerEvent('esx:restoreLoadout')

			if isNew then
				TriggerEvent('skinchanger:loadDefaultModel', skin.sex == 0)
			elseif skin then
				TriggerEvent('skinchanger:loadSkin', skin)
			end

			TriggerEvent('esx:loadingScreenOff')
			ShutdownLoadingScreen()
			ShutdownLoadingScreenNui()
		end)
	end

	ESX.PlayerLoaded = true

	while ESX.PlayerData.ped == nil do Wait(20) end

	if Config.EnablePVP then
		SetCanAttackFriendly(ESX.PlayerData.ped, true, false)
		NetworkSetFriendlyFireOption(true)
	end

	local playerId = PlayerId()

	-- RemoveHudCommonents
	for i = 1, #(Config.RemoveHudCommonents) do
		if Config.RemoveHudCommonents[i] then
			SetHudComponentPosition(i, 999999.0, 999999.0)
		end
	end

	-- DisableNPCDrops
	if Config.DisableNPCDrops then
		local weaponPickups = { `PICKUP_WEAPON_CARBINERIFLE`, `PICKUP_WEAPON_PISTOL`, `PICKUP_WEAPON_PUMPSHOTGUN` }
		for i = 1, #weaponPickups do
			ToggleUsePickupsForPlayer(playerId, weaponPickups[i], false)
		end
	end

	if Config.DisableHealthRegeneration or Config.DisableWeaponWheel or Config.DisableAimAssist or Config.DisableVehicleRewards then
		CreateThread(function()
			while true do
				if Config.DisableHealthRegeneration then
					SetPlayerHealthRechargeMultiplier(playerId, 0.0)
				end

				if Config.DisableWeaponWheel then
					BlockWeaponWheelThisFrame()
					DisableControlAction(0, 37, true)
				end

				if Config.DisableAimAssist then
					if IsPedArmed(ESX.PlayerData.ped, 4) then
						SetPlayerLockonRangeOverride(playerId, 2.0)
					end
				end
				
				if Config.DisableVehicleRewards then
					DisablePlayerVehicleRewards(playerId)
				end

				Wait(0)
			end
		end)
	end

	-- added part for export
	Wait(1000)
	exports['HUNK-AC']:PlayerIsReady()
	----------------------------------

	SetDefaultVehicleNumberPlateTextPattern(-1, Config.CustomAIPlates)
	StartServerSyncLoops()
end)

qb-spawn

inside the client/main.lua find this part this is just an example check where I added the exports['HUNK-AC']:PlayerIsReady()

local function PostSpawnPlayer(ped)
    FreezeEntityPosition(ped, false)
    RenderScriptCams(false, true, 500, true, true)
    SetCamActive(cam, false)
    DestroyCam(cam, true)
    SetCamActive(cam2, false)
    DestroyCam(cam2, true)
    SetEntityVisible(PlayerPedId(), true)
    Wait(500)
    DoScreenFadeIn(250)

    -- added part for export
    Wait(1000)
    exports['HUNK-AC']:PlayerIsReady()
end

if you have a problem with this part you can open a ticket on Discord

Last updated