Jorgito'Molina Posted March 25, 2013 Posted March 25, 2013 (edited) addEventHandler( "onClientResourceStart", getResourceRootElement(), function ( ) fadeCamera( true ); setTimer( setCameraMatrix, 50, 1, 2538.47, 2074.72, 10.67, 1364.53, -1279.62, 13.54 ); --letterBox.flyIn( ); preloadClassesInfo( ); createClassSelectionWnd( ); createGroupSelectionWnd( ); createClassDescriptionWnd( ); createClassWeaponWnd( ); setTimer( createTempPed, 100, 1 ); showCursor( true ); showSpawnMenu( false, true ); showHUDComponents( allHUDElements ); end ); in spawn50p I made another post like this, in this want How to give a random camera when a player connect???? Edited March 25, 2013 by Guest
Castillo Posted March 25, 2013 Posted March 25, 2013 Create a table with the camera positions, then get a random index from it. http://lua-users.org/wiki/TablesTutorial math.random unpack
Jorgito'Molina Posted March 25, 2013 Author Posted March 25, 2013 function ( ) local fadeCamera( true ) = { setCameraMatrix, 50, 1, 2538.47, 2074.72, 10.67, 1364.53, -1279.62, 13.54, setCameraMatrix, 50, 10 1967.71, 1342.9, 26.63, 2034.47, 1343.02, 20.01 } addEventHandler( "setTimer", root, function ( ) setCameraMatrix( source, fadecamera [math.random ( #fadecamera ) ] ) ); end ) i am noob creating tables, I read up 2.4 – Metatables and Metamethods, of "http://www.lua.org/manual/5.2/"
iPrestege Posted March 25, 2013 Posted March 25, 2013 (edited) Do you mean like that? CameraMatrix = { {x,y,z}, {x,y,z}, {x,y,z} } addEventHandler("onPlayerJoin",root, function ( ) local x,y,z = unpack(CameraMatrix[math.random(#CameraMatrix)]); setCameraMatrix(source,x,y,z); end ); Edited March 25, 2013 by Guest
iPrestege Posted March 25, 2013 Posted March 25, 2013 Why do you loop the cameras? ._. Edit i forget that see my post edit time and your post
xXMADEXx Posted March 25, 2013 Posted March 25, 2013 This is how i do it: camraViews = { {x,y,z,x2,y2,z2}, } function randomView() return unpack(camraViews[math.random(#camraViews)]) end addEventHandler("onPlayerJoin",root, function () local p = source local x,y,z,xx,yx,zx = randomView() fadeCamera(p, true, 5) setCameraMatrix(p,x,y,z,xx,yx,zx) end ) addEventHandler("onPlayerLogin",root, function () local k = source fadCamera(k,true,5) setCameraTarget(k,k) end )
hassan.k.s.a Posted March 25, 2013 Posted March 25, 2013 This is how i do it: camraViews = { {x,y,z,x2,y2,z2}, } function randomView() return unpack(camraViews[math.random(#camraViews)]) end addEventHandler("onPlayerJoin",root, function () local p = source local x,y,z,xx,yx,zx = randomView() fadeCamera(p, true, 5) setCameraMatrix(p,x,y,z,xx,yx,zx) end ) addEventHandler("onPlayerLogin",root, function () local k = source fadCamera(k,true,5) setCameraTarget(k,k) end ) fadeCamera(k,true,5)
ixjf Posted March 26, 2013 Posted March 26, 2013 (edited) function ( ) local fadeCamera( true ) = { setCameraMatrix, 50, 1, 2538.47, 2074.72, 10.67, 1364.53, -1279.62, 13.54, setCameraMatrix, 50, 10 1967.71, 1342.9, 26.63, 2034.47, 1343.02, 20.01 } addEventHandler( "setTimer", root, function ( ) setCameraMatrix( source, fadecamera [math.random ( #fadecamera ) ] ) ); end ) i am noob creating tables, I read up 2.4 – Metatables and Metamethods, of "http://www.lua.org/manual/5.2/" Metatables/metamethods are far from what you want. Your code has nothing to do with metatables either. Edited March 27, 2013 by Guest
Moderators IIYAMA Posted March 26, 2013 Moderators Posted March 26, 2013 Just make it easy for your self. local camera = { {50, 1, 2538.47, 2074.72, 10.67, 1364.53, -1279.62, 13.54}, -- camera 1 {50, 10, 1967.71, 1342.9, 26.63, 2034.47, 1343.02, 20.01 } -- camera 2 } local indexCamera = #camera addEventHandler("onPlayerJoin",root, function () setTimer (function () if isElement (source) then setCameraMatrix( source,unpack(camera[math.random(indexCamera)])) fadeCamera(source, true)--fadecamera end end,3000,1) end) #camera -- table range. {} + {} = 2 math.random() -- can be number 1 t/m table range camera[]-- index the table. {}, {} unpack() -- unpack the data. >50, 1, 2538.47, 2074.72, 10.67, 1364.53, -1279.62, 13.54<
ixjf Posted March 26, 2013 Posted March 26, 2013 Just make it easy for your self. local camera = { {50, 1, 2538.47, 2074.72, 10.67, 1364.53, -1279.62, 13.54}, -- camera 1 {50, 10, 1967.71, 1342.9, 26.63, 2034.47, 1343.02, 20.01 } -- camera 2 } local indexCamera = #camera addEventHandler("onPlayerJoin",root, function () setTimer (function () if isElement (source) then setCameraMatrix( source,unpack(camera[math.random(indexCamera)])) fadeCamera(source, true)--fadecamera end end,3000,1) end) #camera -- table range. {} + {} = 2 math.random() -- can be number 1 t/m table range camera[]-- index the table. {}, {} unpack() -- unpack the data. >50, 1, 2538.47, 2074.72, 10.67, 1364.53, -1279.62, 13.54< Why are you declaring a variable and initializing it with the table's length? What's it for?
Moderators IIYAMA Posted March 26, 2013 Moderators Posted March 26, 2013 well if you go index a both this range, don't you get some warnings/errors? Ftable = { {1}, {2}, {3} } outputChatBox(Ftable[4]) -- warning/error
ixjf Posted March 26, 2013 Posted March 26, 2013 (edited) well if you go index a both this range, don't you get some warnings/errors? Ftable = { {1}, {2}, {3} } outputChatBox(Ftable[4]) -- warning/error Sure, you do but since the table is indexed you can use # to get its length, turning things flexible. Edited March 27, 2013 by Guest
Markeloff Posted March 26, 2013 Posted March 26, 2013 Give the player a camera ( the weapon ) or set his view on joining ?
Moderators IIYAMA Posted March 26, 2013 Moderators Posted March 26, 2013 @Markeloff Re: How to give a random camera when a player connect???? (title) Hey bro! @ixjf correct as you said you can also write it like this: setCameraMatrix( source,unpack(camera[math.random(#camera)])) Then you have to re-index the table, but if that isn't needed then I prefer a value outside the function. But very flexible.(re-index)
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