Jump to content

Changeing Camera Viewpoints


Recommended Posts

Hi,

On the login of our server, you have a location in mta as your background. Im looking to make it change every 5 seconds to a different view point, I have no idea of where to start with this. Atm for my view point i have

    fadeCamera(false,1) 
    setTimer(setCameraMatrix,1000,1,1515, -1636, 22.153465271, 1550, -1675, 9.881813049316) 
    setTimer(fadeCamera,1000,1,true) 

So if anyone can help please reply :S

Thanks

Link to comment

Very simple, make a table with the locations, then randomize from it.

local myLocationsTable = {} 
{x, y, z}, 
{x, y, z}, 
{x, y, z}, 
{x, y, z} 
  
function getRandomLocation() 
local rand = math.random(#myLocationsTable) 
local x, y, z = myLocationsTable[rand][1], myLocationsTable[rand][2], myLocationsTable[rand][3] 
return x, y, z 
end 

Link to comment

something like this:

  
views = { 
  { 1515, -1636, 22.153465271, 1550, -1675, 9.881813049316 }, -- first view 
  { 1515, -1636, 22.153465271, 1550, -1675, 9.881813049316 }, -- second view (change coordinats obviously) 
  { 1515, -1636, 22.153465271, 1550, -1675, 9.881813049316 }, -- third, etc 
  timer = false, -- view changing timer will be here 
  current = 0 -- current view will be stored here 
} 
  
-- then 
views.timer = setTimer(function() 
  local new = views.current == #views and 1 or views.current + 1 -- switch to view 1 if the last view is active or switch to next view 
  setCameraMatrix(views[new][1], views[new][2], views[new][3], views[new][4], views[new][5], views[new][6]) 
  views.current = new -- set new view as current 
end, 5000, 0) 
  
-- when you'll need to stop 
killTimer(views.timer) 
  

PS: while i was writing, Solidsnake14 already posted. but you forgot camera facing coordinates :D

Link to comment
Thanks for the speedy responce, but i added the code and now when you join the server, it makes you fall and then spawn on the ground, completly bypassing the login. :S

Any ideas?

you can't just add and expect it to work as you want. these are just examples.

Link to comment
  • Moderators

I fixed the SolidSnake's code:

-- your 3 lines: 
fadeCamera(false,1) 
TimerChange = setTimer(changeLocation,1000,0, ) 
setTimer(fadeCamera,1000,1,true) 
  
--------------------- 
local myLocationsTable = { 
{x, y, z, x2, y2, z2}, -- specify the position of the camera ( x, y, z ) and the point that the camera look at ( x2, y2, z2 ) 
{x, y, z, x2, y2, z2}, 
{x, y, z, x2, y2, z2}, 
{x, y, z, x2, y2, z2} 
 } 
  
function changeLocation(player) 
    local cx, cy, cz, px, py, pz = getRandomLocation() 
    setCameraMatrix( cx, cy, cz, px, py, pz ) 
end 
  
function getRandomLocation() 
    local rand = math.random(#myLocationsTable) 
    local x, y, z, x2, y2, z2 = myLocationsTable[rand][1], myLocationsTable[rand][2], myLocationsTable[rand][3], myLocationsTable[rand][4], myLocationsTable[rand][5], myLocationsTable[rand][6] 
    return x, y, z, x2, y2, z2 
end 
  
-- When the player is logged: 
killTimer( TimerChange ) 

EDIT:

actually you did not. this will not put anything in myLocationsTable:

Fixed :P

Edited by Guest
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...