Altering player collision with a particular enemy

Status
Not open for further replies.

Goldenhog

Wandering Protagonist
I have this enemy whom I want to make the player bounce higher than usual and force them out of their spinning frames when they bop it. I'd also like it if this enemy didn't award the player points or release a flicky when destroyed. The former could (maybe?) be done by placing a custom Lua action in the enemy's death frames that grabs the nearest player, A_ZThrusts them upwards and forces their state to S_PLAY_FALL1, but I have no idea where to start with the latter (making the enemy award no points and stopping flickies from appearing).
 
If a Lua function added to the MobjDeath hook returns true, it'll override the killed object's default death behavior.
 
That sounds just like what I need. Sadly the last time I worked with hooks was years ago (the only thing I'm using Lua for right now is to call functions and actions to do the actual job for me) so I'm a bit out of my depth here.

Code:
local function walkerbounce(target,inflictor,source)
    if inflictor.player
        P_DoPlayerPain(inflictor.mo,target,target)
        return true
    end
end

addHook("MobjDeath", walkerbounce, MT_WALKER)
From what I read in the wiki pages and surmised from my old Gravity Shield code, this should be working? It calls the function walkerbounce when MT_WALKER is destroyed, which then checks if the thing that destroyed it is a player and then should have the player get hit (to test if it's working) with no other effects like points or flickies. But in-game it's all behaving the same as if this code wasn't here at all.
 
Code:
local function walkerbounce(target,inflictor,source)
    if inflictor.player
        P_DoPlayerPain(inflictor.mo,target,target)
        return true
    end
end
 addHook("MobjDeath", walkerbounce, MT_WALKER)
From what I read in the wiki pages and surmised from my old Gravity Shield code, this should be working? -
It shouldn't be working. You accidentally wrote "inflictor.mo" instead of "inflictor.player" in the P_DoPlayerPain function (the function expects a player, not an object), and if the first player uses player node 0, you should probably check something like "if inflictor.player.valid" instead of "if inflictor.player" (as 0 is considered false by "if" checks).
 
Thanks for the heads up, but those alone didn't help.

But I did manage to figure it out. The game wasn't entering the hook at all (I added a print to the hook before the if and sure enough it was never getting fired). It does enter the hook if I leave MT_WALKER out or replace it MT_NULL, and if I add additional checks to see if target is the right type then it all works properly.

And it's all the fault of the game running Lua scripts before SOC ones. If I move declaring MT_WALKER from the MAINCFG to the lump where the Lua code is, then having MT_WALKER at the end of the addHook like I did before works like it should.

Anyway, thanks to the both of you for the help.
 
Status
Not open for further replies.

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

Back
Top