Ranking
Original Post
camera hook
I saw some in the 3.1 thread that wondered about the camera hook API.

It can override the lookat, pos and FOV of the camera.

Currently there is a bug that prevents over riding on WASD movement.

local function camera()
        -- lookat needs to be called before pos 
        set_camera_lookat(0, 2, 1.5)
        set_camera_pos(3, 2, 1.1)
        set_fov(120)

        -- return 1 to disable the clients camera functions
        -- NOTE WASD and arrows are not possible to disable today 
        return 1
end

add_hook("camera", "fovcam", camera)
my god that looks funky

Quick Script using fov with information to show how lua works. (its uploaded at the bottom if you are lazy).
Use M and N to change FOV
Use B and V to change to preset FOV's.
local FOV = 120 --Variable that can be used throughout the script

local function camera()
        set_fov(FOV) --Sets camera Field Of Veiw
end

local function keypress(key)
    PresetB = 10 --Variable that can only be used in the "keypress" function
    PresetV = 120
    echo(key) --Prints the key code, usefull for finding keys
        if(key == 109) then -- If the key pressed is 109 (M) 
            FOV = FOV + 1 --then Add one to FOV
            echo(FOV) --and print FOV
        elseif(key == 110) then --If it isn't 109 (M) then check its 110 (N)
            FOV = FOV - 1
            echo(FOV)
        elseif(key == 118) then
            FOV = PresetB
            echo("Preset Key: " .. key .. ". FOV: " .. FOV) -- Use .. to seperate Variables and text.
        elseif(key == 98) then
            FOV = PresetV
            echo("Preset Key: " .. key .. ". FOV: " .. FOV)
        elseif key == string.byte('P') then -- If the key pressed is C
        echo(key)
        end --Ends the If
end --Ends the function

add_hook("key_down","FunCam", keypress) --Hooks to check for keys.
add_hook("camera", "FunCam", camera) --Hooks the Camera.
Last edited by Blam; Mar 29, 2008 at 11:27 AM.
:D
Originally Posted by hampa View Post
I saw some in the 3.1 thread that wondered about the camera hook API.

Me. :P

I thought it was like...free roam camera so i got all excited.. but it's not. lol..so i still really don't get it..But tbh i don't care, the only reason i was interested was because it sounded like free roam.

Thanks though.
It may not be simple to make (for us), but it is much easier to edit. I didn't even read the tut (I did, but didn't get it). The thing that made it easy for me is that I realized it's sorta like math. For example:
If w = y then x +1.
If w = y, add one to x.
or
If x = 1 then y = 0
If x is on/pressed, y is 0.
 
if(key == 109) then -- If the key pressed is 109 (M) 
FOV = FOV + 1 --then Add one to FOV
echo(FOV) --and print FOV
If M, which is key 109, is pressed, increase your FOV by 1.

(Thank you Mathomatic)
Last edited by Nuyashaki; Jan 24, 2008 at 07:20 PM.
I think I can make a free range camera, but I have not room for controls. I need WSAD freed up, and take Q and E too.
It should be relatively easy, but I can't really test it without a set of controls I can use.
Originally Posted by FNugget View Post
I think I can make a free range camera, but I have not room for controls. I need WSAD freed up, and take Q and E too.
It should be relatively easy, but I can't really test it without a set of controls I can use.

Why not use the number pad?

789
456
123


? seems like plenty of keys to me...
"Splint Chesthair" - Is my real name.
>< oh yeah...
I pressed them and I was like, awww they're camera too. But they're override-able! I'm on it!

Nevermind, it seems to still use toribash camera. Unless theres an different way to disable? I r use mac, and my keypad uses toribash camera.
Also it detects a single press, not button holds. I might be able to code around that, but i'd rather find a key hold command type thing.
Last edited by FNugget; Jan 26, 2008 at 05:03 PM.
Couldn't you have a keydown and keyup hook and return 1 in those if the key is w a s or d (or whatever)?

@FNugget

Set up flag variables for your keys, then check for keydown and keyup. If a key was pressed, set its flag on, and if its released, set it off. Then in your camera movement handler, check all flags, and if they are on, move the cam in that direction.
Last edited by NewbLuck; Feb 4, 2008 at 06:49 AM.
 ____  _____  __  __  _  _  ___  _  _ 
(  _ \(  _  )(  )(  )( \( )/ __)( \/ )
 ) _ < )(_)(  )(__)(  )  (( (__  \  / 
(____/(_____)(______)(_)\_)\___) (__) 
BTW, read my FreeCam thread. I got a semi free roam camera. It's free look at least.

Uhm, can anyone tell me to minimums and maximum angles the camera can go? It also seems the start position of camera is different in my script, even though I don't touch it. Anyone know that start position?

Right now I'm having to sync the camera buttons with my data. I gets out of sync sometimes.