For a single frame instead of being balled up, I'm in a standing postition making me vulnerable.

Vestige

Member
script I'm creating (I'm inexperianced):
freeslot("VEST_SPRT", "BAR_SPRT")

local button = BT_CUSTOM1
local bounceButton = BT_SPIN
local skin = "vestige"
local starttimer = 100
local dash_drain_per_tick = 20
local bounce_force = 15 * FRACUNIT
local bounce_cooldown_max = 12
local bounce_force_dividend = 10
local max_dashes_per_airtime = 3




-- Helper Functions
local function SpeedBoost_Reset(p)
    local mo = p.mo
    if mo and mo.skin == skin then
        p.normalspeed = skins[skin].normalspeed
        p.jumpfactor = skins[skin].jumpfactor
        p.charflags = p.charflags & ~SF_RUNONWATER
        p.camerascale = skins[skin].camerascale
        p.acceleration = skins[skin].acceleration 
        p.accelstart = skins[skin].accelstart       
        mo.blendmode = AST_COPY
        mo.colorized = false
        mo.color = p.skincolor
        bounce_force_dividend = 7
    end
end

local function SpeedBoost_start(p, overcharge)
    local mo = p.mo
    if mo and mo.skin == skin then
        p.charflags = p.charflags | SF_RUNONWATER
        p.normalspeed = skins[skin].normalspeed - 10
        p.jumpfactor = skins[skin].jumpfactor + (p.jumpfactor / 5)
        p.acceleration = skins[skin].acceleration - 25
        p.camerascale = skins[skin].camerascale + (p.camerascale / 9) + overcharge
        mo.blendmode = AST_SUBTRACT
        mo.colorized = true
        p.accelstart = 400
        mo.color = SKINCOLOR_POWER
        bounce_force_dividend = 4
    end
end

local function afterimage(p)
    local mo = p.mo
    local trail = P_SpawnGhostMobj(mo)
    trail.flags = $|MF_NOCLIP|MF_NOCLIPHEIGHT|MF_NOGRAVITY|MF_SCENERY
    trail.scalespeed = FRACUNIT/9
    trail.angle = mo.angle
    trail.color = mo.color
    trail.scale = mo.scale
    trail.blendmode = AST_ADD
    trail.colorized = true
    trail.fuse = 6
    trail.destscale = mo.scale
    trail.scalespeed = $*2

end


local function Bounce(p)
        if (maptol & TOL_NIGHTS) then
        return
    end

    local mo = p.mo
    if not mo or mo.skin ~= skin or p.playerstate ~= PST_LIVE then return end
        if P_PlayerInPain(p) then
                return

            end
    
 
    if not mo.vestige then mo.vestige = {} end
    local data = p.vestige

    if (p.cmd.buttons & bounceButton)
    and not P_IsObjectOnGround(mo)
    and not data.dashing
    and not (p.pflags & PF_THOKKED)
    and (p.pflags & PF_JUMPED or p.pflags & PF_SPINNING)
    and (data.bounce_cooldown or 0) <= 0 then
        bounce_force = min(((p.speed / 100000 / bounce_force_dividend) + 3 + abs(mo.momz / 10000) / bounce_force_dividend), 30)
        P_SetObjectMomZ(mo, bounce_force * FRACUNIT * -5)
        
        mo.state = S_PLAY_JUMP
         afterimage(p)
        p.pflags = $ | PF_THOKKED
        S_StartSound(mo, sfx_bnce2, p)
        data.dash_energy = max(0, data.dash_energy - 20)
        if mo.eflags & MFE_SPRUNG then
            data.want_to_bounce = false
            data.bounce_cooldown = 0
         else
             data.want_to_bounce = true
        end
    end

    if data.want_to_bounce and P_IsObjectOnGround(mo) then
        p.pflags = $ | PF_SPINNING
        P_RadiusAttack(p.mo, p.mo, 100*FRACUNIT, DMG_INSTAKILL, p)
        P_SetObjectMomZ(mo, bounce_force * FRACUNIT)
        mo.state = S_PLAY_JUMP
        P_StartQuake(10 * FRACUNIT, TICRATE / 2)
        S_StartSound(mo, sfx_bnce2, p)
        data.want_to_bounce = false
        data.bounce_cooldown = bounce_cooldown_max
        end

    if data.bounce_cooldown and data.bounce_cooldown > 0 then
        data.bounce_cooldown = $ - 1
    end

