Lua: Access cvars, console output, and the player's camera

Status
Not open for further replies.

OtherChen

The other one
1: Can Lua read or write the game's built-in cvars like "friendlyfire" and "showfps"? Alternatively, can it read the literal console output like "friendlyfire is 'On' default is 'Off'"? I'd like to make non-damaging weapons affect teammates only if friendly fire is enabled, for example.

2: The wiki shows a userdata structure called "camera_t," but doesn't explain how to access any cameras in a map. How would I access a camera that's bound to a player? "camera", "player.camera", "player", "player.mo", and "player.mo.camera" all don't exist or don't refer to a camera.
 
1: Can Lua read or write the game's built-in cvars like "friendlyfire" and "showfps"? Alternatively, can it read the literal console output like "friendlyfire is 'On' default is 'Off'"? I'd like to make non-damaging weapons affect teammates only if friendly fire is enabled, for example.

2: The wiki shows a userdata structure called "camera_t," but doesn't explain how to access any cameras in a map. How would I access a camera that's bound to a player? "camera", "player.camera", "player", "player.mo", and "player.mo.camera" all don't exist or don't refer to a camera.
1) Not as far as I'm aware of.

2) You can access it through a HUD function. To put it in a check, I do something like this (this code is from SkyLua, and this is for checking if chasecam is enabled or not):

Code:
-- Set up a chasecam variable that's not bound to camera_t to check if the player has chasecam enabled
local chasecam

-- Modify the chasecam variable based on chasecam on or off through a dummy hud function, because that's the only function that can access camera_t, then change the chasecam variable to whatever
local function dummyhud(v, player, cam)
    if not player.mo
        return
    end
    if cam.chase==true
        chasecam = true
    else
        chasecam = false
    end
end

-- Add the above function into the game as a hud.add function
hud.add(dummyhud, player, cam)
Then I just check for if the local variable chasecam is true or not later on in whatever I need.
 
Status
Not open for further replies.

Who is viewing this thread (Total: 1, Members: 0, Guests: 1)

Back
Top