Jump to content

camera change


Dimos7

Recommended Posts

cameralocations = {1483.3354492188, -1719.1064453125, 50.896812438965, 1481.7545166016, -1803.435546875, -2.8257052898407, 1429.7171630859, -1709.8178710938, 20.389394760132, 1345.8790283203, -1666.9763183594, -13.311774253845, 1085.6225585938, -1797.7232666016, 19.463459014893, 1185.4050292969, -1796.0799560547, 25.848203659058, 1199.8775634766, -1324.5711669922, 26.630777359009, 1108.8699951172, -1321.8992919922, -14.72714138031, 1353.8889160156, -1280.1647949219, 19.625982284546, 1446.3851318359, -1283.6138916016, -18.22318649292, 1418.2659912109, -890.18493652344, 85.20630645752, 1403.9643554688, -791.30133056641, 89.388885498047}

function tutorial()
    for #cameralocations do 
	     location = cameralocations
        cameraTimer = setTimer(setCameraMatrix, 5000, 1, location[1], location[2], location[3], location[4], location[5], location[6])
    end
end
addEventHandler("onClientResourceStart", resourceRoot, tutorial)

error line 4 # expect  <name> near #

Edited by Dimos7
Link to comment
  • Moderators

You're looping the table the wrong way. Also, it will not work the way you created that.

cameralocations = {
    {1483.3354492188, -1719.1064453125, 50.896812438965, 1481.7545166016, -1803.435546875, -2.8257052898407},
    {1429.7171630859, -1709.8178710938, 20.389394760132, 1345.8790283203, -1666.9763183594, -13.311774253845},
    {1085.6225585938, -1797.7232666016, 19.463459014893, 1185.4050292969, -1796.0799560547, 25.848203659058},
    {1199.8775634766, -1324.5711669922, 26.630777359009, 1108.8699951172, -1321.8992919922, -14.72714138031},
    {1353.8889160156, -1280.1647949219, 19.625982284546, 1446.3851318359, -1283.6138916016, -18.22318649292},
    {1418.2659912109, -890.18493652344, 85.20630645752, 1403.9643554688, -791.30133056641, 89.388885498047}
}

Try with the table like that.

Link to comment
5 minutes ago, DNL291 said:

You're looping the table the wrong way. Also, it will not work the way you created that.


cameralocations = {
    {1483.3354492188, -1719.1064453125, 50.896812438965, 1481.7545166016, -1803.435546875, -2.8257052898407},
    {1429.7171630859, -1709.8178710938, 20.389394760132, 1345.8790283203, -1666.9763183594, -13.311774253845},
    {1085.6225585938, -1797.7232666016, 19.463459014893, 1185.4050292969, -1796.0799560547, 25.848203659058},
    {1199.8775634766, -1324.5711669922, 26.630777359009, 1108.8699951172, -1321.8992919922, -14.72714138031},
    {1353.8889160156, -1280.1647949219, 19.625982284546, 1446.3851318359, -1283.6138916016, -18.22318649292},
    {1418.2659912109, -890.18493652344, 85.20630645752, 1403.9643554688, -791.30133056641, 89.388885498047}
}

Try with the table like that.

This is not enough, tell him also to fix the loop

Link to comment
  • Moderators
3 minutes ago, LoPollo said:

This is not enough, tell him also to fix the loop

Yes, he's calling setTimer function inside a loop, it will not work.

Regarding the loop, I already warned him.

Quote

You're looping the table the wrong way

 

  • Like 1
Link to comment

 

cameralocations = {
    {1483.3354492188, -1719.1064453125, 50.896812438965, 1481.7545166016, -1803.435546875, -2.8257052898407},
    {1429.7171630859, -1709.8178710938, 20.389394760132, 1345.8790283203, -1666.9763183594, -13.311774253845},
    {1085.6225585938, -1797.7232666016, 19.463459014893, 1185.4050292969, -1796.0799560547, 25.848203659058},
    {1199.8775634766, -1324.5711669922, 26.630777359009, 1108.8699951172, -1321.8992919922, -14.72714138031},
    {1353.8889160156, -1280.1647949219, 19.625982284546, 1446.3851318359, -1283.6138916016, -18.22318649292},
    {1418.2659912109, -890.18493652344, 85.20630645752, 1403.9643554688, -791.30133056641, 89.388885498047}
}
function tutorial()
    for #cameralocations do 
	     location = cameralocations
        cameraTimer = setTimer(setCameraMatrix, 5000, 1, location[1], location[2], location[3], location[4], location[5], location[6])
    end
end
addEventHandler("onClientResourceStart", resourceRoot, tutorial)

same error line 10

Link to comment

That's because that's not a correct for loop

in this case it's also useful to use ipairs.

Another thing: you will be overwriting cameraTimer

In the below code i will be using local variables as they're faster

