local DASH_COOLDOWN = 3 local callbacks = {} local classIndices_Internal = { [1] = "Scout", [3] = "Soldier", [7] = "Pyro", [4] = "Demoman", [6] = "Heavy", [9] = "Engineer", [5] = "Medic", [2] = "Sniper", [8] = "Spy", } local CUSTOM_CANTEEN_INDICES = { "Dash" , "Defense" , "Offense" } for _, canteenIndex in pairs(CUSTOM_CANTEEN_INDICES) do callbacks[canteenIndex] = {} end function ClearCallbacks(index, activator, handle) activator:Print(1, "Clearing callbacks...") handle = handle or activator:GetHandleIndex() local weaponCallbacks = callbacks[index][handle] if not weaponCallbacks then return end if activator and IsValid(activator) then for _, callbackId in pairs(weaponCallbacks) do activator:RemoveCallback(callbackId) activator:Print(1, "Callbacks yeeted!") end end callbacks[index][handle] = nil end local cooldown_players = {} local CD_PARAMS = { channel = 2, x = 0.2, y = 0.8, r1 = 255, g1 = 0, b1 = 20, a1 = 204, holdTime = DASH_COOLDOWN, } local READY_PARAMS = { channel = 2, x = 0.2, y = 0.8, r1 = 0, g1 = 255, b1 = 20, a1 = 204, holdTime = DASH_COOLDOWN, } -- "Up" is measured in negative degrees. local function _getPlayerCameraAngleUp(player) local pitch = player["m_angEyeAngles[0]"] pitch = -pitch --Reverses it. if pitch > -24.9 and pitch < 24.9 then pitch = 25 end return Vector(0, 0, pitch) end --todo: add particle effectusing util.ParticleEffect to player's feet. -- GetAbsOrigin + offset? function DoDash(player) local handle = player:GetHandleIndex() if cooldown_players[handle] then return end cooldown_players[handle] = true timer.Simple(DASH_COOLDOWN, function() cooldown_players[handle] = nil player:PlaySoundToSelf("=45|player/recharged.wav") player:ShowHudText(READY_PARAMS, "Dash ready!") end) local angle = _getPlayerCameraAngleUp(player) player:PlaySoundToSelf("=45|weapons/tacky_grenadier_explode2.wav") player:DisplayTextChat(""..tostring(classIndices_Internal[player.m_iClass]).." dash!") --Launch player backwards at low angle. if classIndices_Internal[player.m_iClass] == "Demoman" then player:SetForwardVelocity(-1000) player:AddOutput("BaseVelocity 0 0 270") --Launch player directly upwards. elseif classIndices_Internal[player.m_iClass] == "Heavy" then player:SetForwardVelocity(230) player:AddOutput("BaseVelocity 0 0 700") player:AddCond(125) --Parachutes added via cond 80 cannot be undeployed, annoyingly. -- timer.Simple(0.7, function() -- timer.Create(0.1, function() -- print(player.m_vecBaseVelocity[3]) -- if player.m_hGroundEntity == nil and player.m_vecBaseVelocity[3] < 100 then -- player:AddCond(80) -- return false -- end -- end) -- end) --Launch player forwards at decent angle. Identical to original Winger dash. elseif classIndices_Internal[player.m_iClass] == "Pyro" or "Soldier" then player:SetForwardVelocity(1000) player:AddOutput("BaseVelocity " .. tostring(angle * 10)) end player:ShowHudText(CD_PARAMS, "Dash on cooldown...") end function ActionTest(_, activator) activator:DisplayTextChat("{red}test") end function ActionPressed(_, activator) activator:Print(1, "Action!") local handleIndex = activator:GetHandleIndex() if callbacks.Dash[handleIndex] then DoDash(activator) return end if callbacks.Defense[handleIndex] then -- DoDefense(activator) return end end -- On purchase: add player to list of Dashers. function DashPurchased(_, activator) local handle = activator:GetHandleIndex() callbacks.Dash[handle] = {} local dashCallbacks = callbacks.Dash[handle] activator:Print(2, "Purchased Dash!") dashCallbacks.died = activator:AddCallback(ON_DEATH, function() activator:Print(1, "You died!") if activator:GetAttributeValue("cannot giftwrap") then activator:Print(1, "You still have the giftwrap.") return end DashRefunded(_, activator) end) dashCallbacks.spawned = activator:AddCallback(ON_SPAWN, function() activator:Print(1, "You spawned!") if activator:GetAttributeValue("cannot giftwrap") then activator:Print(1, "You still have the giftwrap.") return end DashRefunded(_, activator) end) end function DashRefunded(_, activator) if IsValid(activator) then activator:Print(2, "Refunded Dash!") ClearCallbacks("Dash", activator, activator:GetHandleIndex()) end end