-- Apply momentum to the player with a speed cap! -- This was built by me, ThatOneCartridgeGuy, for you! -- So, please credit me if you use this in your addon... -- A table for skins that don't benefit from/require momentum. -- And a message for the user when the addon is loaded. if not NoMomentum then rawset(_G, "NoMomentum", {}) print("\x84" + "ApplyMomentum \x80[SRB2 2.2.X]\x84 by ThatCartridgeGuy!") print("\x82" + "Please enjoy, and report any issues to the MB Page. : )") end -- The main function for creating the momentum. -- You could make this way better than I could tbh. rawset(_G, "P_ApplyMomentum", function(p, min, max) local actualSpeed = FixedDiv(FixedHypot(p.cmomx- p.mo.momx, p.cmomy - p.mo.momy), p.mo.scale) local touchwater = p.mo.eflags & MFE_TOUCHWATER if NoMomentum[p.mo.skin] == true then return false end if p.mo and p.mo.valid then p.mo.currz = p.mo.z p.mo.prevz = $ or 0 if p.mo and p.mo.currz < p.mo.prevz and p.speed >= p.runspeed and P_IsObjectOnGround(p.mo) and not p.powers[pw_super] and not p.powers[pw_sneakers] and not p.powers[pw_underwater] then p.normalspeed = actualSpeed+FRACUNIT/2 elseif p.mo and p.mo.currz > p.mo.prevz and p.speed >= p.runspeed and P_IsObjectOnGround(p.mo) and not p.powers[pw_super] and not p.powers[pw_sneakers] and not p.powers[pw_underwater] then p.normalspeed = actualSpeed-FRACUNIT/2 elseif p.mo and P_IsObjectOnGround(p.mo) and p.speed >= p.runspeed and not p.powers[pw_super] and not p.powers[pw_sneakers] and not p.powers[pw_underwater] then p.normalspeed = actualSpeed elseif p.mo and p.mo.currz < p.mo.prevz and p.speed >= p.runspeed and P_IsObjectOnGround(p.mo) and not p.powers[pw_underwater] and (p.powers[pw_super] or p.powers[pw_sneakers]) then p.normalspeed = (3*actualSpeed/5)+FRACUNIT/2 elseif p.mo and p.mo.currz > p.mo.prevz and p.speed >= p.runspeed and P_IsObjectOnGround(p.mo) and not p.powers[pw_underwater] and (p.powers[pw_super] or p.powers[pw_sneakers]) then p.normalspeed = (3*actualSpeed/5)-FRACUNIT/2 elseif p.mo and P_IsObjectOnGround(p.mo) and p.speed >= p.runspeed and not p.powers[pw_underwater] and (p.powers[pw_super] or p.powers[pw_sneakers]) then p.normalspeed = (3*actualSpeed/5) elseif p.mo and p.mo.currz < p.mo.prevz and p.speed >= p.runspeed and P_IsObjectOnGround(p.mo) and not p.powers[pw_super] and not p.powers[pw_sneakers] and p.powers[pw_underwater] then p.normalspeed = 2*actualSpeed+FRACUNIT/2 elseif p.mo and p.mo.currz > p.mo.prevz and p.speed >= p.runspeed and P_IsObjectOnGround(p.mo) and not p.powers[pw_super] and not p.powers[pw_sneakers] and p.powers[pw_underwater] then p.normalspeed = 2*actualSpeed-FRACUNIT/2 elseif p.mo and P_IsObjectOnGround(p.mo) and p.speed >= p.runspeed and not p.powers[pw_super] and not p.powers[pw_sneakers] and p.powers[pw_underwater] then p.normalspeed = 2*actualSpeed elseif p.mo and p.mo.currz < p.mo.prevz and p.speed >= p.runspeed and P_IsObjectOnGround(p.mo) and p.powers[pw_underwater] and (p.powers[pw_super] or p.powers[pw_sneakers]) then p.normalspeed = (6*actualSpeed/5)+FRACUNIT/2 elseif p.mo and p.mo.currz > p.mo.prevz and p.speed >= p.runspeed and P_IsObjectOnGround(p.mo) and p.powers[pw_underwater] and (p.powers[pw_super] or p.powers[pw_sneakers]) then p.normalspeed = (6*actualSpeed/5)-FRACUNIT/2 elseif p.mo and P_IsObjectOnGround(p.mo) and p.speed >= p.runspeed and p.powers[pw_underwater] and (p.powers[pw_super] or p.powers[pw_sneakers]) then p.normalspeed = (6*actualSpeed/5) end if p.mo and p.valid and p.mo.valid and p.speed >= p.runspeed and not P_IsObjectOnGround(p.mo) and not p.powers[pw_underwater] and not p.powers[pw_super] and not p.powers[pw_sneakers] and p.mo.momz <= 0 then p.normalspeed = actualSpeed+FRACUNIT/6 elseif p.mo and p.valid and p.mo.valid and p.speed >= p.runspeed and not P_IsObjectOnGround(p.mo) and p.powers[pw_underwater] and not p.powers[pw_super] and not p.powers[pw_sneakers] and p.mo.momz <= 0 then p.normalspeed = 2*actualSpeed+FRACUNIT/6 elseif p.mo and p.valid and p.mo.valid and p.speed >= p.runspeed and not P_IsObjectOnGround(p.mo) and not p.powers[pw_underwater] and (p.powers[pw_super] or p.powers[pw_sneakers]) and p.mo.momz <= 0 then p.normalspeed = (3*actualSpeed/5)+FRACUNIT/6 elseif p.mo and p.valid and p.mo.valid and p.speed >= p.runspeed and not P_IsObjectOnGround(p.mo) and p.powers[pw_underwater] and (p.powers[pw_super] or p.powers[pw_sneakers]) and p.mo.momz <= 0 then p.normalspeed = (3*actualSpeed/5)+FRACUNIT/6 end if p.mo and p.speed >= max then p.normalspeed = max end if p.mo and p.speed < min and P_IsObjectOnGround(p.mo) then p.normalspeed = min end end p.mo.prevz = p.mo.z end) -- The structure is player_t, minimum normalspeed, maximum normalspeed. addHook("PlayerThink", function(p) if p.mo and p.mo.valid then P_ApplyMomentum(p, skins[p.mo.skin].normalspeed, 120*FRACUNIT) end end) -- 1c Addition! Command to use for applying momentum! local function COMMAND1 if p.mo and p.mo.valid and player == consoleplayer then if tonumber(arg) == 1 then CONS_Printf(consoleplayer, "Momentum applied to " .. p.mo.skin .. ".") NoMomentum[p.mo.skin] = false elseif tonumber(arg) == 2 then CONS_Printf(consoleplayer, "Momentum unapplied to " .. p.mo.skin .. ".") NoMomentum[p.mo.skin] = true else CONS_Printf(consoleplayer, "Usage: applymom {1/2} \n1: Apply to current skin \n2: Unapply to current skin") end end end COM_AddCommand("applymom", COMMAND1) COM_AddCommand("applymom2", COMMAND1, COM_SPLITSCREEN)