Concept - Expose Instawhip mobj to Lua
Very simple edit that as far as I can tell has no adverse effects.
The problem that drove me to make this branch (if you can even call it that) is that right now for Lua scripters there is no exposed variable on the player to precisely track when a player is or isn't instawhipping. When an instawhip is released, for example, the logic to track how long the mobj
that represents the instawhip (player->whip
) is to exist for is handled entirely by the generalized mobj->fuse
field being set to the INSTAWHIP_DURATION
constant which of course is inaccessible if the player->whip
mobj
is itself inaccessible.
mobj_t *whip = P_SpawnMobj(player->mo->x, player->mo->y, player->mo->z, MT_INSTAWHIP);
P_SetTarget(&player->whip, whip);
[...]
whip->fuse = INSTAWHIP_DURATION;
The solution was to treat player->whip
like any other mobj
pushed and pulled to and from Lua in player_set()
and player_get()
respectively.
player_get()
else if (fastcmp(field,"whip"))
LUA_PushUserdata(L, plr->whip, META_MOBJ);
player_set()
else if (fastcmp(field,"whip"))
{
mobj_t *mo = NULL;
if (!lua_isnil(L, 3))
mo = *((mobj_t **)luaL_checkudata(L, 3, META_MOBJ));
P_SetTarget(&plr->whip, mo);
}
Following just these two edits, I created a test script designed to respond to the changes:
addHook("PostThinkFrame",function()
for player in players.iterate do
if(player.whip~=nil)
player.whip.state = S_BLUESPHERE
CONS_Printf(player,"i'm whippin it | "..leveltime)
end
end
end)
As one can see in-game, it works exactly as intended:
ringracers_expose-whip-to-lua_zO9KeONtZw
If I'm so sure of myself then why mark the merge request as a "Concept"?
That's because to be frank I do not know the codebase very well at all and only barely know how Lua is integrated into the project. I don't know if what I'm suggesting is ridiculous and would have all kinds of adverse effects in places like memory management off the top of my head, I just thought I should make the merge request in case Kart Krew were not aware of this problem and therefore didn't realize how simple the fix might be.