--VERTICAL AUTO-RECENTER, a camera script to auto-recenter your vertcial aim --by Nero1024 --v1.3 --new, more readable command names --made a little safer to use in dedicated server environments -- (I still wouldn't recommend using this if heavy 1st person shooting is involved) --config i/o saving --cvar to enable recentering rawset(_G, "cv_camaimrecenter", CV_RegisterVar({ name = "camaimrecenter", defaultvalue = "1", PossibleValue = {Yes = 1, No = 0}, flags = 0 })) --recenter mode rawset(_G, "cv_camaimrecenter_mode", CV_RegisterVar({ name = "camaimrecenter_mode", defaultvalue = "1", PossibleValue = {Active = 1, Passive = 0}, flags = 0 })) --recentering factor cvar --positive values determine the slowness of the recentering --a value of 1.0 have no recentering --0 is (almost) instantaneous --negative values are bouncy and jittery like you just bumped into something --values higher than 1.0 or lower than -1.0 makes the camera freak out rawset(_G, "cv_camaimrecenter_factor", CV_RegisterVar({ name = "camaimrecenter_factor", defaultvalue = "0.85", PossibleValue = {MIN = -1*FRACUNIT, MAX = FRACUNIT}, flags = CV_FLOAT })) --speed threshold where recentering happens cvar --number is multiplied by player's scale (usually 1 FRACUNIT) --negative numbers makes the recentering constant rawset(_G, "cv_camaimrecenter_threshold", CV_RegisterVar({ name = "camaimrecenter_threshold", defaultvalue = "5" })) --time delay for passive mode recentering, in seconds rawset(_G, "cv_camaimrecenter_delay", CV_RegisterVar({ name = "camaimrecenter_delay", defaultvalue = "3.0", PossibleValue = {MIN = 0, MAX = INT32_MAX}, flags = CV_FLOAT })) --file i/o init local FILENAME = "client/aimrecenter/aimrecenter.dat" local function writeCvar(file, cvar) local cvar = CV_FindVar(cvar) file:write(cvar.string, "\n") end local function loadCvar(file, cvar) local value = file:read("*l") COM_BufInsertText(consoleplayer, cvar .. ' "' .. value .. '"') end local function saveCfg(cfgname, p) local file = io.openlocal(cfgname, "w") if file writeCvar(file, "camaimrecenter") writeCvar(file, "camaimrecenter_mode") writeCvar(file, "camaimrecenter_factor") writeCvar(file, "camaimrecenter_threshold") writeCvar(file, "camaimrecenter_delay") file:close() if p then CONS_Printf(p, "Config saved") end else if p CONS_Printf(p, cfgname .. " not found or inaccessible!") else print(cfgname .. " not found or inaccessible!") end end end local function loadCfg(cfgname, p) local file = io.openlocal(cfgname, "r") if file loadCvar(file, "camaimrecenter") loadCvar(file, "camaimrecenter_mode") loadCvar(file, "camaimrecenter_factor") loadCvar(file, "camaimrecenter_threshold") loadCvar(file, "camaimrecenter_delay") file:close() if p then CONS_Printf(p, "Config loaded") end else if p CONS_Printf(p, cfgname .. " not found or inaccessible!") else print(cfgname .. " not found or inaccessible!") end end end --save config command COM_AddCommand("camaimrecenter_save", function(p, arg) --CONS_Printf(p, "Config save") saveCfg(FILENAME, p) end, COM_LOCAL) --load config command COM_AddCommand("camaimrecenter_load", function(p, arg) --CONS_Printf(p, "Config load") loadCfg(FILENAME, p) end, COM_LOCAL) local cv_chasecam = CV_FindVar("chasecam") local cv_chasecam2 = CV_FindVar("chasecam2") --autoload config loadCfg(FILENAME) --dumb camera workaround (krabs) local consoleplayer_camera = nil local function getcam(v, player, camera) consoleplayer_camera = camera end hud.add(getcam, "game") --thinker addHook("PlayerThink", function(p) /* if server and not cv_chasecam and not cv_chasecam.value cv_chasecam.value = 1 end */ p.aiming_centerfactor = cv_camaimrecenter_factor.value p.aiming_threshold = cv_camaimrecenter_threshold.value p.aiming_delay = cv_camaimrecenter_delay.value p.aiming_mode = cv_camaimrecenter_mode.value --p.chasecam_on = cv_chasecam.value p.chasecam_on = true --p.chasecam2_on = cv_chasecam2.value --first person checks if (consoleplayer and consoleplayer_camera and (consoleplayer_camera.chase == true)) --or netgame p.chasecam_on = true else p.chasecam_on = false end --initialize vars if p.aiming_delaytimer == nil then p.aiming_delaytimer = 0 end --debugging printer --print("factor: " .. p.aiming_centerfactor .. ", threshold: " .. p.aiming_threshold .. ", chase: " .. p.chasecam_on .. p.chasecam2_on .. ", mo: " .. tostring(p.mo)) --don't bother recentering if recentering is off or in first person or has no mobj if cv_camaimrecenter.value == 0 or not p.chasecam_on --or (not netgame and not p.chasecam2_on) or not p.mo return end --reset vertical view angle when moving or thokked if (abs(p.mo.momx) > (p.aiming_threshold * p.mo.scale) or abs(p.mo.momy) > (p.aiming_threshold * p.mo.scale)) and (abs(p.cmd.forwardmove) > 0 or abs(p.cmd.sidemove) > 0 or (p.gliding) or (p.pflags & (PF_THOKKED|PF_SPINNING|PF_GLIDING))) p.aiming_delaytimer = $ +1 --active/passive and delay checks if (p.aiming_mode == 0 and p.aiming_delaytimer >= FixedMul(p.aiming_delay, TICRATE)) or p.aiming_mode == 1 p.aiming = FixedMul(p.aiming, p.aiming_centerfactor) end else p.aiming_delaytimer = 0 end end) --save on quit addHook("GameQuit", function() saveCfg(FILENAME) end)