[Best practice] Improve your resource performance

that’s what i’m trying to do… the main problem here is how to find the right script that causes it since it only happens when 26+ players are online

I suggest doing what @d0p3t suggested, see how many queries there are being executed. Probably some script that scales badly with the amount of people.

thanks for the advice :smiley:

The esx_policejob, esx_mafiajob and these esx job things are very FPS looters. Is there any way to improve them?

which version are you using?
and how you know that they are fps looters? you got drops in the near of the markers?!

Yes. I got some drops because of it. And my version is… esx_mafia.rar (40.3 KB)
this

Hi! I have a ELS script and this is the only script that appears as time warning. Any idea to fix this? This is a car-mod script.

Out of curiosity, what’s the suggested method of tracking down hitch warnings? Server isn’t even near cpu or mem capacity and seeing a cascade of hitch warnings. No resource time warnings or errors.

2 Likes

esx jobs gets a lot of cpu usage someone can explain this? and maybe have a fix for it?

jobs used:
Maffia
Cartel
Fire
Police
EMS

Is there a way to see how much are consuming all reosurces??

1 Like

in F8 console type “resmon 1” and to close it “resmon 0”

1 Like

realy useful, thx men

try in the client
Citizen.CreateThread(function()
while ESX == nil do
TriggerEvent(‘esx:getSharedObject’, function(obj) ESX = obj end)
Citizen.Wait(0)
end
end)

to

Citizen.CreateThread(function()
while ESX == nil do
TriggerEvent(‘esx:getSharedObject’, function(obj) ESX = obj end)
Citizen.Wait(500)
end
end)

I changed all the gang jobs - now It is decrease from .24-.30ms to .02-.05

2 Likes


--- DO NOT EDIT THIS --
local holstered  = true
local blocked	 = false
local PlayerData = {}
local cooldown	 = Config.cooldown
local inVehicle = false
------------------------


Citizen.CreateThread(function()
	if Config.UseESX then
		local ESX      	 = nil
		while ESX == nil do
			TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
			Citizen.Wait(0)
		end
		
		while ESX.GetPlayerData().job == nil do
			Citizen.Wait(10)
		end
		
		PlayerData = ESX.GetPlayerData()
		
		if not PlayerData.job.name == 'police' then
			cooldown = Config.CooldownPolice
		end
	end
end)


 Citizen.CreateThread(function()
	while true do
        Citizen.Wait(0)
        local ped = PlayerPedId()
        if DoesEntityExist( ped ) and not IsEntityDead( ped ) and not inVehicle then
            loadAnimDict( "reaction@intimidation@1h" )
            if CheckWeapon(ped) then
                if holstered then
                    TaskPlayAnim(ped, "reaction@intimidation@1h", "intro", 5.0, 1.0, -1, 30, 0, 0, 0, 0 )
                    Citizen.Wait(1700)
                    ClearPedTasks(ped)
                    holstered = false
                end
                SetPedComponentVariation(ped, 0, 0, 0, 0)
            elseif not CheckWeapon(ped) then
                if not holstered then
                    TaskPlayAnim(ped, "reaction@intimidation@1h", "outro", 8.0, 1.0, -1, 30, 0, 0, 0, 0 )
                    Citizen.Wait(1500)
                    ClearPedTasks(ped)
                    holstered = true
                end
                SetPedComponentVariation(ped, 0, 0, 0, 0)
            end
        end
    end
end)

Citizen.CreateThread(function()
    while(true) do
        inVehicle = IsPedInAnyVehicle(PlayerPedId(), true)
        Citizen.Wait(500)
    end
end)

Citizen.CreateThread(function()
	while true do
		Citizen.Wait(0)
			if blocked then
				DisableControlAction(1, 25, true )
				DisableControlAction(1, 140, true)
				DisableControlAction(1, 141, true)
				DisableControlAction(1, 142, true)
				DisableControlAction(1, 23, true)
				DisableControlAction(1, 37, true) -- Disables INPUT_SELECT_WEAPON (TAB)
				DisablePlayerFiring(ped, true) -- Disable weapon firing
			end
	end
end)


function CheckWeapon(ped)
	--[[if IsPedArmed(ped, 4) then
		return true
	end]]
	for i = 1, #Config.Weapons do
		if GetHashKey(Config.Weapons[i]) == GetSelectedPedWeapon(ped) then
			return true
		end
	end
	return false
end


function loadAnimDict(dict)
	while ( not HasAnimDictLoaded(dict)) do
		RequestAnimDict(dict)
		Citizen.Wait(0)
	end
end

This runs at 33 ms how can i improve that?

already fixed it :smiley:

1 Like

Can you help me ? i have the same whet mafias job

Good evening I have a question if you can help me if I replace all Citizen.Wait (0) by Citizen.Wait (100) this is good or not? :slight_smile:

you still coding on fivem by any chance? saw you best practices and have followed your advice. must say lowered the usage by loads. combined 3 scripts to one but still see 0.12 ms when out of car and 60 when in. any chance you whiling to take a look see? it is a combination of Hud simple hud speedometer and esx voice. i have already made the speedometer change its size with different resolutions and is a super clean setup now. just struggling to get the usage down even more. maybe not possible but was just keen to see if you whilling to help (prob something small im over looking) everything works though. thanks in advance

hey how u fix this ? please help …
i change esx get share object, citizen wait(0) to (500), and still same. runs at 30-40ms … this is eat so much fps

how to check how much ms all scripts taking ?? any in game script or something feel free to shre :slight_smile: