Spilled Rings

Status
Not open for further replies.
Is there any way to get the mobj number of the player's spilled rings when they get hit? (In the same sort of manner that you can get the mobj number of an object spawned via P_SpawnMobj)
 
I'm not quite sure what you mean by "mobj number," but I'm assuming you're looking to be able to modify rings that are spilt by the player? I've done some work with spilled rings in the past so maybe this will help.

Hooks like MobjDamage execute as soon as P_DamageMobj is used, which happens to be before the rings are lost—so if you want to find the number of rings the player will spill, simply find player.health - 1 in a MobjDamage hook for MT_PLAYER. If you instead want to modify rings once they are spilled, you can use a MobjThinker hook for MT_FLINGRING. They conveniently set their target to the player that spilled them, so you can use mobj.target to find the player that spilled that flingring! MobjSpawn might be more efficient depending on what you're trying to do but unfortunately that occurs before the ring sets its target to the player, so its use is limited.

Hopefully that answers your question, but if not could you be a little more specific? :)
 
I'm attempting to remake the Combi Ring powerup (the one that makes you drop one big ring when you get hit, with the value of all the rings you lost), or at least, it's effects.

With what you've told me, I was able to modify the ring's attributes (it's scale, and adding a variable for it's worth), but now I'm having trouble with the TouchSpecial part of it, for when the player actually goes to pick the ring up.

addHook("TouchSpecial", function(mobj,toucher)
if mobj.ringvalue != nil
toucher.health = $1 + mobj.ringvalue
toucher.player.health = $1 + mobj.ringvalue
end
end, MT_FLINGRING)

The problem is that the moment the player gets hit, the code runs while the ring is still flying away, each frame, causing the player to gain hundreds of rings. I think there might be a way to stop that via checking player.losstime, but I'm not sure how to go about calculating that, or if there's a better way.
 
Well hey, speak of the devil. That is the exact modification I was working on myself. Let me know if you'd like to take a look at it.

In any case, the best way to do this (and the way that I did it) is to put that code in a MobjDeath hook rather than a TouchSpecial, so that it only occurs when the ring actually "dies" (since the player "kills" the ring when touching it). Don't forget the ring itself will count as a ring when adding to the total, although maybe you accounted for that already.
 
Try P_CanPickupItem(toucher.player), it's the function MT_RING and MT_FLINGRING objects use themselves to prevent themselves being picked up after being created, or in general when the player is flashing after being hurt.

Basically it checks the player's pw_flashing to determine whether the item can be picked up or not.
 
Last edited:
Yeah, P_CanPickupItem works like a charm. With that, it seems to work perfectly! Thank you to the both of you for helping me out with this.
 
I still recommend using the MobjDeath hook as it is more efficient (since the game only runs the code on the single frame the ring dies as opposed to every frame it is touched), but I'm glad you got it to work either way! No problem.
 
Status
Not open for further replies.

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

Back
Top