nickcool9999

PI Upgrader Code

Jul 26th, 2017
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.34 KB | None | 0 0
  1. local button
  2. local spinner = false -- upgrade wheel code
  3.  
  4. if script:FindFirstChild("Inherit") and script.Parent:FindFirstChild("Spinner") then -- is wheel
  5.     button = script.Parent.Spinner[script.Inherit.Value] -- state wheel part
  6.     spinner = true -- set as spinner
  7. else
  8.     button = script.Parent
  9. end
  10.  
  11. local elib = require(game.ServerScriptService.Modules.Lib.Effects)
  12. local lib = require(game.ServerScriptService.Modules.EffectsFunctions)
  13. local saving = require(game.ServerScriptService.Modules.BaseSaving)
  14. local fld
  15.  
  16. -- mod folder
  17. local mods = script.Parent.Parent:FindFirstChild("Modify") or Instance.new("Folder",script.Parent.Parent)
  18. mods.Name = "Modify"
  19. local val = mods:FindFirstChild("ValueMultiplier") or Instance.new("NumberValue",mods)
  20. val.Name = "ValueMultiplier"
  21. val.Value = -1
  22. local inc = mods:FindFirstChild("ValueMultiplier") or Instance.new("NumberValue",mods)
  23. inc.Name = "ValueIncrease"
  24. inc.Value = 0
  25. local pwr = mods:FindFirstChild("PowerCost") or Instance.new("NumberValue",mods)
  26. pwr.Name = "PowerCost"
  27. pwr.Value = 1
  28. local typ = mods:FindFirstChild("ModType") or Instance.new("StringValue",mods)
  29. typ.Name = "ModType"
  30. typ.Value = "Upgrader"
  31.  
  32. function HookupTooltip()
  33.     local f = fld:FindFirstChild("IGChange") or Instance.new("BindableFunction",fld)
  34.     f.Name = "IGChange"
  35.     f.OnInvoke = Tooltip
  36. end
  37. function Tooltip()
  38.     local View = {
  39.         {"Value","x","",val},
  40.         {"Static","+","$",inc},
  41.         {"Consumption","","x",pwr},
  42.     }
  43.     local s = "Automation Stats:" .. string.format'\n'
  44.     for _,dat in pairs(View) do
  45.         --print(dat[4].Name)
  46.         s=s..(dat[1]..": "..dat[2]..tostring(dat[4].Value)..dat[3]..string.format"\n")
  47.     end
  48.     if (not s) or s=="" then
  49.         if fld and fld.Name=="UnitOptions" and fld:FindFirstChild("IG_Tooltip") then
  50.             fld.IG_Tooltip:Destroy()
  51.         end
  52.         return
  53.     end
  54.     if not fld then return end
  55.     if fld.Name~="UnitOptions" then return end
  56.     local v = fld:FindFirstChild("IG_Tooltip") or Instance.new("StringValue",fld)
  57.     v.Name = "IG_Tooltip"
  58.     v.Value = s
  59.     return v
  60. end
  61.  
  62. if spinner then -- if is spinner
  63.     fld = script.Parent:WaitForChild(script.Inherit.Value) -- get separate folder (Inherit defined)
  64. else
  65.     fld = button.Parent:WaitForChild("UnitOptions")
  66. end
  67.  
  68. if fld:FindFirstChild("RequiresSun") then
  69.     sun = fld.RequiresSun
  70. end
  71.  
  72. if fld and fld:FindFirstChild("PowerConsumption") then
  73.     local defv = fld.PowerConsumption.Value
  74.     pwr.Changed:connect(function(val)
  75.         fld.PowerConsumption.Value = defv*val
  76.     end)
  77. end
  78.  
  79. local deb = {}
  80.  
  81. RNG = function(min,max) -- replacement to account for high numbers
  82.     local n = min+(math.random()*(max-min))
  83.     --print(n.. " Generated.")
  84.     return n
  85. end
  86.  
  87. local dodebug = false
  88. debugprint = function(...)
  89.     if not dodebug then return end
  90.     --print(...)
  91. end
  92.  
  93. local orange = BrickColor.new("Deep orange")
  94. local black = BrickColor.new("Black")
  95. local sun_value = game.ReplicatedStorage.WorldSettings.SolarPower
  96. gravity = 150
  97.  
  98. function short(n)
  99.     return math.floor(n*100 + 0.5)/100
  100. end
  101. function doGravity(dir,part,f)
  102.     dir=((dir.unit)*part:GetMass()*(gravity/1.5))
  103.     f.Force = dir
  104. end
  105. function getOwner()
  106.     if script.Parent.Parent:FindFirstChild("Owner") then
  107.         if script.Parent.Parent.Owner.Value then
  108.             return script.Parent.Parent.Owner.Value
  109.         end
  110.     end
  111. end
  112. local acteffects = {"do","darken"}
  113. function EntActivate(dvalue,basev,part)
  114.     local chances = (math.log(dvalue.Value)/291)*100
  115.     if chances<50 then -- around 1e64
  116.         local e = Instance.new("Explosion",workspace)
  117.         e.Position = part.Position
  118.     else
  119.         chances=chances-50
  120.         chances=(chances/4)^.5
  121.         local roll = math.random(1,1000)/10
  122.         --print(short(chances).."% Chance to effect! (Roll: " ..short(roll).. "%)")
  123.         if chances >= roll then
  124.             local eff = acteffects[math.random(1,2)]
  125.             if eff=='darken' then
  126.                 basev.Value = 1e127
  127.                 dvalue.Value = 1e127
  128.                 part.BrickColor = BrickColor.Black()
  129.                 part.Material = "Neon"
  130.                 game.ServerStorage.Darkness:Clone().Parent = part
  131.                 local pl = getOwner()
  132.                 if pl and workspace.Players[pl.Name].PlayerData.Difficulty.Value == "Extreme" then
  133.                     saving:SaveBadge(pl, "Drop Graduation")
  134.                 end
  135.             elseif eff== 'do' then
  136.                 basev.Value = 1e127
  137.                 dvalue.Value = 1e127
  138.                 local pl = getOwner()
  139.                 if pl and workspace.Players[pl.Name].PlayerData.Difficulty.Value == "Extreme" then
  140.                     saving:SaveBadge(pl, "Drop Graduation")
  141.                 end
  142.             end
  143.         else
  144.             local rng=math.random(1,5)
  145.             if rng==1 then
  146.                 local e = Instance.new("Explosion",workspace)
  147.                 e.Position = part.Position
  148.                 lib.DissapearDrop(part,script)
  149.             elseif rng==2 then
  150.                 local f = Instance.new("BodyForce",part)
  151.                 doGravity(Vector3.new(0,1,0),part,f)
  152.                 delay(3,function() if part and part.Parent then lib.DissapearDrop(part,script) end end)
  153.             elseif rng>=3 then
  154.                 lib.DissapearDrop(part,script)
  155.             end
  156.         end
  157.     end
  158. end
  159.  
  160. function applyEffect(part, effectname, dvalue)
  161.     -- Applies an effect to a drop
  162.     if sun and sun.Value then
  163.         if sun_value.Value <= 0.01 then
  164.             return false, 4, black -- not enough sun
  165.         end
  166.     end
  167.     deb[part] = true
  168.     local eff = part:FindFirstChild("Effects") or Instance.new("Folder")
  169.     eff.Name = "Effects"
  170.     eff.Parent = part
  171.  
  172.     if elib[effectname] then -- check effect exists
  173.         local effect = elib[effectname] -- get the effect
  174.         local maxEffects = effect.maxEffects or 9e9 -- store max applications
  175.         local maxApplies = effect.affects or -1 -- store max value applied to
  176.         local minApplies = effect.minAffects or -1 -- store min value applied to
  177.         local minBase = effect.minBase or -1 -- store min base value applied to
  178.         local base = effect.base or -1 -- store exact base to be applied to
  179.  
  180.         local effv
  181.         if not spinner then
  182.             effv = eff:FindFirstChild("Effect"..effectname) -- look up existing effect
  183.         else
  184.             effv = eff:FindFirstChild("EffectSpinner"..script.Parent.Name) -- spinner model effect
  185.         end
  186.         local basev = part:FindFirstChild("BaseValue") -- look up unupgraded value
  187.         if not basev then
  188.             basev = basev or Instance.new("NumberValue",part) -- create new basevalue if it doesnt exist
  189.             basev.Name = "BaseValue" -- give it the proper name
  190.             basev.Value = dvalue.Value -- set base value
  191.         end
  192.         local entropic = basev and (basev.Value>=1e127) -- is this drop entropic?
  193.         if dvalue and dvalue.Value>1e57 then
  194.             if (not effect.extreme) and (not effect.entropic) then
  195.                 return false, 5, orange
  196.             end
  197.             if dvalue.Value>1e127 and (not effect.entropic) then
  198.                 return false, 6, black
  199.             end
  200.         end
  201.         if minBase ~= -1 then
  202.             if basev.Value < minBase then return false end
  203.         end
  204.         if base ~= -1 then
  205.             if basev.Value ~= base then --[[print('incorrect base: '..basev.Value)]] return false end
  206.         end
  207.         if effv and effv.Value >= maxEffects then return false end -- if cant apply return false
  208.         if maxApplies ~= -1 then -- if maxApplies is a valid number
  209.             -- this line requires an ore to be at most said value
  210.             if dvalue.Value > maxApplies then debugprint'too value' return false end -- if application is invalid return false
  211.         end
  212.         if minApplies ~= -1 then
  213.             -- this line requires an ore be a value before it accepts an upgrade
  214.             if dvalue.Value < minApplies then debugprint('too little value ' ..dvalue.Value.. ' < ' ..minApplies) return false end -- if application is invalid return false
  215.         end
  216.         local v = effv or Instance.new("IntValue",eff) -- create new effectvalue if it doesnt exist
  217.         if not spinner then
  218.             v.Name = "Effect"..effectname -- give it the proper name
  219.         else
  220.             v.Name = "EffectSpinner"..script.Parent.Name -- give it spinner name
  221.         end
  222.         v.Value = v.Value + 1 -- add 1 to its applications
  223.         --print("EditType:".. effect.dropEdit[1],effect.dropEdit[2])
  224.         if effect.dropEdit then
  225.             -- declarations
  226.             local editType = effect.dropEdit[1]
  227.             local editFactor
  228.             --print("effect.dropEdit[2]: " ..effect.dropEdit[2])
  229.             --print("val.Value: " ..val.Value)
  230.             if val.Value >= 0.1 then
  231.                 editFactor = effect.dropEdit[2] * val.Value
  232.             else
  233.                 editFactor = effect.dropEdit[2]
  234.             end
  235.             --print("editFactor: " ..editFactor)
  236.             local editExtra = effect.dropEdit[3] -- optional, for ceil random
  237.             -- comparisons
  238.             dvalue.Value=dvalue.Value+inc.Value -- mod support
  239.             if editType == "addTo" then
  240.                 dvalue.Value = dvalue.Value + editFactor -- add (can be negative)
  241.                 --print(editFactor)
  242.                 dvalue.Value = math.max(1,dvalue.Value)
  243.                 --print(dvalue.Value)
  244.                 if not entropic then
  245.                     dvalue.Value = math.min(.99*1e127,dvalue.Value) -- maximum to entropic activation
  246.                 end
  247.                 --print(dvalue.Value)
  248.                 return true
  249.             elseif editType == "multiplyTo" then
  250.                 dvalue.Value = dvalue.Value * editFactor -- multiply
  251.                 dvalue.Value = math.max(1,dvalue.Value)
  252.                 if not entropic then
  253.                     dvalue.Value = math.min(.99*1e127,dvalue.Value) -- maximum to entropic activation
  254.                 end
  255.                 return true
  256.             elseif editType == "divideBy" then
  257.                 dvalue.Value = dvalue.Value / editFactor -- divide
  258.                 dvalue.Value = math.max(1,dvalue.Value)
  259.                 if not entropic then
  260.                     dvalue.Value = math.min(.99*1e127,dvalue.Value) -- maximum to entropic activation
  261.                 end
  262.                 return true
  263.             elseif editType == "exponentiate" then
  264.                 dvalue.Value = dvalue.Value ^ editFactor -- apply power
  265.                 dvalue.Value = math.max(1,dvalue.Value)
  266.                 if not entropic then
  267.                     dvalue.Value = math.min(.99*1e127,dvalue.Value) -- maximum to entropic activation
  268.                 end
  269.                 return true
  270.             elseif editType == "randomMult" then
  271.                 dvalue.Value = dvalue.Value * RNG(editFactor,editExtra) -- apply random
  272.                 dvalue.Value = math.max(1,dvalue.Value)
  273.                 if not entropic then
  274.                     dvalue.Value = math.min(.99*1e127,dvalue.Value) -- maximum to entropic activation
  275.                 end
  276.                 return true
  277.             elseif editType == "ANOMALY" then
  278.                 -- entropic activation
  279.                 EntActivate(dvalue,basev,part)
  280.                 return true
  281.             else
  282.                 return false,1 -- can't compare editType, return false
  283.             end
  284.         else
  285.             return false,2 -- cant find dropEdit, return failed
  286.         end
  287.         return true,3 -- return success
  288.     end
  289.     return false,4 -- return failed
  290. end
  291.  
  292. -- handle touch
  293.  
  294. local color = button.BrickColor
  295. local x = print
  296. button.Touched:connect(function(hit)
  297.     if deb[hit] then return end
  298.     if not hit then return end
  299.     if not hit.Parent then return end
  300.     if not hit.Name == "DropperDrop" then return end
  301.     local hitdeb = hit:FindFirstChild("deb")
  302.     if not hitdeb then return end
  303.     if hit:FindFirstChild("rdeb") then return end -- not able to upgrade cards no more lol
  304.     if hitdeb.Value then return end
  305.     local dvalue = hit:WaitForChild("DropData"):WaitForChild("DropValue")
  306.     dvalue.Value = math.max(1,dvalue.Value)
  307.     local success,problem,blink = applyEffect(hit, fld.UpgradeID.Value, dvalue)
  308.     if not success then
  309.         button.BrickColor = BrickColor.Red()
  310.         if problem then x('e6? well, ' ..problem.. ' is the code to be.') end
  311.         wait(3)
  312.         if blink then
  313.             button.BrickColor = blink
  314.         else
  315.             button.BrickColor = color
  316.         end
  317.         deb[hit] = nil
  318.         return
  319.     elseif fld:FindFirstChild("DropExtra") then
  320.         local drp = fld["DropExtra"]
  321.         if drp:FindFirstChild("NewParticle") and not hit:FindFirstChild("NewParticle") then
  322.             drp['NewParticle']:Clone().Parent = hit
  323.             hit.NewParticle.Enabled = true
  324.         end
  325.         if drp:FindFirstChild("Material") then
  326.             hit.Material = drp.Material.Value
  327.         end
  328.     end
  329.     --if not game.ReplicatedStorage.ProducingMore.Value then lib.DisappearDrop(hit) return -1 end
  330.     wait(.1)
  331.     if not button.BrickColor == color then button.BrickColor = color end
  332.     deb[hit]=nil
  333. end)
  334.  
  335. -- IG Tooltip
  336. Tooltip()
  337. HookupTooltip()
Advertisement
Add Comment
Please, Sign In to add comment