-- ghost trail by lemin -- v 1.0 local ghost_mobj = nil local player_mobj = nil local last_breadcrumb = nil local breadcrumb_type = MT_THOK local function calculateDistance(x1, y1, z1, x2, y2, z2) -- Calculate the difference in the XY plane using FixedHypot local xyDistance = FixedHypot(x2 - x1, y2 - y1) -- Calculate the difference in the Z direction local dz = z2 - z1 -- Now calculate the total 3D distance using these two values return FixedHypot(xyDistance, dz) end local function spawnBreadcrumb(x, y, z, scale, type) local breadcrumb = P_SpawnMobj(x, y, z, type) breadcrumb.scale = FRACUNIT * scale breadcrumb.renderflags = RF_FULLBRIGHT breadcrumb.blendmode = AST_ADD breadcrumb.color = SKINCOLOR_YELLOW last_breadcrumb = breadcrumb end addHook("PlayerThink", function(player) if modeattacking == true then player_mobj = player.mo else player_mobj = nil end end) addHook("MobjThinker", function(mobj) if modeattacking == true and leveltime > 2 then if mobj.type == MT_GHOST and ghost_mobj == nil then ghost_mobj = mobj end if mobj == ghost_mobj then local distanceFromPlayer = calculateDistance(mobj.x, mobj.y, mobj.z, player_mobj.x, player_mobj.y, player_mobj.z) local distanceFromLastBreadcrumb = 1000001 -- yes this is kinda dumb but it works if last_breadcrumb ~= nil then distanceFromLastBreadcrumb = calculateDistance(mobj.x, mobj.y, mobj.z, last_breadcrumb.x, last_breadcrumb.y, last_breadcrumb.z) end if distanceFromPlayer > 10000000 and distanceFromLastBreadcrumb > 1000000 then spawnBreadcrumb(mobj.x, mobj.y, mobj.z, 1, breadcrumb_type) end end if mobj.type == breadcrumb_type then local distance = calculateDistance(mobj.x, mobj.y, mobj.z, player_mobj.x, player_mobj.y, player_mobj.z) if distance > 10000000 then mobj.tics = -1 else mobj.tics = 0 end end else ghost_mobj = nil last_breadcrumb = nil end end)