Scommer Posted October 30, 2009 Share Posted October 30, 2009 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 Link to comment
Dark Dragon Posted October 30, 2009 Share Posted October 30, 2009 well currently you set the camera matrix but instantly set it again, again and another time. this happens so fast that you don't notice anything is happening at all. try to count how many times the player pressed the button, if its the first time, set the matrix to the second if its the second time to the third and so on. Link to comment
Scommer Posted October 30, 2009 Author Share Posted October 30, 2009 can you give me an example or something how to count how many times players pressed the button? Link to comment
Dark Dragon Posted October 30, 2009 Share Posted October 30, 2009 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 ) Link to comment
Scommer Posted November 2, 2009 Author Share Posted November 2, 2009 So now if want to make that arrow_l turns previous camera i need to count presses again ? Or what? Link to comment
50p Posted November 2, 2009 Share Posted November 2, 2009 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? Link to comment
Dark Dragon Posted November 3, 2009 Share Posted November 3, 2009 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 Link to comment
Scommer Posted November 3, 2009 Author Share Posted November 3, 2009 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 I think i'm get learning Lua from hardest things Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now