Jump to content

Question about camera


KirillWd

Recommended Posts

Hey, Everyone! My question is how can I record the camera's position?

Why doesn't it work?

  
[b]function[/b] trace(player) 
     [b]local [/b]x, y, z = getCameraMatrix(player) 
     [b]outputChatBox[/b]("x: "..tostring(x).."; y: "..tostring(y).."; z: "..tostring(z), player) 
[b]end[/b] 
----- 
[b]addCommandHandler[/b]("t", trace) 
  

It always prints:

x: false; y: nil; z: nil

I don't understand why x is false, y and z are undefined. Please, help!

Link to comment

actually, the values could go in with out using "tostring" or "tonumber".

anyways, make sure this is server-sided.

if it still doesn't work, try this:

function trace(source) 
    local x, y, z = getCameraMatrix(source) 
    if x and y and z then 
        outputChatBox("Your Camera Positions are x: "..(x).."; y: "..(y).."; z: "..(z),source) 
    else 
        outputChatBox("Test!!!",source) 
        local x1,y1,z1 = getElementPosition(source) 
        setCameraMatrix(source,x1,y1,z1+3,x1,y1,z1) -- this would set the camera looking down at you 
        x, y, z = getCameraMatrix(source) --replace the current vars 
        outputChatBox("Your Camera Positions are x: "..(x).."; y: "..(y).."; z: "..(z),source) 
        setTimer(setCameraTarget,7000,1,source,source) 
        setTimer(setCameraTarget,7000,1,source,source) 
    end 
end 
addCommandHandler("t",trace) 

Edited by Guest
Link to comment

yep, this file is on server-side.

Jaysds1, that isn't i want. yeah, this work, but everytime camera's x (either y) are the same of player's x (and y). I needn't know the player's position, but camera's. If change the position after the first time, there is the test again.

Why does it happen?

Link to comment

Do you want a joke? This script works on client-side and doesn't on server-side. so

-- <script src="script.lua" type="client" /> 
[b]function[/b] trace() 
    local x, y, z = getCameraMatrix() 
    outputChatBox("x: "..math.ceil(x).."; y: "..math.ceil(y)) 
[b]end[/b] 
addCommandHandler("t", trace) 
-- works! 
  

Nevermind, I've understood I don't need server to know camera's position of all players. Well, the task is completed. Anyway, thx to everyone who has tried to help! :)

Link to comment

For your information, server-side getCameraMatrix will return the values you previously set with setCameraMatrix, you will not get position of player's camera unless you set it first. That's because server doesn't need to update this information every tick, this would lag the server and eventually freeze it.

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