local dc_livesback = nil local dc_stlivex = nil local dc_faceprefix = {} local dc_superprefix = {} local dc_deaths = {} local function DC_DrawSmallPatch(v, x, y, s, p, c) v.drawScaled(x << FRACBITS, y << FRACBITS, FRACUNIT / 2, p, s, c) end local function DC_DrawScaledPatch(v, x, y, s, p) v.drawScaled(x << FRACBITS, y << FRACBITS, FRACUNIT, p, s) end local function DC_LoadFaceGraphics(v, skinnum) -- taken from the engine, ST_LoadFaceGraphics in src/st_stuff.c -- credit goes to STJr for the original code if skins[skinnum].sprites[SPR2_XTRA].numframes > 0 then dc_faceprefix[skinnum] = v.getSprite2Patch(skinnum, SPR2_XTRA, false) local superskin, hassuper = v.getSprite2Patch(skinnum, SPR2_XTRA, true) if hassuper then dc_superprefix[skinnum] = superskin else dc_superprefix[skinnum] = dc_faceprefix[skinnum] end else dc_faceprefix[skinnum] = v.cachePatch("MISSING") dc_superprefix[skinnum] = dc_faceprefix[skinnum] end end hud.add(function (v, stplyr, cam) if (netgame or multiplayer) and G_CoopGametype() then hud.disable("lives") else hud.enable("lives") return end -- taken from the engine, ST_drawLivesArea in src/st_stuff.c -- credit goes to STJr for the original code if not stplyr.skincolor or G_IsSpecialStage(gamemap) then return end if dc_livesback == nil then dc_livesback = v.cachePatch("STLIVEBK") end if dc_faceprefix[stplyr.skin] == nil then DC_LoadFaceGraphics(v, stplyr.skin) end DC_DrawSmallPatch(v, hudinfo[HUD_LIVES].x, hudinfo[HUD_LIVES].y, hudinfo[HUD_LIVES].f|V_PERPLAYER|V_HUDTRANS, dc_livesback) if stplyr.spectator then local colormap = v.getColormap(stplyr.skin, SKINCOLOR_CLOUDY) DC_DrawSmallPatch(v, hudinfo[HUD_LIVES].x, hudinfo[HUD_LIVES].y, hudinfo[HUD_LIVES].f|V_PERPLAYER|V_HUDTRANSHALF, dc_faceprefix[stplyr.skin], colormap) elseif stplyr.mo and stplyr.mo.color then local colormap = v.getColormap(stplyr.skin, stplyr.mo.color) local face = dc_faceprefix[stplyr.skin] if stplyr.powers[pw_super] and not (stplyr.charflags & SF_NOSUPERSPRITES) then face = dc_superprefix[stplyr.skin] end DC_DrawSmallPatch(v, hudinfo[HUD_LIVES].x, hudinfo[HUD_LIVES].y, hudinfo[HUD_LIVES].f|V_PERPLAYER|V_HUDTRANS, face, colormap) elseif stplyr.skincolor then local colormap = v.getColormap(stplyr.skin, stplyr.skincolor) DC_DrawSmallPatch(v, hudinfo[HUD_LIVES].x, hudinfo[HUD_LIVES].y, hudinfo[HUD_LIVES].f|V_PERPLAYER|V_HUDTRANS, dc_faceprefix[stplyr.skin], colormap) end local colmap = V_YELLOWMAP if stplyr.spectator then colmap = V_GRAYMAP else if dc_stlivex == nil then dc_stlivex = v.cachePatch("STLIVEX") end DC_DrawScaledPatch(v, hudinfo[HUD_LIVES].x+22, hudinfo[HUD_LIVES].y+10, hudinfo[HUD_LIVES].f|V_PERPLAYER|V_HUDTRANS, dc_stlivex) v.drawString(hudinfo[HUD_LIVES].x+66, hudinfo[HUD_LIVES].y+8, dc_deaths[#stplyr], hudinfo[HUD_LIVES].f|V_PERPLAYER|V_HUDTRANS, "right") end colmap = colmap | V_HUDTRANS | hudinfo[HUD_LIVES].f | V_PERPLAYER v.drawString(hudinfo[HUD_LIVES].x+66, hudinfo[HUD_LIVES].y, "DEATHS", colmap, "right") end) addHook("NetVars", function (network) dc_deaths = network(dc_deaths) end) addHook("MapLoad", function (mapnum) -- NOTE: we're calling this on map load in case the gametype was changed if (netgame or multiplayer) and G_CoopGametype() and G_GametypeUsesLives() then -- use CV_StealthSet here so we don't display the change message CV_StealthSet(CV_FindVar("cooplives"), 0) -- force infinite lives end end) addHook("PlayerJoin", function (playernum) dc_deaths[playernum] = 0 emeralds = 127 end) addHook("MobjDeath", function (target, inflictor, source, damagetype) -- don't count deaths in special stages if not G_IsSpecialStage(gamemap) then dc_deaths[#target.player] = dc_deaths[#target.player] + 1 end end, MT_PLAYER)