Last active
December 16, 2023 00:59
-
-
Save flowers3176/3ab482897a9c65b2f144e64b5b311e21 to your computer and use it in GitHub Desktop.
Luau Combo Container Module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Compiled with roblox-ts v2.2.0 | |
local ComboContainer | |
do | |
ComboContainer = setmetatable({}, { | |
__tostring = function() | |
return "ComboContainer" | |
end, | |
}) | |
ComboContainer.__index = ComboContainer | |
function ComboContainer.new(name:string, maxCount:number|nil, defaultCombo:number|nil) | |
local self = setmetatable({}, ComboContainer) | |
return self:__constructor(name, maxCount, defaultCombo) or self | |
end | |
function ComboContainer:__constructor(name, maxCount, defaultCombo) | |
self.defaultCombo = 0 | |
self.playerComboList = {} | |
self.playerClearComboThreads = {} | |
self.maxCount = maxCount | |
local _condition = defaultCombo ~= nil | |
if _condition then | |
self.defaultCombo = defaultCombo | |
_condition = (self.defaultCombo) | |
end | |
local _myComboContainers = ComboContainer.__myComboContainers | |
local _name = name | |
local _self = self | |
_myComboContainers[_name] = _self | |
end | |
function ComboContainer:getComboContainer(name) | |
local _myComboContainers = self.__myComboContainers | |
local _name = name | |
return _myComboContainers[_name] | |
end | |
function ComboContainer:add(player:Player, duration:number|nil, amount:number|nil) | |
local _playerClearComboThreads = self.playerClearComboThreads | |
local _player = player | |
local lastThread = _playerClearComboThreads[_player] | |
local _ = lastThread and task.cancel(lastThread) | |
local _playerClearComboThreads_1 = self.playerClearComboThreads | |
local _player_1 = player | |
local _arg1 = task.delay(duration, function() | |
local _playerComboList = self.playerComboList | |
local _player_2 = player | |
local _defaultCombo = self.defaultCombo | |
_playerComboList[_player_2] = _defaultCombo | |
return _playerComboList | |
end) | |
_playerClearComboThreads_1[_player_1] = _arg1 | |
local _condition = amount | |
if _condition == nil then | |
_condition = 1 | |
end | |
local amountToAdd = _condition | |
local _playerComboList = self.playerComboList | |
local _player_2 = player | |
local _condition_1 = _playerComboList[_player_2] | |
if _condition_1 == nil then | |
_condition_1 = self.defaultCombo | |
end | |
local playerCombos = _condition_1 | |
local subTotal = playerCombos + amountToAdd | |
local toSub = if self.maxCount == nil then 0 else math.floor(subTotal / (self.maxCount + 1)) * self.maxCount | |
local total = subTotal - toSub | |
local totalCombo | |
if (total < self.defaultCombo) then totalCombo = self.defaultCombo else totalCombo = total end | |
local _playerComboList_1 = self.playerComboList | |
local _player_3 = player | |
_playerComboList_1[_player_3] = totalCombo | |
end | |
function ComboContainer:get(player:Player) | |
local _playerComboList = self.playerComboList | |
local _player = player | |
local _condition = _playerComboList[_player] | |
if _condition == nil then | |
_condition = self.defaultCombo | |
end | |
return _condition | |
end | |
function ComboContainer:remove(player:Player) | |
local _playerComboList = self.playerComboList | |
local _player = player | |
_playerComboList[_player] = nil | |
end | |
ComboContainer.__myComboContainers = {} | |
end | |
return ComboContainer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment