math.ease = {} math.WeightedRandom = function( tbl ) local total = 0 for i, d in pairs( tbl ) do if tostring( type( d ) ) == "table" then total = total + d.Weight else total = total + d end end local random = math.randomfloat( 0, total ) local cumulativeProbability = 0 for key, item in pairs(tbl) do if tostring( type( item ) ) == "table" then cumulativeProbability = cumulativeProbability + item.Weight else cumulativeProbability = cumulativeProbability + item end if (cumulativeProbability >= random) then return key; end end end math.WeightedRandomVoteCate = function( tbl ) local total = 0 for i, d in pairs( tbl ) do if tostring( type( d ) ) == "table" then total = total + d.Weight else total = total + d end end local random = math.randomfloat( 0, total ) local cumulativeProbability = 0 for key, item in pairs(tbl) do if tostring( type( tbl[key] ) ) == "table" then cumulativeProbability = cumulativeProbability + tbl[key].Weight else cumulativeProbability = cumulativeProbability + tbl[key] end if (cumulativeProbability >= random) then if tbl and ( tostring( type( tbl ) ) == "table" ) and tbl[key] and (tostring( type( tbl[key] ) ) == "table") and tbl[key].RealValue then --- THIS return tbl[key].RealValue; else return key; end end end end --[[ the table shoud look like tbl = { 1, 0.6, 0.2, } or tbl = { [1] = { Weight = 1 }, [2] = { Weight = 0.6 }, [3] = { Weight = 0.2 } } --]] math.WeightedRandomEnemy = function( tbl ) local total = 0 for i, d in pairs( tbl ) do total = total + ( d.Weight * ENEMY_TYPE_CHANCE_MULT[ d.Type ] ) end local random = math.randomfloat( 0, total ) local cumulativeProbability = 0 for key, item in pairs(tbl) do cumulativeProbability = cumulativeProbability + ( tbl[key].Weight * ENEMY_TYPE_CHANCE_MULT[ tbl[key].Type ] ) if (cumulativeProbability >= random) then return key; end end end math.WeightedRandomEnemySummon = function( tbl ) local total = 0 for i, d in pairs( tbl ) do total = total + ( d.Weight ) end local random = math.randomfloat( 0, total ) local cumulativeProbability = 0 for key, item in pairs(tbl) do cumulativeProbability = cumulativeProbability + ( tbl[key].Weight ) if (cumulativeProbability >= random) then return key; end end end CEntity.GetAttributeValueClean = function(self, attribute, default, slot) -- IDIOT FACE if slot == nil then return default end if (IsValid(self)) then -- print( self, attribute, default, slot, slot == LOADOUT_POSITION_BODY, ( self:GetAttributeValue( tostring( attribute ), true ) or default ) ) if slot == LOADOUT_POSITION_BODY then return ( self:GetAttributeValue( tostring( attribute ), true ) or default ) else if IsValid( self:GetPlayerItemBySlot(slot) ) then return ( self:GetPlayerItemBySlot(slot):GetAttributeValue( tostring( attribute ), true ) or default ) end end end return default end CEntity.GetItemBySlotClean = function(self, slot) if (IsValid(self)) then -- print( attribute, default, slot, slot == LOADOUT_POSITION_BODY, ( self:GetAttributeValue( tostring( attribute ), true ) or default ) ) -- print( slot ) if slot == LOADOUT_POSITION_BODY then return self elseif slot == LOADOUT_POSITION_PRIMARY_AND_SECONDARY then return { self:GetPlayerItemBySlot( 0 ), self:GetPlayerItemBySlot( 1 ) } elseif slot == LOADOUT_POSITION_ALL then return { self:GetPlayerItemBySlot( 0 ), self:GetPlayerItemBySlot( 1 ), self:GetPlayerItemBySlot(2) } elseif slot == LOADOUT_POSITION_ACTIVE_WEAPON then return self.m_hActiveWeapon else return self:GetPlayerItemBySlot( tonumber(slot) ) end end end ents.GetAllAliveBots = function() local ply = {} for _, player in pairs( ents.GetAllPlayers() ) do if player:IsBot() and player:IsAlive() then table.insert( ply, player ) end end return ply end ents.GetAllAliveNonMedicBots = function() local ply = {} for _, player in pairs( ents.GetAllPlayers() ) do if player:IsBot() and player:IsAlive() and ( player.m_iClass ~= TF_CLASS_MEDIC ) then table.insert( ply, player ) end end return ply end ents.FindBySteamID = function( id ) for _, player in pairs( ents.GetAllRealPlayers() ) do if player.m_szNetworkIDString == id then return player end end return false end CEntity.SetAttributeValueTemporary = function( self, attribute, value, duration ) self:SetAttributeValue( attribute, value ) self["AttributeRemoveDelay"..tostring(self:GetNetIndex())..tostring(attribute)] = CurTime() + duration self["AttributeTimer"..tostring(self:GetNetIndex())..tostring(attribute)] = timer.Create( 0.1, function() if CurTime() >= self["AttributeRemoveDelay"..tostring(self:GetNetIndex())..tostring(attribute)] then self:SetAttributeValue( attribute, nil ) return false end end, 0 ) end function string.starts(String,Start) -- Copied from StackOverflow cause lazy return string.sub(String,1,string.len(Start))==Start end math.ease.InCubic = function(x) return x * x * x end math.ease.OutCubic = function(x) return 1 - math.pow(1 - x, 3) end