OnClientPreRender: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
No edit summary
 
(One intermediate revision by one other user not shown)
Line 15: Line 15:
This example makes the camera follow the player in a GTA2-like way.
This example makes the camera follow the player in a GTA2-like way.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
root = getRootElement ()
function updateCamera ()
function updateCamera ()
local x, y, z = getElementPosition ( getLocalPlayer () )
local x, y, z = getElementPosition ( localPlayer )
setCameraMatrix ( x, y, z + 50, x, y, z )
setCameraMatrix ( x, y, z + 50, x, y, z )
end
end
Line 24: Line 23:


==Warning==
==Warning==
This event and [[onClientPreRender]] will trigger whatever function it is attached to with every frame. Depending on the server's maximum FPS and what your computer might handle - you might end up triggering the function 30-60 times '''per second'''.
This event and [[onClientRender]] will trigger whatever function it is attached to with every frame. Depending on the server's maximum FPS and what your computer might handle - you might end up triggering the function 30-60 times '''per second'''.


As a result, this event may cause severe lag and/or even crashes if not used cautiously.
As a result, this event may cause severe lag and/or even crashes if not used cautiously.

Latest revision as of 17:24, 30 July 2020

This event is triggered every time before GTA renders a new frame.

Parameters

float timeSlice
  • timeSlice: The interval between this frame and the previous one in milliseconds (delta time).

Source

The source of this event is the client's root element.

Example

This example makes the camera follow the player in a GTA2-like way.

function updateCamera ()
	local x, y, z = getElementPosition ( localPlayer )
	setCameraMatrix ( x, y, z + 50, x, y, z )
end
addEventHandler ( "onClientPreRender", root, updateCamera )

Warning

This event and onClientRender will trigger whatever function it is attached to with every frame. Depending on the server's maximum FPS and what your computer might handle - you might end up triggering the function 30-60 times per second.

As a result, this event may cause severe lag and/or even crashes if not used cautiously.

See Also

Game Processing Order

Other client events


Client event functions