local cameralocations = {
    { 1483.3354492188, -1719.1064453125, 50.896812438965, 1481.7545166016, -1803.435546875, -2.8257052898407 },
    { 1429.7171630859, -1709.8178710938, 20.389394760132, 1345.8790283203, -1666.9763183594, -13.311774253845 },
    { 1085.6225585938, -1797.7232666016, 19.463459014893, 1185.4050292969, -1796.0799560547, 25.848203659058 },
    { 1199.8775634766, -1324.5711669922, 26.630777359009, 1108.8699951172, -1321.8992919922, -14.72714138031 },
    { 1353.8889160156, -1280.1647949219, 19.625982284546, 1446.3851318359, -1283.6138916016, -18.22318649292 },
    { 1418.2659912109, -890.18493652344, 85.20630645752, 1403.9643554688, -791.30133056641, 89.388885498047 },
}
local cameraTimers = {}

function tutorial()
    for index,location in ipairs(cameralocations) do
        if isTimer( cameraTimers[index] ) then 
            killTimer(cameraTimers[index])
            cameraTimers[index] = nil
        end

        cameraTimers[index] = setTimer( 
            setCameraMatrix, 
            5000, 1, 
            location[1], location[2], location[3], 
            location[4], location[5], location[6]
        )
    end
end
addEventHandler("onClientResourceStart", resourceRoot, tutorial)

This should what you wanted to do. Also notice this is completely useless since the timers are going to be executed all after 5s, so actually only the last location will be shown:

wait 5s, set camera matrix to loc1, set camera matrix to loc2, ......., set camera matrix to loc6 -> only loc6 landscape will be visible (loc stands for location)

If you want to change the location every 5s in a loop then tell us and it will be shown to you.

like this: set to loc1, wait 5s, set to loc2, wait 5s, set to loc3, wait5s, ...., set to loc6, wait 5s, restart from loc1

Edited by LoPollo
  • Like 1
Link to comment
local cameraLocations = {
	{ 1483.3354492188, -1719.1064453125, 50.896812438965, 1481.7545166016, -1803.435546875, -2.8257052898407 },
	{ 1429.7171630859, -1709.8178710938, 20.389394760132, 1345.8790283203, -1666.9763183594, -13.311774253845 },
	{ 1085.6225585938, -1797.7232666016, 19.463459014893, 1185.4050292969, -1796.0799560547, 25.848203659058 },
	{ 1199.8775634766, -1324.5711669922, 26.630777359009, 1108.8699951172, -1321.8992919922, -14.72714138031 },
	{ 1353.8889160156, -1280.1647949219, 19.625982284546, 1446.3851318359, -1283.6138916016, -18.22318649292 },
	{ 1418.2659912109, -890.18493652344, 85.20630645752, 1403.9643554688, -791.30133056641, 89.388885498047 },
}

local cameraTimers = {}
function tutorial1()
	for index,location in ipairs(cameraLocations) do --set the timers from location
		if isTimer( cameraTimers[index] ) then 
			killTimer(cameraTimers[index])
			cameraTimers[index] = nil
		end
		
		cameraTimers[index] = setTimer( 
			setCameraMatrix, 
			5000*index, 1,  --5s*1st location = 5s, 5s*2nd loc = 10s, 5s*6th loc = 30s
			location[1], location[2], location[3], 
			location[4], location[5], location[6]
		)
	end

	if isTimer( cameraTimers[0] ) then 
		killTimer(cameraTimers[0])
		cameraTimers[0] = nil
	end
	cameraTimers[0] = setTimer( setCameraTarget, 5000*(#cameraLocations+1), 1, localPlayer ) --the camera will return to player
end

local activeLocation
function tutorial2()
	if not activeLocation then
		activeLocation = 1
	end
	local location = cameraLocations[activeLocation]
	setCameraMatrix( location[1], location[2], location[3], location[4], location[5], location[6] )
	if activeLocation < #cameraLocations then
		activeLocation = activeLocation + 1
		setTimer( tutorial2, 5000, 1 )
	else
		setCameraTarget( localPlayer )
	end
end
addEventHandler("onClientResourceStart", resourceRoot, tutorial1 ) --or tutorial2

This is not tested, also i tried to be as clear as possible. Please note that these 2 are not the only nor the best ways to achieve what you want, but i think they are clean and easy to understand. But everyone understand in its own way, so if you have any question we're here to answer them.

Link to comment

oh found the problem of method 2, just a moment

Edit: done

local activeLocation
function tutorial2()
	if not activeLocation then
		activeLocation = 1
	end
	if activeLocation <= #cameraLocations then
		local location = cameraLocations[activeLocation]
		setCameraMatrix( location[1], location[2], location[3], location[4], location[5], location[6] )
		activeLocation = activeLocation + 1
		setTimer( tutorial2, 5000, 1 )
	else
		setCameraTarget( localPlayer )
	end
end
addEventHandler("onClientResourceStart", resourceRoot, tutorial2 )

 

Edited by LoPollo
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...