Skip to content

Instantly share code, notes, and snippets.

@nok-ko
Last active June 1, 2023 00:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nok-ko/7a2b780a54b2029b5d401f9416213aab to your computer and use it in GitHub Desktop.
Save nok-ko/7a2b780a54b2029b5d401f9416213aab to your computer and use it in GitHub Desktop.
Periodic Crosshair Hider, featuring `rpn` (ab)use
// periodic_crosshair.cfg
// Nokko — Xonotic script to periodically turn your crosshair off
// DOES count shots even when weapon is on cooldown, since it's not that easy
// to check the current weapon and whether it's ready to fire.
// Think of it as being wired directly to the "trigger" of the current weapon.
/////////////////////////
// !! USER SETTINGS !! //
/////////////////////////
// Period of the crosshair-hiding.
// E.g. with period 5, shots go [S, H, H, H, H] where S is a visible crosshair
// and H is a hidden one.
set xhair_period 5
// Key that you use to fire your primary weapon.
set fire_key "mouse1"
// Scroll to last line and modify it if you have a "fire" key other than mouse1
////////////////////////////////
// !! END OF USER SETTINGS !! //
////////////////////////////////
// INNER WORKINGS:
// (Don’t edit except to tinker :P)
// (internal cvars)
// This variable controls whether the crosshair will be displayed after the
// player fires their weapon. (Not whether it is currently shown.)
// Start with a xhair, so next state should be hidden
set _xhair_shown 0
// This variable counts from 0 to ($xhair_period - 1) in a loop, incrementing
// each time the fire button is released.
// The crosshair is shown when _shots_fired == 0.
set _shots_fired 0
// (helper aliases)
alias "update_xhair" "rpn /_xhair_shown 1 0 /_shots_fired load /xhair_period load mod 0 eq when def"
// Translation from RPN-ese:
// set _xhair_shown = (_shots_fired % xhair_period == 0) ? 1 : 0)
alias "count_shot" "rpn /_shots_fired /_shots_fired load 1 add /xhair_period load mod def
// Translation from RPN-ese:
// set _shots_fired = ($shots_fired + 1) % $xhair_period)
// (keybind aliases)
// Fire; works like normal
alias "+xhair_fire" "+fire"
// Fire release; normal, then alters crosshair state to match counter, then
// increments counter.
alias "-xhair_fire" "-fire; update_xhair; count_shot; crosshair_enabled $_xhair_shown"
// (keybind)
// Rebind the "fire" key
// Note: default fire bind is just +fire
bind $fire_key "+xhair_fire"
@nok-ko
Copy link
Author

nok-ko commented Jun 1, 2023

(Script is for the game Xonotic.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment