local SPELLS = { Empty = -1, Fireball = 0, SwarmofBats = 1, Overheal = 2, PumpkinMIRV = 3, BlastJump = 4, Stealth = 5, ShadowLeap = 6, BallOLightning = 7, Minify = 8, MeteorShower = 9, SummonMONOCULUS = 10, SkeletonsHorde = 11, BoxingRocket = 12, BASEJump = 13, OverhealBumperCars = 14, BombHead = 15, } local SPELL_CANTEENS = { ["SPELL: Halloween green flames"] = SPELLS.Fireball, ["SPELL: Halloween pumpkin explosions"] = SPELLS.PumpkinMIRV, ["rj air bombardment"] = SPELLS.MeteorShower, ["enables aoe heal"] = SPELLS.Overheal, ["SPELL: Halloween death ghosts"] = SPELLS.SkeletonsHorde, ["attach particle effect"] = SPELLS.SummonMONOCULUS, ["cloak consume rate decreased"] = SPELLS.Stealth, ["rocketjump attackrate bonus"] = SPELLS.Minify, -- ["attach particle effect"] = SPELLS.BallOLightning, } local USE_JANKY_BUT_COOL_FAKE_CANTEEN_UPGRADE_ICON = false local function getAttributeFromSpellIndex(i) for attribute, index in pairs(SPELL_CANTEENS) do if index == i then return attribute end end end local function giveCanteen(player) local canteen = player:GiveItem("Power Up Canteen (MvM)") return canteen end local function giveSpellBook(player) local spellBook = player:GiveItem("Halloween Spellbook") return spellBook end local function handleSpawn(player) giveSpellBook(player) end AddGlobalCallback("OnPlayerConnected", function(player) if player:IsAlive() then handleSpawn(player) end player:AddCallback(ON_SPAWN, function() handleSpawn(player) end) end) local playersInStationIndexes = {} AddEventCallback("player_upgraded", function() for handleIndex in pairs(playersInStationIndexes) do local player = Entity(handleIndex) -- local canteen = player:GetPlayerItemByName("Power Up Canteen (MvM)") timer.Simple(0, function() if IsValid(player:GetPlayerItemByName("Halloween Spellbook")) then player:RemoveItem("Halloween Spellbook") giveCanteen(player) end end) end end) for _, station in pairs(ents.FindAllByClass("func_upgradestation")) do station:AddCallback(ON_START_TOUCH, function(_, player) if not player:IsRealPlayer() then return end local canteenCount local canteenAttribute local book = player:GetPlayerItemByName("Halloween Spellbook") if book then canteenAttribute = getAttributeFromSpellIndex(book.m_iSelectedSpellIndex) canteenCount = book.m_iSpellCharges end player:RemoveItem("Halloween Spellbook") local canteen = giveCanteen(player) if canteenCount then canteen:SetAttributeValue("powerup charges", canteenCount) canteen.m_usNumCharges = canteenCount if canteenCount <= 0 and canteenAttribute then canteen:SetAttributeValue(canteenAttribute, nil) end end local playerIndex = player:GetHandleIndex() playersInStationIndexes[playerIndex] = true if USE_JANKY_BUT_COOL_FAKE_CANTEEN_UPGRADE_ICON then local closeUpgradeLoop = nil local aborted = false local function stopLoop() aborted = true if closeUpgradeLoop then timer.Stop(closeUpgradeLoop) closeUpgradeLoop = nil end if IsValid(player) then player.m_bInUpgradeZone = 1 end end local function alive() if aborted then return false end if not IsValid(canteen) or not IsValid(player) or not playersInStationIndexes[playerIndex] then stopLoop() return false end return true end local function step(delay, fn) timer.Simple(delay, function() if not alive() then return end fn() end) end local function beginForce() closeUpgradeLoop = timer.Create(0, function() if not alive() then return end player.m_bInUpgradeZone = 0 end, 0) end local function endForce() if closeUpgradeLoop then timer.Stop(closeUpgradeLoop) closeUpgradeLoop = nil end player.m_bInUpgradeZone = 1 end step(0.1, function() beginForce() canteen.m_bInitialized = 0 step(0.1, function() endForce() step(0.15, function() beginForce() canteen.m_iItemDefinitionIndex = 1069 canteen.m_bInitialized = 1 step(0.1, function() endForce() step(0.15, function() beginForce() step(0.1, function() endForce() end) end) end) end) end) end) end end) station:AddCallback(ON_END_TOUCH, function(_, player) if not player:IsRealPlayer() then return end local canteen = player:GetPlayerItemByName("Power Up Canteen (MvM)") local selectedSpellIndex local spellCharges if canteen then for attribute in pairs(canteen:GetAllAttributeValues(false)) do if SPELL_CANTEENS[attribute] then local spellIndex = SPELL_CANTEENS[attribute] local amount = canteen:GetAttributeValue("powerup charges", true) selectedSpellIndex = spellIndex spellCharges = amount end end end player:RemoveItem("Power Up Canteen (MvM)") local spellBook = giveSpellBook(player) playersInStationIndexes[player:GetHandleIndex()] = nil if selectedSpellIndex then spellBook.m_iSelectedSpellIndex = selectedSpellIndex spellBook.m_iSpellCharges = spellCharges end end) end