SetFPSLimit: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Improved information, also making use of the countless discussion between staff and racing scene people (for instance) that have taken place over the years in discord, dev channels and bugtracker. So these are plain facts as investigated.)
 
(20 intermediate revisions by 2 users not shown)
Line 2: Line 2:
__NOTOC__
__NOTOC__
This function sets the maximum [http://en.wikipedia.org/wiki/Frame_rate FPS (Frames per second)] that players on the server can run their game at.   
This function sets the maximum [http://en.wikipedia.org/wiki/Frame_rate FPS (Frames per second)] that players on the server can run their game at.   
{{Note|When set client side, the actual limit used is the lowest of both the server and client set values}}
{{Note|
* When set client side, the actual limit used is the lowest of both the server and client set values.
* Starting from version [[https://buildinfo.mtasa.com/?Revision=21313&Branch r21313]] and above '''fpsLimit''' range is '''25-32767'''. In older MTA releases it was '''25-100'''.
}}
==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
Line 9: Line 12:


===Required Arguments===  
===Required Arguments===  
*'''fpsLimit:''' An integer value representing the maximum FPS. This value may be between '''25''' and '''100''' FPS. 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''').
*'''fpsLimit:''' An integer value representing the maximum FPS. Refer to the note above 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===
Line 17: Line 20:
Note: with "very high" FPS, any FPS limit over 74 is meant.
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:
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.
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.
74 FPS is the breaking point that opens the door to various more severe GTA bugs related to FPS and physics.
Line 25: Line 25:
* 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.
* 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.
* 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
* At very high FPS, climbing over certain objects will result in instant death. Example at: 2520.108, -1681.407, 19.406, 266 - [https://wiki.multitheftauto.com/wiki/SetFPSLimit#Fix_for_climbing_over_certain_objects you can use this Lua code to fix it.]
* At very high FPS, satchels can be thrown up to ~10% less distance.
* 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 [https://github.com/multitheftauto/mtasa-blue/projects/14 Framerate issues tracker] github project.


==Example==  
==Example==  
This command sets the fps limit in a command handler.
This example allows players to limit their own FPS using a command.
<section name="Server" class="server" show="true">
<section name="Client" class="client" show="true">
<syntaxhighlight lang="lua">function fpsFunction( player, command, limit ) -- First define the function
<syntaxhighlight lang="lua">
  if hasObjectPermissionTo ( player, "function.setFPSLimit" ) and limit then  
local minFPS = 25
    -- If the player has permission to set FPS limit and limit is submitted...
local maxFPS = 100
    setFPSLimit ( limit ) -- Set the fps.
 
  end
function fpsFunction(commandName, fpsLimit)
end
local newFPS = tonumber(fpsLimit)
local displaySyntax = (not newFPS) or (newFPS < minFPS) or (newFPS > maxFPS)
 
if displaySyntax then
outputChatBox("Syntax: /"..commandName.." ["..minFPS.." ~ "..maxFPS.."] - limit your own FPS.")
 
return false
end
 
local currentLimit = getFPSLimit()
local setNewFPS = (newFPS ~= currentLimit)
 
if setNewFPS then
outputChatBox("Your FPS has been limited to: "..newFPS..".")
setFPSLimit(newFPS)
end
end
addCommandHandler("limitfps", fpsFunction)
addCommandHandler("fpslimit", fpsFunction)
</syntaxhighlight>
</section>
 
== Fix for climbing over certain objects==
You can use this small code to fix one of high FPS issues, specifically the one which would instantly kill player climbing over some objects.
<section name="Client" class="client" show="true">
<syntaxhighlight lang="lua">
function onClientPlayerDamage(attackerElement, damageType, bodyPart)
local fallDamage = damageType == 54
 
if not fallDamage then
return false
end
 
local playerTask = getPedSimplestTask(localPlayer)
local playerClimbing = playerTask == "TASK_SIMPLE_CLIMB"


addCommandHandler ( "setfps", fpsFunction ) -- Attach the setfps command to fpsFunction function.
if playerClimbing then
cancelEvent()
end
end
addEventHandler("onClientPlayerDamage", localPlayer, onClientPlayerDamage)
</syntaxhighlight>
</syntaxhighlight>
</section>
</section>

Latest revision as of 01:01, 14 June 2023

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 above 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:

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 - you can use this Lua code to fix it.
  • 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
local minFPS = 25
local maxFPS = 100

function fpsFunction(commandName, fpsLimit)
	local newFPS = tonumber(fpsLimit)
	local displaySyntax = (not newFPS) or (newFPS < minFPS) or (newFPS > maxFPS)

	if displaySyntax then
		outputChatBox("Syntax: /"..commandName.." ["..minFPS.." ~ "..maxFPS.."] - limit your own FPS.")

		return false
	end

	local currentLimit = getFPSLimit()
	local setNewFPS = (newFPS ~= currentLimit)

	if setNewFPS then
		outputChatBox("Your FPS has been limited to: "..newFPS..".")
		setFPSLimit(newFPS)
	end
end
addCommandHandler("limitfps", fpsFunction)
addCommandHandler("fpslimit", fpsFunction)

Fix for climbing over certain objects

You can use this small code to fix one of high FPS issues, specifically the one which would instantly kill player climbing over some objects.

Click to collapse [-]
Client
function onClientPlayerDamage(attackerElement, damageType, bodyPart)
	local fallDamage = damageType == 54

	if not fallDamage then
		return false
	end

	local playerTask = getPedSimplestTask(localPlayer)
	local playerClimbing = playerTask == "TASK_SIMPLE_CLIMB"

	if playerClimbing then
		cancelEvent()
	end
end
addEventHandler("onClientPlayerDamage", localPlayer, onClientPlayerDamage)

See Also