end


--- runs bouncing
addHook("PlayerThink", Bounce)
    



-- Main Logic
addHook("PlayerThink", function(p)

        if (maptol & TOL_NIGHTS) then
        return
    end
    
    if not p.mo or p.mo.skin ~= skin or p.playerstate ~= PST_LIVE then return end
        if P_PlayerInPain(p) then
                return

            end


    if not p.vestige then
        p.vestige = {
            dash_energy = 0,
            notdashingtimer = 20,
            dashing = false,
            can_dash = true,
            combo = 0,
            combo_timer = 0,
            combo_score = 0,
            energy_force = 0,
            bounce_cooldown = 0,
            dashes_in_air = 0
        }
    end

    local data = p.vestige
 

    if (p.mo.eflags & MFE_UNDERWATER) then
        data.energy_force = 30
    else
        data.energy_force = 60
    end

    data.dash_energy = tonumber(data.dash_energy) or 0
    data.combo = data.combo or 0
    data.combo_timer = data.combo_timer or 0
    data.combo_score = data.combo_score or 0
    data.notdashingtimer = data.notdashingtimer or 20
    data.energy_force = data.energy_force or 0
    data.bounce_cooldown = data.bounce_cooldown or 0
    data.dashes_in_air = data.dashes_in_air or 0

    local dash_energy = data.dash_energy
    local overcharged = (dash_energy > starttimer) and (dash_energy - starttimer) or 0

    if not data.dashing then
        data.notdashingtimer = data.notdashingtimer - 1
        p.mo.dashtime = 0
    end

    -- Reset dash count when landing
    if P_IsObjectOnGround(p.mo) then
        data.dashes_in_air = 0
    end

    if dash_energy < starttimer / (1 + (1 / 2)) then
        data.dash_energy = $1 + 20
        SpeedBoost_Reset(p)
    else
        SpeedBoost_start(p, overcharged)
        if dash_energy < starttimer then
            data.dash_energy = $1 + (1 / 2)
        end
    end
 
    if data.dashing == true then

        if not p.cmd.forwardmove then
                p.cmd.forwardmove = 50 --Intentionally not in PreThinkFrame
            end

          
        data.dash_energy = dash_energy - dash_drain_per_tick
        if data.dash_energy <= 0 or (not (p.cmd.buttons & button) and p.playerstate == PST_LIVE) and not P_PlayerInPain(p) then
            data.dashing = false
            p.mo.dashtime = 0
            p.charflags = p.charflags & ~SF_CANBUSTWALLS
            p.cmd.forwardmove = 50
        else
            -- Continue dashing
            p.mo.dashtime = p.mo.dashtime + 1
            afterimage(p)
            p.charflags = p.charflags | SF_CANBUSTWALLS
            p.pflags = p.pflags & ~PF_SPINNING
            P_InstaThrust(p.mo, p.drawangle, abs(data.energy_force + p.speed / 2000000) * FRACUNIT)
    
            data.dashing = true
            p.pflags = p.pflags & ~PF_SPINNING
            if P_IsObjectOnGround(p.mo) then
                p.mo.state = S_PLAY_RUN
        --        p.powers[pw_invulnerability] = TICRATE / 2

                p.mo.speed = ((p.speed + (p.speed / 2)) / FRACUNIT) + sin(p.mo.angle) + 4 * FRACUNIT
                P_SpawnSkidDust(p, p.mo.radius, true)
                p.mo.state = S_PLAY_RUN
            elseif p.pflags & PF_JUMPED and p.mo.dashtime <= 9 then
                p.mo.state = S_PLAY_JUMP
                p.mo.momz = ((p.speed + (p.speed / 2)) / FRACUNIT) + sin(p.mo.angle) + 4 * FRACUNIT
            end

        end
    end


    if not (p.cmd.buttons & button) then
        if not data.dashing and data.notdashingtimer <= 0 then
            data.can_dash = true
            data.notdashingtimer = 20
        end
    else

        if not data.dashing and data.can_dash and dash_energy >= 20 and data.dashes_in_air < max_dashes_per_airtime then
            data.can_dash = false
            p.mo.dashtime = 1
            data.dashing = true
            data.dashes_in_air = data.dashes_in_air + 1
            afterimage(p)
            P_Thrust(p.mo, p.drawangle, abs(data.energy_force * 5) * FRACUNIT)     
            S_StartSound(p.mo, sfx_vboost, p)
            P_StartQuake(10*FRACUNIT, TICRATE / 2)
            data.spritexscale = FRACUNIT * 6
            data.spriteyscale = FRACUNIT * -6
            if p.mo.state == S_PLAY_STND
                or p.mo.state == S_PLAY_WALK
                or p.mo.state == S_PLAY_WAIT
                or p.mo.state == S_PLAY_EDGE then
                p.mo.state = S_PLAY_RUN
            end
        end
    end
end)

addHook("MobjMoveBlocked", function(mo)
    if not (mo and mo.player) then return end   
    local p = mo.player
    local data = p.vestige
    if not data or not data.dashing then return end

    -- stop dash
    data.dashing = false
    data.can_dash = false

    local speed = R_PointToDist2(0,0, mo.momx, mo.momy)

    local bounce_angle = mo.angle + ANGLE_180
    S_StartSound(mo, sfx_mario1, p)


 --  print("Thrustforce: " .. speed)
    P_StartQuake(10 * FRACUNIT, TICRATE / 2)

    P_InstaThrust(mo, bounce_angle, speed / 20)
    p.pflags = p.pflags & ~PF_SPINNING

    P_SetObjectMomZ(mo, speed / 2000000 * FRACUNIT, false)

    mo.state = S_PLAY_PAIN
end)

addHook("MobjDamage", function(target, inf, src, dmg, dmgType)
    if target.player and target.player.vestige and target.skin == skin then
        local data = target.player.vestige
        if data.dashing == true then
            if dmgType == DMG_FIRE or dmgType == DMG_WATER or dmgType == DMG_ELECTRIC
            or dmgType == DMG_SPIKE or dmgType == DMG_NUKE or dmgType == DMG_DROWNED
            or dmgType == DMG_CRUSHED or dmgType == DMG_CANHURTSELF then
                return true
            end
        end
    end
end, MT_PLAYER)


for _, spike in ipairs({MT_SPIKE, MT_WALLSPIKE}) do
    addHook("MobjCollide", function(mobj, playermobj)
        if playermobj.player and playermobj.player.vestige and playermobj.skin == skin then
            local data = playermobj.player.vestige
            if data.dashing == true and (mobj.z >= (playermobj.z - 16*FRACUNIT)) and (mobj.z <= (playermobj.z + playermobj.height + 16*FRACUNIT)) then
                P_KillMobj(mobj, playermobj, playermobj)
                data.dash_energy = data.dash_energy + 10
            end
        end
    end, spike)
end

addHook("PlayerCanDamage", function(p) -- Player kills enemies while boosting
    if p.vestige and p.vestige.dashing then
        p.vestige.dash_energy = max(p.vestige.dash_energy + 10, 100)
        return true
    end
end)



addHook("MobjCollide", function(mobj, playermobj)
    if playermobj.player and playermobj.player.vestige and playermobj.skin == skin then   
        local data = playermobj.player.vestige
        if playermobj.player and playermobj.player.vestige and playermobj.skin == skin and mobj.flags & MF_MONITOR
        and data.dashing == true then
            P_DamageMobj(mobj, playermobj, playermobj, 5, DMG_INSTAKILL)
        end
    end
end)






addHook("PlayerSpawn", function(p)
    if p.mo and p.mo.skin == skin then
        p.vestige = {
            dash_energy = 0,
            dash_penalty = 0,
            dashed_once = false,
        }
    end
end)
 

Attachments

  • srb20000.gif
    srb20000.gif
    2.9 MB · Views: 77

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

Back
Top