local TANK_DEBUG_MODE = true local function removeCashSafe(pack) pack:SetAbsOrigin(Vector(0, -100000, 0)) -- hide despawn particles local objectiveResource = ents.FindByClass("tf_objective_resource") local moneyBefore = objectiveResource.m_nMvMWorldMoney pack:Remove() local moneyAfter = objectiveResource.m_nMvMWorldMoney local packPrice = moneyBefore - moneyAfter local mvmStats = ents.FindByClass("tf_mann_vs_machine_stats") local vscript = 'NetProps.SetPropInt(activator, "m_currentWaveStats.nCreditsDropped", NetProps.GetPropInt(activator, "m_currentWaveStats.nCreditsDropped") - %s)' local curWave = "m_currentWaveStats" mvmStats:RunScriptCode(vscript:format(packPrice), mvmStats, mvmStats) end local curTankIndex = 0 function SpawnTank(tankTemplate, isSupport) local objectiveResource = ents.FindByClass("tf_objective_resource") if tankTemplate.IncludeScriptsOnSpawn then local includeVscript = "" for _, scriptString in pairs(tankTemplate.IncludeScriptsOnSpawn) do includeVscript = includeVscript .. "IncludeScript(`" .. scriptString .. "`);" end if objectiveResource then objectiveResource:RunScriptCode(includeVscript, objectiveResource, objectiveResource) end end local modifiedTrackEnts = {} if tankTemplate.StartingPathTrackNode then for _, track in pairs(ents.FindAllByClass("path_track")) do local trackName = track:GetName() if trackName ~= tankTemplate.StartingPathTrackNode then modifiedTrackEnts[track] = track.m_iClassname track.m_iClassname = "_temporarilyDisabledPath" end end end local tankTargetName = tankTemplate.Name or "tankboss" -- (royal): for some fucking reason, a teamplay_broadcast_audio event callback existing makes spawntank returns an event number instead of an entity return curTankIndex = curTankIndex + 1 local defaultTankEntName = "tankboss_lua_" .. tostring(curTankIndex) ents.CreateWithKeys("tank_boss", { targetname = defaultTankEntName, health = tankTemplate.Health, speed = tankTemplate.Speed, TeamNum = tankTemplate.TeamNum or TEAM_BLUE, }, false) local tankEnt = ents.FindByName(defaultTankEntName) if not tankEnt then -- backup print("backup tank creation used") tankEnt = ents.CreateWithKeys("tank_boss", { targetname = defaultTankEntName, health = tankTemplate.Health, speed = tankTemplate.Speed, TeamNum = tankTemplate.TeamNum or TEAM_BLUE, }, false) end if tankTemplate.Skin then tankEnt:RunScriptCode(("activator.SetSkin(%d)"):format(tankTemplate.Skin), tankEnt, tankEnt) end tankEnt:SetName(tankTargetName) print(tankEnt) tankEnt:RunScriptCode("activator.DispatchSpawn()", tankEnt, tankEnt) for track, originalClassName in pairs(modifiedTrackEnts) do track.m_iClassname = originalClassName end local callbacks = {} callbacks.died = tankEnt:AddCallback(ON_REMOVE, function() for _, callbackId in pairs(callbacks) do tankEnt:RemoveCallback(callbackId) end if TANK_DEBUG_MODE then util.PrintToChatAll("[SPAWNTANK]: A TANK HAS DIED, REMOVING HARDCODED CURRENCY") end -- remove hardcoded $125 which tank always drops timer.Simple(0, function() for _, pack in pairs(ents.FindAllByClass("item_currencypack_custom")) do if not pack.PopLuaCurrency then removeCashSafe(pack) end end end) -- despawned without dying if tankEnt.m_iHealth > 0 then return end if not objectiveResource then return end if not isSupport then local classIcon = tankTemplate.ClassIcon or "tank" -- TODO: check if icon flag matches tankTemplate's flag (only matters for non-miniboss tank vs miniboss tank) for i, v in pairs(objectiveResource.m_iszMannVsMachineWaveClassNames) do if v == classIcon then objectiveResource.m_nMannVsMachineWaveClassCounts[i] = objectiveResource.m_nMannVsMachineWaveClassCounts[i] - 1 end end end end) return tankEnt end