Jump to content

Garage setCameraMatrix


Karuzo

Recommended Posts

Posted

Hey Guys,

So i have a problem :

I want to set the Camera Matrix of the player to a garage which i created , so i've got a question , how can i change to the next garage if i press the arrow keys ?

Posted

ye i know , but i want it if the player writes /garage it should show the first garage, and then if he presses right arrow key it moves to the next garage, but how do i put it in the ShowGarages function ?

Because it would be pretty bad if the next garage shows up when the player presses right arrow key :-)

function ShowGarages() 
    setCameraMatrix(1558.5915527344, -1027.4820556641, 30.416728973389) 
end 
addCommandHandler("garage", resourceRoot, ShowGarages) 

Posted

Create a table containing all the camera positions, and store the current table index in a table, then you increment it once he presses the key and obtain the camera position out of that index.

Posted
local garages = -- Define a table with few positions 
    { 
        { 0, 0, 0, 0, 0, 0 }, 
        { 0, 123, 0, 0, 0, 2 }, 
        { 465, 0, 0, 0, 0, 87 } 
    } 
local curGarage = 1 -- Define a variable with 1 as value 
  
function showGarage ( cmd ) 
    if ( garages [ curGarage ] ) then -- If the garages table contains the index specified in 'curGarage' variable... 
        setCameraMatrix ( unpack ( garages [ curGarage ] ) ) -- Unpack the table value from that index and set the camera position. 
    end 
end 
addCommandHandler ( "garage", showGarage ) 
  
function switchGarage ( key ) 
    if ( key == "arrow_l" ) then 
        if ( curGarage > 1 ) then 
            curGarage = ( curGarage - 1 ) -- Lower the 'curGarage' variable by 1 
        end 
    else 
        if ( #garages > curGarage ) then 
            curGarage = ( curGarage + 1 ) -- Increment the 'curGarage' variable by 1 
        end 
    end 
  
    showGarage ( ) 
end 
bindKey ( "arrow_l", "down", switchGarage ) 
bindKey ( "arrow_r", "down", switchGarage ) 

The positions in 'garages' table are just to show you how it works, you can add as much as you want.

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...