(blua bug) player.mo.pmomz does not work inside a PlayerThink hook

Worm

worm
"pmomz" is a variable of the mobj userdata structure that holds the z velocity of the moving floor the object is on (or zero otherwise). If you try to read a player's pmomz while inside a PlayerThink hook, it will always be zero. I've tested it in every other thinker hook (excluding boss and transition thinkers), and it works fine, it's only PlayerThink that fails apparently. This is a problem if you want to do anything that cares about the player's z momentum.

You can easily verify this with a simple script, which is attached as a PK3 and also written out below. There's a moving platform near the start of GFZ2 where you can test.

addHook("PlayerThink", function(player)
print("PlayerThink: " + tostring(player.mo.pmomz))
end)

addHook("MobjThinker", function(mobj)
print("MobjThinker: " + tostring(mobj.pmomz))
end, MT_PLAYER)

addHook("ThinkFrame", function()
for player in players.iterate()
print("ThinkFrame: " + tostring(player.mo.pmomz))
end
end)

I believe this bug is caused by lines 8787 and 8788 of p_user.c, but I'm afraid I'm not gonna learn how to compile SRB2 from source just to delete two lines and test it lol. Anyway, when P_MovePlayer is called, those lines will set pmomz to zero, and P_MovePlayer is called just before the PlayerThink lua hook. I don't understand the purpose of the lines, as they set pmomz to zero if the player is grounded, but pmomz can only be nonzero when the player is grounded. They don't have any comments either, so I truly have no idea if they do anything. You (if you're a dev) would know the codebase better than I.

That's it! It's a small bug so hopefully the fix is simple.
 

Attachments

  • pmomzbug.pk3
    377 bytes · Views: 49

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

Back
Top