-- 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", { ["msonic"] = true, ["modernsonic"] = true, ["adventuresonic"] = true, }) 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, def, top) local mo = p.mo local powers = (p.powers[pw_super] or p.powers[pw_sneakers]) local pmul = powers and 3*FRACUNIT/5 or 1 local water = mo.eflags & MFE_UNDERWATER and 2 or 1 mo.truespeed = FixedDiv(FixedHypot(p.cmomx- mo.momx, p.cmomy - mo.momy), mo.scale) mo.topspeed = top mo.defspeed = def mo.lastz = $ or mo.z if mo and mo.valid and mo.z > mo.lastz and p.speed >= p.runspeed and P_IsObjectOnGround(mo) then p.normalspeed = $1 - (FRACUNIT - FRACUNIT/3) elseif mo and mo.valid and mo.z < mo.lastz and p.speed >= p.runspeed and P_IsObjectOnGround(mo) then p.normalspeed = $1 + (FRACUNIT - FRACUNIT/3) elseif mo and mo.valid and p.speed >= p.runspeed and P_IsObjectOnGround(mo) then p.normalspeed = max(mo.truespeed*pmul, mo.defspeed)*water end if mo and mo.valid and p.speed > mo.topspeed then p.normalspeed = mo.topspeed end if mo and mo.valid and p.speed < mo.defspeed then p.normalspeed = max(mo.defspeed, mo.defspeed*pmul)*water end mo.truespeed = $1*pmul*water mo.lastz = mo.z end) -- Call the function NOW! addHook("PlayerThink", function(p) if p.mo and p.mo.valid and not NoMomentum[p.mo.skin] then P_ApplyMomentum(p, skins[p.mo.skin].normalspeed, 120*FRACUNIT) end end) -- I command you to use this command when you wanna. COM_AddCommand("applymom", function(p, arg) if p.mo and p.mo.valid and consoleplayer == p 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 no longer applied to " .. p.mo.skin .. ".") NoMomentum[p.mo.skin] = true else CONS_Printf(consoleplayer, "Usage: applymom {1/2} \n1: Apply to current skin \n2: Remove from current skin") end end end)