VanishingPoint
Member
I've given Sonic the ability to choose between two different situational midair abilities depending on whether or not the spin key is held down when the jump key is tapped. Because it requires use of the spin key in midair, if a player is wearing a shield with an ability attached, conflictions occur. What I believe to be my best bet is to provide a buffer in between the pressing of the spin key and the activation of the shield ability, as to give the player time to use the spin-key-related character ability before the shield ability activates.
In other words, the idea is, when the player starts holding the spin key, a timer is set. Once the timer reaches zero, the shield ability will be activated if the player has not yet touched the ground. if the player has landed, started to hang on to something, performed a char. ability, or let go of the spin key, the timer is reset. The timer should not effect the player's ability to use the spin-held char. ability, and as such there is a chance to use it before or after the shield ability is allowed to activate. My code as of yet is as follows:
This only partially reflects my idea, with the current status being that the shield buffer (timer) is (re)set at some of the appropriate times and continuously counts down at all other times- Any perceivable functionality is nonexistent, as one may have guessed. I would like to know, besides (insert title here), if there is an easier way to activate a shield ability at a custom time than recreating each one using SRB2's provided functions (which I predict becomes a chore in the case of the Elemental and S3&K shields)?
In other words, the idea is, when the player starts holding the spin key, a timer is set. Once the timer reaches zero, the shield ability will be activated if the player has not yet touched the ground. if the player has landed, started to hang on to something, performed a char. ability, or let go of the spin key, the timer is reset. The timer should not effect the player's ability to use the spin-held char. ability, and as such there is a chance to use it before or after the shield ability is allowed to activate. My code as of yet is as follows:
Lua:
addHook("PlayerSpawn", function(player)
if (player.mo.skin ~= "sonic") then // no service
return
end
player.canAbility = false
player.underwaterDivisor = 1
player.shieldBuffer = 0
end)
addHook("PlayerThink",function(player)
if (player.mo.skin ~= "sonic") then // no service
return
end
if player.shieldBuffer > 0
player.shieldBuffer = $ - 1
if player.shieldBuffer < 0
player.shieldBuffer = 0
end
if P_IsObjectOnGround(player.mo) or (player.mo.state == S_PLAY_RIDE) then
player.canAbility = true
end
if (player.mo.eflags & MFE_UNDERWATER) then
player.underwaterDivisor = 2 // to prevent shenanigans in DSZ
else
player.underwaterDivisor = 1
end
end)
addHook("AbilitySpecial",function(player)
if (player.mo.skin ~= "sonic") then // no service
return false
end
if player.canAbility then
if (player.cmd.buttons & BT_SPIN) then // use the vertical!
if (abs(player.mo.momx) + abs(player.mo.momy) > (4/player.underwaterDivisor)*FRACUNIT) then // slow sonic way down
A_Thrust(player.mo,4/player.underwaterDivisor,1)
end
A_ZThrust(player.mo,16/player.underwaterDivisor,(1<<FRACBITS)+0)
else // use the airlunge!
if (abs(player.mo.momx) + abs(player.mo.momy) < (32/player.underwaterDivisor)*FRACUNIT) then // get sonic up to speed if he's not already
A_Thrust(player.mo,32/player.underwaterDivisor,1)
else // otherwise, simply redirect momentum
A_Thrust(player.mo,((abs(player.mo.momx) + abs(player.mo.momy))/FRACUNIT)-2,1)
end
A_ZThrust(player.mo,8/player.underwaterDivisor,(1<<FRACBITS)+0)
end
player.canAbility = false
end
return true
end)
addHook("ShieldSpecial",function(player)
if (player.mo.skin ~= "sonic") then // no service
return false
end
if (player.powers[pw_shield] ~ SH_NONE|SH_PITY|SH_PINK|SH_FIREFLOWER) then // pretty pink fire flower!
if not (player.cmd.buttons & BT_SPIN) then
player.shieldBuffer = 1*TICRATE
end
end
end)
This only partially reflects my idea, with the current status being that the shield buffer (timer) is (re)set at some of the appropriate times and continuously counts down at all other times- Any perceivable functionality is nonexistent, as one may have guessed. I would like to know, besides (insert title here), if there is an easier way to activate a shield ability at a custom time than recreating each one using SRB2's provided functions (which I predict becomes a chore in the case of the Elemental and S3&K shields)?