Jump to content

How to give a random camera when a player connect????


Recommended Posts

  
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 by Guest
Link to comment
  
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 
        ) 
  

:roll:

i am noob creating tables,

I read up 2.4 – Metatables and Metamethods, of "http://www.lua.org/manual/5.2/"

Link to comment

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 by Guest
Link to comment

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 
) 
  

Link to comment
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) 

Link to comment
  
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 
        ) 
  

:roll:

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 by Guest
Link to comment
  • Moderators

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< 
  

Link to comment
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?

Link to comment
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 by Guest
Link to comment
  • Moderators

@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)

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