setCameraTarget | Multi Theft Auto: Wiki Skip to content

setCameraTarget

Client-side
Server-side
Shared

Pair: getCameraTarget

This page is incomplete! Help wanted!

Please finish this page using the corresponding Old Wiki article.
Go to Contribution guidelines for more information.


This function allows you to set a player's camera to follow other elements instead. Currently supported element type is:

Syntax

setCameraTarget ( )

Code Examples

server
g_Players = getElementsByType("player") -- get a list of all players in the server
for i,aPlayer in ipairs(g_Players) do -- find out what index the local player has in the list
if aPlayer == localPlayer then
g_CurrentSpectated = i
break
end
end
function spectatePrevious() -- decrement the spectate index and spectate the corresponding player
if g_CurrentSpectated == 1 then
g_CurrentSpectated = #g_Players
else
g_CurrentSpectated = g_CurrentSpectated - 1
end
setCameraTarget(g_Players[g_CurrentSpectated])
end
function spectateNext() -- increment the spectate index and spectate the corresponding player
if g_CurrentSpectated == #g_Players then
g_CurrentSpectated = 1
else
g_CurrentSpectated = g_CurrentSpectated + 1
end
setCameraTarget(g_Players[g_CurrentSpectated])
end
-- Bind above functions to arrow keys
bindKey("arrow_l", "down", spectatePrevious)
bindKey("arrow_r", "down", spectateNext)