Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[Chip Converter]]--
- g_chip_lua = "function update()\nlocal ChipDes = self.getDescription()\nlocal Count = self.getQuantity()\nlocal ChipValue = Global.call('format_number', {tonumber(ChipDes)})\nif (Count > 0) then\nlocal Total = Global.call('format_number', {tonumber(Count * ChipDes)})\nself.setName('* '..ChipValue..' = $'..Total)\nelse\nself.setName('$'..ChipValue)\nend\nend"
- chip_table = {}
- chip_values = {}
- firstTime = 0
- function sortTable(a, b)
- return a > b
- end
- function initializeChipTable()
- local scripted_zone = getObjectFromGUID('##CHIP ZONE##') -- Where the chips are read from, if you have a stack at the back of your hidden zone
- local chips = scripted_zone.getObjects()
- for k, v in ipairs(chips) do
- local val = tonumber(v.getDescription()) or 0
- if val > 0 then
- chip_table[val] = v.getGUID()
- table.insert(chip_values, val)
- end
- end
- table.sort(chip_values, sortTable)
- end
- function spawnChip(value)
- local params = {}
- params.position = {20, 15, -8.5}
- local original_chip = getObjectFromGUID(chip_table[value])
- chip = original_chip.clone(params)
- chip.setLuaScript(g_chip_lua)
- chip.unlock()
- return chip
- end
- function spawnChips(amount)
- local chip = nil
- local num = 0
- for i, v in ipairs(chip_values) do
- --local num = math.floor(amount / v)
- local num = amount / v
- if num >= 0.99999 and num <= 1.00001 then
- num = 1
- end
- if num % 1 ~= 0 then
- num = math.floor(num)
- end
- if (num >= 1) then
- amount = amount - num * v
- for i = 1, num, 1 do
- chip = spawnChip(v)
- end
- end
- end
- end
- function convertChipsDown(amount)
- if amount == 5 then
- spawnChip(amount)
- else
- for i, v in ipairs(chip_values) do
- if amount ~= v then
- local num = math.floor(amount / v)
- amount = amount - num * v
- for i = 1, num, 1 do
- chip = spawnChip(v)
- end
- end
- end
- end
- end
- timeConvert = os.time()
- function convertChips()
- if firstTime == 0 then
- firstTime = 1
- initializeChipTable()
- else
- if os.time() >= timeConvert then
- local scripted_zone = getObjectFromGUID('##CHIP CONVERT ZONE##')
- local chip_table = scripted_zone.getObjects()
- local amount = 0
- local amount_chips = 0
- local obj = {}
- local istack = 0
- for i, v in ipairs(chip_table) do
- local mult = 0
- local val = 0
- mult = v.getQuantity()
- val = tonumber(v.getDescription()) or 0
- if mult == -1 then
- mult = 1
- end
- if val > 0 then
- amount_chips = amount_chips + 1
- istack = mult
- amount = amount + (val * mult)
- v.destruct()
- end
- end
- if amount_chips == 1 and istack == 1 then
- convertChipsDown(amount)
- else
- spawnChips(amount)
- end
- timeConvert = os.time() + 5
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement