Sonic 3 Shield Projectile Deflect

Rodriv64

Member
Hello! I'm trying to make a lua script that makes so if a player has a shield, even when standing, the shield would deflect most projectiles, a-la Sonic 3 & Knuckles. I tried making this code, but it doesn't work, idk what's wrong
Shield Deflect code:
addHook("PlayerThink", function(p)
    if p.mo and p.mo.valid
        if p.powers[pw_shield]
            if mo and mo.valid and ((mo.flags & MF_SHOOTABLE) or (mo.flags & MF_MISSILE) or (mo.flags & MF_PAIN))
                P_KillMobj(target,inf,src)
            end
        end
    end
end)
Could someone help me?
 
Hello! I'm trying to make a lua script that makes so if a player has a shield, even when standing, the shield would deflect most projectiles, a-la Sonic 3 & Knuckles. I tried making this code, but it doesn't work, idk what's wrong
Shield Deflect code:
addHook("PlayerThink", function(p)
    if p.mo and p.mo.valid
        if p.powers[pw_shield]
            if mo and mo.valid and ((mo.flags & MF_SHOOTABLE) or (mo.flags & MF_MISSILE) or (mo.flags & MF_PAIN))
                P_KillMobj(target,inf,src)
            end
        end
    end
end)
Could someone help me?
Most of the stuff on this script are in the wrong hook type. For stuff like this, you would want the "ShouldDamage" hook, which runs when an object recieves damage.

The arguments for the "ShouldDamage"'s function are...: function(target, inflictor, source, damage, damagetype)
target is the object about to recieve damage
inflictor is the object that will damage target
source is the object where inflictor comes from
damage is the amount of damage player is recieving
damagetype is the type of damage player is recieving (ie.: Fire damage would be DMG_FIRE)

If the function of this hook returns false, the damage behavior will be canceled.
If the function of this hook returns true/nil, the damage behavior will continue.

There's also an extra argument for this hook, which specifies the object type that should activate this hook



I've also made a fixed version of your script with the "ShouldDamage" hook:
Projectile deflection for shields:
addHook("ShouldDamage", function(mobj, inf, src)
    if mobj
    and mobj.valid
    and mobj.health
    and mobj.player
    and mobj.player.powers[pw_shield]
    and mobj.player.powers[pw_shield] != SH_FIREFLOWER
    and inf
    and inf.valid
    and inf.flags & MF_MISSILE
        P_KillMobj(inf, mobj)
        return false
    end
end, MT_PLAYER)

srb20084.gif
 

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

Back
Top