Jump to content

[Help] setCameraMatrix and bindKey


Scommer

Recommended Posts

Posted

I'm making changeable cameras with bind key "arrow_r" but i'm fucked up somewhere so i need your help.

function setCameraOnPlayerJoin()
fadeCamera(source, true, 1)
setCameraMatrix(source, 1769, -1846, 25, 1743, -1862, 14) --- Starting Camera
end
function cameraNext ( player, key, state )
setCameraMatrix(player, 792, -1320, 24, 823, -1341, 14) --- 1st
setCameraMatrix(player, 2229, -2640, 25, 2256, -2609, 9) ---2nd
setCameraMatrix(player, 1675, -2333, 25, 1643, -2333, 14) --- 3rd
setCameraMatrix(player, 2302, -2159, 26, 2299, -2126, 14) ---4th
end
function onPlayerJoin()
bindKey ( source, "arrow_r", "down", cameraNext )
end
addEventHandler ( "onPlayerJoin", getRootElement(), onPlayerJoin )
addEventHandler ( "onPlayerJoin", getRootElement(), setCameraOnPlayerJoin )

When i press arrow_r starting camera changes to camera 4th and then when i want to press arrow_r nothing happens.So i need your help how to make that starting camera change to 1st then 2nd then 3rd and etc

Posted
function setCameraOnPlayerJoin()
fadeCamera(source, true, 1)
setCameraMatrix(source, 1769, -1846, 25, 1743, -1862, 14) --- Starting Camera
end
function cameraNext ( player, key, state )
local count = getElementData ( player, "clicks" ) --get the element date we've just set on join
local count = count + 1 --add 1 to is (because the player just pressed the button)
setElementData ( player, "clicks", count ) --set the new element data for the next time
 
if count == 1 then --if 1, choose this camera
setCameraMatrix(player, 792, -1320, 24, 823, -1341, 14) --- 1st
elseif count == 2 then --elseif 2, choose this camera
setCameraMatrix(player, 2229, -2640, 25, 2256, -2609, 9) ---2nd
elseif count == 3 then --elseif 3, choose this camera
setCameraMatrix(player, 1675, -2333, 25, 1643, -2333, 14) --- 3rd
elseif count == 4 then --elseif 4, choose this camera
setCameraMatrix(player, 2302, -2159, 26, 2299, -2126, 14) ---4th
setElementData ( player, "clicks", 0 ) -- set the data to 0 again so it can start again with the first camera when pressed again
end
end
function onPlayerJoin()
bindKey ( source, "arrow_r", "down", cameraNext )
setElementData ( source, "clicks", 0 ) --set an element data called "click" for the player (so each player is treated separately)
end
addEventHandler ( "onPlayerJoin", getRootElement(), onPlayerJoin )
addEventHandler ( "onPlayerJoin", getRootElement(), setCameraOnPlayerJoin )

Posted
function setCameraOnPlayerJoin()
fadeCamera(source, true, 1)
setCameraMatrix(source, 1769, -1846, 25, 1743, -1862, 14) --- Starting Camera
end
function cameraNext ( player, key, state )
local count = getElementData ( player, "clicks" ) --get the element date we've just set on join
local count = count + 1 --add 1 to is (because the player just pressed the button)
setElementData ( player, "clicks", count ) --set the new element data for the next time
 
if count == 1 then --if 1, choose this camera
setCameraMatrix(player, 792, -1320, 24, 823, -1341, 14) --- 1st
elseif count == 2 then --elseif 2, choose this camera
setCameraMatrix(player, 2229, -2640, 25, 2256, -2609, 9) ---2nd
elseif count == 3 then --elseif 3, choose this camera
setCameraMatrix(player, 1675, -2333, 25, 1643, -2333, 14) --- 3rd
elseif count == 4 then --elseif 4, choose this camera
setCameraMatrix(player, 2302, -2159, 26, 2299, -2126, 14) ---4th
setElementData ( player, "clicks", 0 ) -- set the data to 0 again so it can start again with the first camera when pressed again
end
end
function onPlayerJoin()
bindKey ( source, "arrow_r", "down", cameraNext )
setElementData ( source, "clicks", 0 ) --set an element data called "click" for the player (so each player is treated separately)
end
addEventHandler ( "onPlayerJoin", getRootElement(), onPlayerJoin )
addEventHandler ( "onPlayerJoin", getRootElement(), setCameraOnPlayerJoin )

What is the reason to sync the click count?

Posted

as this guy doesn't seem to have much experience i tried to keep it basic and easy. actually i didn't even want him to take this but find out how to do it himself.

local count = getElementData ( player, "clicks" ) --get the element date we've just set on join
local count = count + 1 --add 1 to is (because the player just pressed the button)
setElementData ( player, "clicks", count ) --set the new element data for the next time

as you can see here i really did it step by step

Posted

Thanks for helping really,but now i need to make that arrow_l turns previous camera and with "enter" make a spawn on camera number If camera is 3rd then spawn will be 3rd :P I think i'm get learning Lua from hardest things :D

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