SetFPSLimit: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Improve FPS range note.)
(Add red note about moving sideways.)
Line 21: Line 21:
It is recommended to set a conservative FPS limit (between 40-60 and 74 highest) because high FPS can break some GTA internal calculations, causing various bugs. The higher the FPS the more of a problem these become:
It is recommended to set a conservative FPS limit (between 40-60 and 74 highest) because high FPS can break some GTA internal calculations, causing various bugs. The higher the FPS the more of a problem these become:


* The higher your FPS, the longer it takes for you to start moving sideways while aiming certain weapons. At very high FPS, it may become impossible to do so. (Fixed in [https://buildinfo.mtasa.com/index.php?Revision=21268&Branch= r21268 and above.])
{{Deprecated items|3.0160|1.5.9|
* The higher your FPS, the longer it takes for you to start moving sideways while aiming certain weapons.
|21268}}
As the most common issue, you should know that the breaking point for this bug is 70 FPS, so we recommend using a limit of 70 FPS if you intend to avoid this bug. Using 74 FPS is only recommended in non-combat focussed gamemodes (no gunfights) as the aforementioned breaking point of 70 FPS means that at 71 FPS, you will start getting a delay in moving sideways while aiming (having to hold the strafe key for longer). At 70 FPS, it still works perfectly.
As the most common issue, you should know that the breaking point for this bug is 70 FPS, so we recommend using a limit of 70 FPS if you intend to avoid this bug. Using 74 FPS is only recommended in non-combat focussed gamemodes (no gunfights) as the aforementioned breaking point of 70 FPS means that at 71 FPS, you will start getting a delay in moving sideways while aiming (having to hold the strafe key for longer). At 70 FPS, it still works perfectly.



Revision as of 10:40, 23 December 2022

This function sets the maximum FPS (Frames per second) that players on the server can run their game at.

[[{{{image}}}|link=|]] Note:
  • When set client side, the actual limit used is the lowest of both the server and client set values.
  • Starting from version [r21313] and above fpsLimit range is 25-32767. In older MTA releases it was 25-100.

Syntax

bool setFPSLimit ( int fpsLimit )         

Required Arguments

  • fpsLimit: An integer value representing the maximum FPS. Refer to the note for possible values. You can also pass 0 or false, in which case the FPS limit will be the one set in the client settings (by default, 100 FPS and the client fps limit should also be manually changed via "fps_limit=0" in console or MTA San Andreas 1.5\MTA\config\coreconfig.xml).

Returns

Returns true if successful, or false if it was not possible to set the limit or an invalid value was passed.

Issues when increasing FPS

Note: with "very high" FPS, any FPS limit over 74 is meant. It is recommended to set a conservative FPS limit (between 40-60 and 74 highest) because high FPS can break some GTA internal calculations, causing various bugs. The higher the FPS the more of a problem these become:

BEFORE VERSION 1.5.9 r21268:
  • The higher your FPS, the longer it takes for you to start moving sideways while aiming certain weapons.

As the most common issue, you should know that the breaking point for this bug is 70 FPS, so we recommend using a limit of 70 FPS if you intend to avoid this bug. Using 74 FPS is only recommended in non-combat focussed gamemodes (no gunfights) as the aforementioned breaking point of 70 FPS means that at 71 FPS, you will start getting a delay in moving sideways while aiming (having to hold the strafe key for longer). At 70 FPS, it still works perfectly.

74 FPS is the breaking point that opens the door to various more severe GTA bugs related to FPS and physics.

  • Physics of vehicles is effected, both high and low FPSes may bring their own set of unfair advantages. Speaking about the consequences of high FPS in this context, up to 70 or 74 FPS is considered safe (as any differences in physics, if they do exist to begin with as they theoretically should, are so tiny that they are unmeasurable and thus wouldn't affect racing results in practise). Anything beyond 74 FPS may cause impactful discrepancies.
  • Pressing the horn button to turn on and off sirens gets really hard at very high FPS. For instance, at 100 FPS, you are more likely to hit the regular horn 3 times (inconsistent) before eventually triggering the siren, besides taking a similar amount of tries to turn off the siren.
  • At very high FPS, climbing over certain objects will result in instant death. Example at: 2520.108, -1681.407, 19.406, 266
  • The higher your FPS, the more of a penalty in satchel throwing distance (up to ~10% at very high FPS) will apply.

For a full list of FPS-related GTA bugs (that are much less likely to impact gameplay in a meaningful way) and MTA developers' progress in tackling them, see the Framerate issues tracker github project.

Example

This example allows players to limit their own FPS using a command.

Click to collapse [-]
Client
function fpsFunction(command, limit)
	if limit and tonumber(limit) and tonumber(limit) >= 30 and tonumber(limit) <= 74 then
		limit = tonumber(limit)

		if setFPSLimit(limit) then
			outputChatBox("Your FPS has been limited to: " .. limit .. ".")
		end
	else
		outputChatBox("SYNTAX: /" .. command .. " [30 ~ 74] - Limit your own FPS.")
	end
end
addCommandHandler("limitfps", fpsFunction)
addCommandHandler("fpslimit", fpsFunction)


This example lets servers that have chosen to use FPS above 70 (even 100 FPS), fix the "walking sideways while aiming" (strafing) bug for all of their players.

Click to collapse [-]
Client
local previousTask = false
local defaultFpsLimit


-- Store FPS limit on resource start to ensure its reliability (as server FPS limit)
function getLimit()
	defaultFpsLimit = getFPSLimit()
end
addEventHandler("onClientResourceStart", resourceRoot, getLimit)

local isAdded = false

-- Not important to understand the logic of this script example, but just optimization for the render event to limit unnecesary execution
function optimizeRender(prevSlot, curSlot)
	if not isAdded and (curSlot >= 2 and curSlot <= 6) then
		addEventHandler("onClientRender", getRootElement(), fixStrafing)
		isAdded = true
	elseif isAdded and (curSlot <= 1 or curSlot >= 7) then
		removeEventHandler("onClientRender", getRootElement(), fixStrafing)
		isAdded = false
	end
end
addEventHandler("onClientPlayerWeaponSwitch", localPlayer, optimizeRender)


function fixStrafing()

	local weapon = getPedWeaponSlot(localPlayer)

	-- Don't execute if player isn't holding a (suitable) weapon
	-- This selects only weapons that are guns and suffer from strafing bug (slot 2, 3, 4, 5 and 6)
	-- Allowing other weapon types will bug the script as throwing/punch weapons don't support 'release' state of TASK_SIMPLE_USE_GUN
	if not (weapon >= 2 and weapon <= 6)
		then return
	end

	local newTask = getPedTask(localPlayer, "secondary", 0)

	if (previousTask ~= "TASK_SIMPLE_USE_GUN" or false) and (previousTask ~= newTask) then
		setFPSLimit(70)
	elseif (previousTask == "TASK_SIMPLE_USE_GUN") and (previousTask ~= newTask) then
		setFPSLimit(defaultFpsLimit)
	end

	previousTask = newTask
end

See Also