Skip to content

Instantly share code, notes, and snippets.

@ValentinFunk
Last active January 17, 2018 10:04
Show Gist options
  • Save ValentinFunk/315654df234f08e6a91fa3458ca7326f to your computer and use it in GitHub Desktop.
Save ValentinFunk/315654df234f08e6a91fa3458ca7326f to your computer and use it in GitHub Desktop.
local function generateStattrakItemInfo( itemClass, itemChance )
local info = {
chance = itemChance * 0.1, -- 10% chance of original item = get stattrak item
itemOrInfo = {
isInfoTable = true,
item = itemClass,
getIcon = function()
local icon = vgui.Create("DCsgoItemIcon")
icon:SetItemClass(itemClass)
-- Force border to red
local _setRarity = icon.SetRarity
function icon:SetRarity()
_setRarity(self, { color: Color(255, 0,0) })
end
return icon
end,
printName = itemClass.PrintName .. " (StatTrak™)",
createItem = function(temporaryInstance)
local item = itemClass:new( )
item.isStatTrak = true
item.PrintName = itemClass:GetPrintName( ) .. " (StatTrak™)"
return temporaryInstance and item or item:save( )
end
}
}
return info
end
function ItemFromCategoryFactory:GetChanceTable( )
local category = Pointshop2.GetCategoryByName( self.settings["ManualSettings.CategoryName"] )
if not category then
LibK.GLib.Error( "Invalid Category " .. self.settings["ManualSettings.CategoryName"] )
end
local weightedChances = {}
local sum = 0
for k, itemClass in ipairs( category.items ) do
local weight = 1
if self.settings["BasicSettings.WeightedRandom"] then
if itemClass.Price.points then
weight = itemClass.Price.points
elseif itemClass.Price.premiumPoints then
weight = itemClass.Price.premiumPoints * 10
end
weight = ( 1 / weight ) * 100
end
table.insert(weightedChances, {chance = weight, itemOrInfo = itemClass})
-- If the item in the category is a weapon, generate a stattrak version as well
if (subclassOf( KInventory.Items.base_weapon, itemClass )) then
table.insert(weightedChances, generateStattrakItemInfo(itemClass, weight))
end
end
return weightedChances
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment