Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function giveChipstackName(chipstack)
- chipInfo = getChipInfo(chipstack.script_code)
- if chipInfo ~= nil then
- local pre = (chipInfo.prefix ~= nil) and (chipInfo.prefix) or ("")
- local suf = (chipInfo.suffix ~= nil) and (chipInfo.suffix) or ("")
- local preSingle = (chipInfo.prefixSingular ~= nil) and (chipInfo.prefixSingular) or (pre)
- local sufSingle = (chipInfo.suffixSingular ~= nil) and (chipInfo.suffixSingular) or (suf)
- local val = chipInfo.value
- local amount = chipstack.getQuantity()
- chipstack.setName(" * " .. preSingle .. tostring(val) .. sufSingle .. " = " .. pre .. tostring(val * amount) .. suf)
- end
- end
- function giveChipName(chip)
- chipInfo = getChipInfo(chip.script_code)
- if chipInfo ~= nil then
- local pre = (chipInfo.prefixSingular ~= nil) and (chipInfo.prefixSingular) or ((chipInfo.prefix ~= nil) and (chipInfo.prefix) or "")
- local suf = (chipInfo.suffixSingular ~= nil) and (chipInfo.suffixSingular) or ((chipInfo.suffix ~= nil) and (chipInfo.suffix) or "")
- local val = chipInfo.value
- chip.setName(pre .. tostring(val) .. suf)
- end
- end
- function getChipInfo(chipScript)
- local prefix = nil
- local suffix = nil
- local prefixSingular = nil
- local suffixSingular = nil
- local value = nil
- for line in chipScript:gmatch('[^\r\n]+') do
- if (prefix == nil) and (line:find("^-- prefix:")) then
- prefix = line:sub(#("-- prefix:") + 1)
- elseif (suffix == nil) and (line:find("^-- suffix:")) then
- suffix = line:sub(#("-- suffix:") + 1)
- elseif (prefixSingular == nil) and (line:find("^-- prefixsingular:")) then
- prefixSingular = line:sub(#("-- prefixsingular:") + 1)
- elseif (suffixSingular == nil) and (line:find("^-- suffixsingular:")) then
- suffixSingular = line:sub(#("-- suffixsingular:") + 1)
- elseif line:find("^-- value:") then
- value = tonumber(line:sub(#("-- value:") + 1))
- end
- if (prefix ~= nil) and (suffix ~= nil) and (prefixSingular ~= nil) and (suffixSingular ~= nil) and (value ~= nil) then
- break
- end
- end
- if value == nil then
- return nil
- else
- return
- {
- ["prefix"] = prefix,
- ["suffix"] = suffix,
- ["prefixSingular"] = prefixSingular,
- ["suffixSingular"] = suffixSingular,
- ["value"] = value
- }
- end
- end
- function onObjectEnterContainer(container, enter_object)
- if container.name == "Custom_Model_Stack" then
- giveChipstackName(container)
- end
- end
- function onObjectLeaveContainer(container, leave_object)
- if container.name == "Custom_Model_Stack" then
- giveChipstackName(container, leave_object)
- end
- end
- function onObjectSpawn(obj)
- if (obj.tag == "Chip") then
- if obj.getQuantity() == -1 then -- is single chip
- giveChipName(obj)
- else -- is chip stack
- giveChipstackName(obj)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment