Advertisement
_Andrew27_

Retail Tycoon Copy Stores

Feb 15th, 2023 (edited)
2,527
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.82 KB | None | 0 0
  1. -- by bvthxry : copy script
  2. -- u obv need $$ for this
  3.  
  4. --settings
  5. target = 'playername'
  6. copyWorkers = true
  7. copyTycoonProperties = true
  8. copySignCeilingTexts = true
  9.  
  10. --~~~~
  11. local lp = game.Players.LocalPlayer
  12. local ltycoon = workspace.Functions.GetTycoon:InvokeServer()
  13. local ptycoon
  14. for i = 1, 6 do
  15.     local t = workspace['Tycoon'..i]
  16.     ptycoon = not nil and ptycoon or t.Info.Owner.Value==target and t
  17. end
  18.  
  19. function notify(msg)
  20.     lp.PlayerGui.Notifications.NotifyFunction:Invoke(msg, Color3.new(1,1,1))
  21. end
  22.  
  23. function makeFurni(FurniParent_AkaTileModel, Rotation, Type, Color)
  24.     workspace.Functions.Furniture:FireServer(ltycoon, FurniParent_AkaTileModel, Rotation, Type, Color);
  25. end
  26.  
  27. function deleteFurni(furniModel)
  28.     workspace.Functions.SellFurniture:FireServer(furniModel)
  29. end
  30.  
  31. function makeCeiling(CeilingParent_AkaTileModel, Type, isRot, Color)
  32.     workspace.Functions.Ceiling:FireServer(true, CeilingParent_AkaTileModel, Type, isRot, Color);
  33. end
  34.  
  35. function deleteCeiling(ceilingModel)
  36.     deleteFurni(ceilingModel)
  37. end
  38.  
  39. function makeWall(Type, Pos, Color) -- GlassWall22 / CFrame / Color3
  40.     workspace.Functions.Wall:FireServer(true, ltycoon.Walls, Type, Pos, Color);
  41. end
  42.  
  43. function deleteWall(wallmodel)
  44.     workspace.Functions.Wall:FireServer(false, wallmodel);
  45. end
  46.  
  47. if copyWorkers then
  48.     for i, v in pairs(ptycoon.WorkerList:GetChildren()) do
  49.         workspace.Functions.SetWorker:FireServer(ltycoon, v.Name, v.Value)
  50.     end
  51. end
  52.  
  53. if copyTycoonProperties then
  54.     for i, v in pairs(ptycoon.Info:GetChildren()) do
  55.         local exclusions = {'Origin', 'Owner', 'Autosave'}
  56.         if not table.find(exclusions, v.Name) then
  57.             workspace.Functions.EditTycoon:FireServer(ltycoon, v.Name, v.Value)
  58.         end
  59.     end
  60. end
  61.  
  62. local PTiles, LTiles = {}, {} -- [TileModel] = Vector3
  63.  
  64. for i, tile in pairs(ptycoon.Tiles:GetChildren()) do -- PTiles
  65.     local base = ptycoon.TycoonBase
  66.     local delta = (base.Position - tile.Tile.Position)
  67.     if base.Position.x < 0 then
  68.         delta = Vector3.new(-delta.x,0,-delta.z)
  69.     end
  70.     PTiles[tile] = Vector3.new(delta.X,0,delta.Z)
  71. end
  72.  
  73. for i, tile in pairs(ltycoon.Tiles:GetChildren()) do -- LTiles
  74.     local base = ltycoon.TycoonBase
  75.     local delta = (base.Position - tile.Tile.Position)
  76.     if base.Position.x < 0 then
  77.         delta = Vector3.new(-delta.x,0,-delta.z)
  78.     end
  79.     LTiles[tile] = Vector3.new(delta.X,0,delta.Z)
  80. end
  81.  
  82. local Flooring = {
  83.     Concrete = 'Concrete',
  84.     Cobblestone = 'Stone',
  85.     Fabric = 'Carpet',
  86.     WoodPlanks = 'Wood',
  87.     Marble = 'Marble'
  88. }
  89.  
  90. getLTile = function(ptile)
  91.     for ltile, ltilepos in pairs(LTiles) do
  92.         local ptilepos = PTiles[ptile]
  93.         if ltilepos == ptilepos then
  94.             return ltile
  95.         end
  96.     end
  97. end
  98.  
  99. local detectedtiles = 0
  100. local amountOfPTiles = 0
  101. local amountOfLTiles = 0
  102.  
  103. for i, ppos in pairs(PTiles) do
  104.     amountOfPTiles = amountOfPTiles + 1
  105.     amountOfLTiles = 0 -- only starts counting at the last loop
  106.     for i, lpos in pairs(LTiles) do
  107.         amountOfLTiles = amountOfLTiles + 1
  108.         if ppos == lpos then
  109.             detectedtiles = detectedtiles + 1
  110.         end
  111.     end
  112. end
  113.  
  114. if math.min(amountOfLTiles, amountOfPTiles) == detectedtiles then
  115.     notify'preparing to copy, wiping store'
  116. else
  117.     notify'error, buy more land'
  118.     return
  119. end
  120.  
  121. --wipe everything
  122. for ltile, _ in pairs(LTiles) do
  123.     for _, model in pairs(ltile:children()) do
  124.         if model:isA'Model' then --we dont want to delete everything o.0
  125.             deleteFurni(model)
  126.         end
  127.     end
  128. end
  129.  
  130. for ltile, _ in pairs(LTiles) do
  131.     workspace.Functions.Flooring:FireServer(false, ltile)
  132. end
  133.  
  134. for _, wall in pairs(ltycoon.Walls:GetChildren()) do
  135.     deleteWall(wall)
  136. end
  137.  
  138. --start building
  139. local check
  140. repeat wait()
  141.     check = true
  142.     for i, v in pairs(ltycoon.Tiles:GetChildren()) do
  143.         local modelexists = v:FindFirstChildOfClass'Model'
  144.         if modelexists or v.Tile.Material.Name~='Grass' then
  145.             check = false
  146.             break
  147.         end
  148.     end
  149. until #ltycoon.Walls:GetChildren() == 0 and check
  150.  
  151. local signMirrors = {}
  152. local signCeilingData = {}
  153. local NSE = lp.Events.NewSignEvent.OnClientEvent:Connect(function(Gui,Part,UpdateSign)
  154.     table.insert(signCeilingData, {
  155.         updateRemote = UpdateSign,
  156.         part = Part,
  157.         gui = Gui,
  158.         lceiling = Part.Parent
  159.     })
  160. end)
  161.  
  162. notify'starting to build'
  163.  
  164. for i = 1, 5 do -- parking / sign
  165.     if ptycoon:FindFirstChild('Lot'..i) then
  166.         workspace.Functions.NewParking:InvokeServer(ltycoon, i)
  167.     end
  168.     if ptycoon:FindFirstChild('Sign'..i) then
  169.         workspace.Functions.NewSign:InvokeServer(ltycoon, i)
  170.     end
  171. end
  172.  
  173. for ptile, _ in pairs(PTiles) do -- flooring
  174.     local ltile = getLTile(ptile)
  175.     if ptile.Tile.Material ~= ltile.Tile.Material and ptile.Tile.Material.Name ~= 'Grass' then
  176.         workspace.Functions.Flooring:FireServer(true, ltile, Flooring[ptile.Tile.Material.Name])
  177.     end
  178. end
  179.  
  180. local Ceilings = {
  181.     'Skylight20',
  182.     'Speaker20',
  183.     'LargeLight20',
  184.     'SmallSign20',
  185.     'LargeSign20',
  186.     'SmallLight20',
  187.     'Default20',
  188.     'SmallSign12',
  189.     'Default12',
  190.     'SmallLight12',
  191.     'Speaker12',
  192.     'Skylight12'
  193. }
  194.  
  195. for ptile, _ in pairs(PTiles) do -- furnitures / ceilings
  196.     local ltile = getLTile(ptile)
  197.     for i, v in pairs(ptile:GetChildren()) do
  198.         if v:isA'Model' and v.Name ~= 'Spill' then
  199.            
  200.             local Color = Color3.new(.8, 0, .8)
  201.             if v:FindFirstChild'ColorPart' then
  202.                 Color = v.ColorPart.Color
  203.             end
  204.            
  205.             if table.find(Ceilings, v.Name) then
  206.                 makeCeiling(ltile, v.Name, v.Base.Rotation.Y==0, Color)
  207.                 local isSign = (v.Name:match'Sign'~=nil)
  208.                 if isSign then
  209.                     local ceiling = ltile:WaitForChild(v.Name)
  210.                     signMirrors[ceiling]=v
  211.                     signMirrors[v]=ceiling
  212.                 end
  213.             else
  214.                 local Rot = v:FindFirstChild'Rotation'
  215.                 makeFurni(ltile, Rot and Rot.Value or 0, v.Name, Color)
  216.                
  217.                 if v:FindFirstChild'Item' then -- if its a display item
  218.                     if v.Item.Value ~= 'Empty' then -- if its empty ignore
  219.                         local furni = ltile:WaitForChild(v.Name)
  220.                         spawn(function()
  221.                             workspace.Functions.NewStock:InvokeServer(ltycoon, furni, v.Item.Value)
  222.                         end)
  223.                     end
  224.                 end
  225.             end
  226.         end
  227.     end
  228. end
  229.  
  230. for i, wall in pairs(ptycoon.Walls:GetChildren()) do --walls
  231.     local pbase, lbase = ptycoon.TycoonBase, ltycoon.TycoonBase
  232.     local pdelta = (wall.PrimaryPart.Position - pbase.Position)
  233.    
  234.     if pbase.Position.x < 0 then
  235.         pdelta = Vector3.new(-pdelta.x,7,-pdelta.z)
  236.     else
  237.         pdelta = Vector3.new(pdelta.x,7,pdelta.z)
  238.     end
  239.    
  240.     local newpos
  241.     if lbase.Position.x > 0 then
  242.         newpos = (lbase.CFrame + pdelta)
  243.     else
  244.         newpos = (lbase.CFrame - pdelta) * CFrame.new(0,14,0)
  245.     end
  246.     newpos = newpos * CFrame.Angles(0, math.rad(wall.PrimaryPart.Rotation.Y+90), 0)
  247.    
  248.     local Color = Color3.new(.8, 0, .8)
  249.     if wall:FindFirstChild'ColorPart' then
  250.         Color = wall.ColorPart.Color
  251.     end
  252.     makeWall(wall.Name, newpos, Color)
  253. end
  254.  
  255. if copySignCeilingTexts then
  256.     for _, data in pairs(signCeilingData) do
  257.         local pceiling = signMirrors[data.lceiling]
  258.         local surfacegui = pceiling:FindFirstChild(data.gui.Name, true)
  259.         local text = surfacegui.Label.Text
  260.         spawn(function()
  261.             data.updateRemote:InvokeServer(text,data.gui.Name,data.part)
  262.         end)
  263.         data.gui.TextBox.Text=text -- so it shows locally
  264.     end
  265. end
  266. NSE:Disconnect()
  267.  
  268. notify'done'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement