Last active
July 23, 2022 22:17
-
-
Save caligari87/ca20c1547c76fb6f1999a2bfa952463f to your computer and use it in GitHub Desktop.
Small GZDoom zscript function for checking input buttons
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ---------------------------------------- | |
// the default pointer is "self" for use in a custom player class. | |
// For an inventory item it would be owner, etc. | |
// if (KeyCheck(BT_ATTACK, KPT_JUSTPRESSED)) { console.printf("just pressed Attack!"); } | |
// ---------------------------------------- | |
bool KeyCheck(int toCheck, int checkType = KPT_PRESSING, PlayerPawn pointer = null) { | |
if (pointer == null) { pointer = PlayerPawn(self); } // default fallback | |
if (!pointer) { return; } // nullcheck just to be safe | |
int b = pointer.player.cmd.buttons; int ob = pointer.player.oldbuttons; | |
switch (checkType) { | |
case KPT_PRESSING: return (b&toCheck);break; | |
case KPT_JUSTPRESSED: return ((b&toCheck) && !(ob&toCheck));break; | |
case KPT_JUSTRELEASED: return (!(b&toCheck) && (ob&toCheck));break; | |
case KPT_HELD: return ((b&toCheck) && (ob&toCheck));break; | |
}return false; | |
} | |
enum KeyPressTypes { | |
KPT_PRESSING, | |
KPT_JUSTPRESSED, | |
KPT_JUSTRELEASED, | |
KPT_HELD, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment