-- by lexidog :3 local CRUSH_RESISTANCE_LIMIT = 10 * TICRATE local DEATHPIT_TELEPORT_RESISTANCE_LIMIT = 4 local DEATHPIT_TELEPORT_VULNERABILITY_LIMIT = 4 * TICRATE local DEATHPIT_LAUNCH_SPEED = 3 * FRACUNIT local DEATHPIT_LAUNCH_SPEED_MINIMUM = 16 * FRACUNIT local DEATHPIT_LAUNCH_COOLDOWN_LIMIT = 2 local crusherLeniency = CV_RegisterVar( { name = "crusherleniency"; defaultvalue = "On"; flags = CV_NETVAR|CV_SHOWMODIF; PossibleValue = CV_OnOff; } ) local deathPitLeniency = CV_RegisterVar( { name = "deathpitleniency"; defaultvalue = "Teleport"; flags = CV_NETVAR|CV_SHOWMODIF; PossibleValue = {Off = 0, Bounce = 1, Teleport = 2}; } ) local function updateLastGroundedPosition(mobj) if mobj.valid then mobj.lastgroundedx = mobj.x mobj.lastgroundedy = mobj.y mobj.lastgroundedz = mobj.z mobj.lastgroundedangle = mobj.angle end end addHook("ShouldDamage", function(target, inflictor, source, damage, damagetype) if (damagetype == DMG_CRUSHED and crusherLeniency.string == "On") or (damagetype == DMG_DEATHPIT and deathPitLeniency.string ~= "Off") then local player = target.player if damagetype == DMG_CRUSHED then player.crushresistance = $ - 3 if player.crushresistance <= 0 then return end end if damagetype == DMG_DEATHPIT and ( (deathPitLeniency.string == "Bounce" and player.deathpitlaunchcooldown < DEATHPIT_LAUNCH_COOLDOWN_LIMIT) or (deathPitLeniency.string == "Teleport" and (player.deathpitteleportresistance <= 1 or not P_CheckPosition(target, target.lastgroundedx, target.lastgroundedy))) ) then return end local storedMomZ = target.momz P_DamageMobj(target, inflictor, source) if damagetype == DMG_DEATHPIT and player.playerstate == PST_LIVE then if deathPitLeniency.string == "Bounce" then target.state = S_PLAY_JUMP player.pflags = $ | PF_JUMPED player.pflags = $ & ~PF_THOKKED player.pflags = $ & ~PF_SHIELDABILITY target.momx = 0 target.momy = 0 local newMomZ = abs(storedMomZ) + DEATHPIT_LAUNCH_SPEED if newMomZ < DEATHPIT_LAUNCH_SPEED_MINIMUM then newMomZ = DEATHPIT_LAUNCH_SPEED_MINIMUM end P_SetObjectMomZ(target, newMomZ, false) player.deathpitlaunchcooldown = 0 S_StartSound(target, sfx_sprong) elseif deathPitLeniency.string == "Teleport" then target.momx = 0 target.momy = 0 P_SetObjectMomZ(target, 0, false) P_ResetPlayer(player) P_SetOrigin(target, target.lastgroundedx, target.lastgroundedy, target.lastgroundedz) target.angle = target.lastgroundedangle player.powers[pw_nocontrol] = TICRATE / 2 player.deathpitteleportresistance = $ - 1 player.deathpitteleportvulnerability = DEATHPIT_TELEPORT_VULNERABILITY_LIMIT P_FlashPal(player, PAL_MIXUP, 10) S_StartSound(target, sfx_mixup) end end return false end end, MT_PLAYER) addHook("PlayerSpawn", function(player) player.crushresistance = CRUSH_RESISTANCE_LIMIT player.deathpitlaunchcooldown = DEATHPIT_LAUNCH_COOLDOWN_LIMIT player.deathpitteleportresistance = DEATHPIT_TELEPORT_RESISTANCE_LIMIT player.deathpitteleportvulnerability = 0 player.recentlyonconveyor = 0 if player.mo and player.mo.valid updateLastGroundedPosition(player.mo) end end) addHook("PlayerThink", function(player) local playerMobj = player.mo if player.mo and player.mo.valid if player.crushresistance == nil then player.crushresistance = CRUSH_RESISTANCE_LIMIT end if player.deathpitlaunchcooldown == nil then player.deathpitlaunchcooldown = DEATHPIT_LAUNCH_COOLDOWN_LIMIT end if player.deathpitteleportresistance == nil then player.deathpitteleportresistance = DEATHPIT_TELEPORT_RESISTANCE_LIMIT end if player.deathpitteleportvulnerability == nil then player.deathpitteleportvulnerability = 0 end if player.recentlyonconveyor == nil then player.recentlyonconveyor = 0 end if player.crushresistance < CRUSH_RESISTANCE_LIMIT then player.crushresistance = $ + 1 end if player.deathpitteleportvulnerability > 0 then player.deathpitteleportvulnerability = $ - 1 end if player.deathpitteleportvulnerability <= 0 then player.deathpitteleportresistance = DEATHPIT_TELEPORT_RESISTANCE_LIMIT end if player.recentlyonconveyor > 0 then player.recentlyonconveyor = $ - 1 end if player.onconveyor ~= 0 then player.recentlyonconveyor = TICRATE / 4 end if playerMobj.lastgroundedx == nil or playerMobj.lastgroundedy == nil or playerMobj.lastgroundedz == nil or playerMobj.lastgroundedangle == nil then updateLastGroundedPosition(playerMobj) end if P_IsObjectOnGround(playerMobj) then if player.deathpitlaunchcooldown < DEATHPIT_LAUNCH_COOLDOWN_LIMIT then player.deathpitlaunchcooldown = $ + 1 end if P_CheckPosition(playerMobj, playerMobj.x, playerMobj.y) and player.recentlyonconveyor <= 0 then updateLastGroundedPosition(playerMobj) end end end end)