A quick question.

Status
Not open for further replies.

Lat'

Absolute territory where
Kart Krew™️
The title. How can I make it so hurt players lose only 1 Ring instead of all of them? (Obviously Lua, I guess.)
Thanks in advice.
 
Set up a MobjDamage hook for MT_PLAYER and wire in the code you want, then return true at the end to override the normal damage effect. You'll have to re-create the standard effects you want, but the knockback is as easy as calling P_DoPlayerPain(mo, inflictor, source) or something like that, then you can spawn an MT_FLINGRING, send it flying out how you want, and subtract one from mo.health and mo.player.health.
 
Code:
local function RingLoss (me, bomb, bombguy, pain)
	if not me.player
		return false // this used to limit it to one skn, I guess I can use this as a validity check?
	end

	local player = me.player // let's make things easier and use this as a shortcut to writing me.player.anything!

	P_DoPlayerPain(player, bombguy, bomb) // send yourself into the pain animation
	S_StartSound(player.mo, sfx_s3kb9) //hurt sound
	
	player.health = max($1 - pain, 0) // remove damage from health, set to 0 if this goes under 0!
	me.health = $1 - pain // do the same for the mobj part of the player, doesn't matter about keeping it above 0 apparently
	P_PlayerRingBurst(player,1) //spill a ring
	
	if me.health < 1
		P_DamageMobj(me, bomb, bombguy,10000)
		P_KillMobj(me,bomb,bombguy)
		return true // you're dead, that's it, no point to continuing!
	end
	return true // that's it, we just end P_DamageMobj right here, nothing else happens with damaging after this
end
addHook("MobjDamage", RingLoss, MT_PLAYER)

Ripped straight from Quickman, then did a few adjustments on it to suit your needs. Thankfully MonsterIestyn had done all the commenting beforehand so you can understand what's going on easily.

(pain is by default 1 btw)
 
Code:
Insert lua code here.

Ripped straight from Quickman, then did a few adjustments on it to suit your needs. Thankfully MonsterIestyn had done all the commenting beforehand so you can understand what's going on easily.

(pain is by default 1 btw)

Thanks, this skips me a lot of work ^^
I guess I'll have to learn Lua more, because even if I understood most of the things in there I couldn't do it myself ><
Anyway I guess this solves my problem
 
There's also something else to consider, the script above needs a condition so that it can also work when the player that's been hit has a shield.

Plus remember that getting hit in match won't award points to whoever hits you, or show a text saying how you got hit, or have the typical knockback of the weapon used on you, unless all these things are added in the script too.

And the last part of the script that runs only if me.health < 1 isn't really needed, I'd rather have the "hit" part of the script run only if you have at least one ring.



EDIT: Would making the player have only one ring as he gets hit be a valid alternative?
Code:
local function RingLoss (me)
    if not me.player or me.player.health == 1 or me.player.powers[pw_shield] != 0
        return false // 
    end
 
        me.player.lastrings = me.player.health //
        me.player.health = 2 // 
    me.health = 2 // 
    me.player.playerhit = 1 //
    return false // 
end
addHook("MobjDamage", RingLoss, MT_PLAYER)
addHook("ThinkFrame", function ()
        for player in players.iterate
                if player.playerhit == 1
                      player.health = player.lastrings - 1
                      player.mo.health = player.lastrings - 1
                      player.playerhit = 0
                end 
        end
end)
 
Last edited:
Status
Not open for further replies.

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

Back
Top