Lua "ThinkFrame" hook - Checking if BT_USE and not PF_USEDOWN does not trigger at all

Flame

WR 102
Lua "ThinkFrame" hook - Checking if BT_USE and not PF_USEDOWN does not trigger at all

Checking to see if the USE (Spin) button is pressed (p.cmd.buttons & BT_USE), and not held down (p.pflags & PF_USEDOWN) fails to trigger. Within the "ThinkFrame" hook for the player.

Example Code Below:
Code:
addHook("ThinkFrame", do
	for p in players.iterate
		if p and p.valid and not p.spectator
			if (p.cmd.buttons & BT_USE) and not (p.pflags & PF_USEDOWN)
				print("trigger once!!")
			end
			
			if (p.cmd.buttons & BT_USE)
				print("trigger for as long the button is held!")
			end
		end
	end
end, MT_PLAYER)

Checking them separately gives accurate results however.
Output text in attachments:
 

Attachments

  • btuseoutput.PNG
    btuseoutput.PNG
    10.5 KB · Views: 219
Last edited:
Writing here what I wrote on Discord.

PF_USEDOWN/PF_JUMPDOWN are set or unset at the end of P_PlayerThink in the source code.
ThinkFrame runs after all thinkers, so it makes sense why you wouldn't be able to
see the previous state of these flags at that point.

There's be a PlayerThink hook in 2.2.1, but this hook runs after those flags are set
as well. There's also a PreThinkFrame hook in 2.2.1, which runs before
P_PlayerThink or any other thinkers. That'll be the best option you have, though it
may worth it for us to consider setting those flags at the end of the tic instead.
 

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

Back
Top