Advertisement
Descaii

2D Game ServerSide Joiner

Feb 22nd, 2014
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.45 KB | None | 0 0
  1. -- Joiner --
  2. --http://www49.zippyshare.com/v/38178937/file.html
  3. --Mouse=game.Players.LocalPlayer:GetMouse();Mouse.Button1Down:connect(function()ypcall(function()print(Mouse.Target)local a = Mouse.Target.Parent Mouse.Target:Destroy() a:Destroy() end)end)
  4. ScreenSize = 1000
  5. Players = {}
  6. Screens = {}
  7. GlobalObjects = {}
  8. function clerp(c1,c2,sp)
  9.     return CFrame.new(
  10.         c1.X+(c2.X-c1.X)*sp,
  11.         c1.Y+(c2.Y-c1.Y)*sp,
  12.         c1.Z+(c2.Z-c1.Z)*sp
  13.     )
  14. end
  15. local PBT = Instance.new("Part",script)
  16. PBT.Transparency = 1
  17. PBT.Anchored = true
  18. local PBTG = Instance.new("SurfaceGui",PBT)
  19. PBTG.CanvasSize = Vector2.new(500,200)
  20. PBT.FormFactor = "Custom"
  21. PBT.Size = Vector3.new(5,2,1)
  22. PBTS = Vector3.new(5,2,1)
  23. PBTC = CFrame.new(0,3,20)
  24. local PBTGB = Instance.new("TextLabel",PBTG)
  25. PBTGB.Size = UDim2.new(1,0,1,0)
  26. PBTGB.BackgroundColor3 = Color3.new(0,1,0)
  27. PBTGB.Text = "Play"
  28. PBTGB.TextScaled = true
  29. PBT.CFrame = CFrame.new(0,2,0)
  30. local Play = Instance.new("ClickDetector",PBT)
  31. Play.MouseClick:connect(function(player)
  32.     ypcall(function()
  33.         if not player:findFirstChild("IsPlaying") then
  34.             NLS(game:GetService("HttpService"):GetAsync("http://pastebin.com/raw.php?i=m8JPNBBn"),player.Backpack)
  35.         end
  36.     end)
  37. end)
  38. function NewScreen(World)
  39.     local PlayerGui = Instance.new("Part",script)
  40.     PlayerGui.Anchored = true
  41.     PlayerGui.FormFactor = "Custom"
  42.     --PlayerGui.Size = Vector3.new(ScreenSize/100,ScreenSize/100,0)
  43.     PlayerGui.CFrame = CFrame.new(0,(ScreenSize/100)/2,0)
  44.     PlayerGui.Transparency = 1
  45.     local Play = Instance.new("ClickDetector",PlayerGui)
  46.     local A = #Screens+1
  47.     Play.MouseClick:connect(function(player)
  48.         ypcall(function()
  49.             --[[if not player:findFirstChild("IsPlaying") then
  50.                 NLS(game:GetService("HttpService"):GetAsync("http://pastebin.com/raw.php?i=m8JPNBBn"),player.Backpack)
  51.             end]]
  52.             CurrentWorld = A
  53.         end)
  54.     end)
  55.     local Screen = Instance.new("SurfaceGui",PlayerGui)
  56.     Screen.Name = "2DGame"
  57.     Screen.CanvasSize = Vector2.new(ScreenSize,ScreenSize)
  58.     local Background = Instance.new("ImageLabel",Screen)
  59.     BackgroundID = World.ID
  60.     Background.Image = "http://www.roblox.com/asset/?id="..BackgroundID-1
  61.     Background.Size = UDim2.new(0,1000,0,600)
  62.     Background.Position = UDim2.new(0.5,-500,0.5,-300)
  63.     local Title = Instance.new("TextLabel",Background)
  64.     Title.Size = UDim2.new(0,200,0,50)
  65.     Title.Text = "World"
  66.     Title.TextColor3 = Color3.new(0.5,0.5,0.5)
  67.     Title.TextWrapped = false
  68.     Title.BackgroundTransparency = 1
  69.     Title.FontSize = "Size14"
  70.     Title.Position = UDim2.new(0.5,-100,0,0)
  71.     local A = {}
  72.     A.PG = PlayerGui
  73.     A.SC = Screen
  74.     A.BK = Background
  75.     A.World = World
  76.     A.Title = Title
  77.     A.PlayButton = Play
  78.     table.insert(Screens,A)
  79.     return A
  80. end
  81. Worlds = {
  82.     --{Height = 400,ID = 161283188,Size = Vector2.new(1000,600),Objects={}},
  83.     --{Height = 400,ID = 161397987,Size = Vector2.new(1000,600),Objects={}},
  84.     --{Height = 400,ID = 161402869,Size = Vector2.new(1000,600),Objects={}},
  85.     --{Height = 400,ID = 161413779,Size = Vector2.new(1000,600),Objects={}}
  86. }
  87. function NewWorld(Name,Height,ID,TSize)
  88.     local A = {}
  89.     A.Height = Height
  90.     A.ID = ID
  91.     A.Size = TSize
  92.     A.Objects = {}
  93.     A.Name = Name
  94.     function A:NewObject(LSize,LPosition)
  95.         local B = Instance.new("Frame",Background)
  96.         B.Size = UDim2.new(0,LSize.X,0,LSize.Y)
  97.         B.Position = UDim2.new(0,LPosition.X,0,LPosition.Y)
  98.         local C = {}
  99.         C.B = B
  100.         C.World = A
  101.         function C:IsAbove(V)
  102.             local X = V.X
  103.             local Y = V.Y
  104.             if Y < B.Position.Y.Offset+LSize.Y/2 and X > B.Position.X.Offset and X < B.Position.X.Offset+LSize.X then
  105.                 return true
  106.             else
  107.                 return nil
  108.             end
  109.         end
  110.         function C:IsBelow(V)
  111.             local X = V.X
  112.             local Y = V.Y
  113.             if Y > B.Position.Y.Offset+LSize.Y/2 and X > B.Position.X.Offset and X < B.Position.X.Offset+LSize.X then
  114.                 return true
  115.             else
  116.                 return nil
  117.             end
  118.         end
  119.         table.insert(A.Objects,C)
  120.         table.insert(GlobalObjects,Y)
  121.     end
  122.     table.insert(Worlds,A)
  123.     return A
  124. end
  125. First = NewWorld("Grasslands(Earth)",500,161283188,Vector2.new(1000,600))
  126. First:NewObject(Vector2.new(100,50),Vector2.new(0,400))
  127. First:NewObject(Vector2.new(100,50),Vector2.new(150,350))
  128. NewWorld("Terrain(Earth)",500,161397987,Vector2.new(1000,600))
  129. NewWorld("Cloudy(Earth)",500,161402869,Vector2.new(1000,600))
  130. NewWorld("Maket(Planet)",500,161413779,Vector2.new(1000,600))
  131. for i,v in pairs(Worlds) do
  132.     NewScreen(v)
  133. end
  134. function ChangeToWorld(Num)
  135.     if Worlds[Num] then
  136.         for i,v in pairs(RealWorld.Objects) do
  137.             v.B.Visible = false
  138.         end
  139.         CurrentWorld = Num
  140.     end
  141.     local Length
  142.     if tonumber(Num) then
  143.         Length = 1
  144.     else
  145.         Length = #Num
  146.     end
  147.     for i,v in pairs(Worlds) do
  148.         if string.sub(v.Name,1,Length) == Num then
  149.             for i,v in pairs(RealWorld.Objects) do
  150.                 v.B.Visible = false
  151.             end
  152.             CurrentWorld = i
  153.         end
  154.     end
  155. end
  156. function ChangeWorld(up)
  157.     if up then
  158.         ChangeToWorld(CurrentWorld+1)
  159.     else
  160.         ChangeToWorld(CurrentWorld-1)
  161.     end
  162. end
  163. function GetOffsetByRotation(Rotation,Position,Offset)
  164. end
  165. CurrentWorld = 1
  166. RealWorld = Worlds[CurrentWorld]
  167. --[[GoForward = Instance.new("TextButton",Background)
  168. GoForward.Size = UDim2.new(0,40,0,40)
  169. GoForward.Text = ">"
  170. GoForward.TextScaled = true
  171. GoForward.BackgroundColor3 = Color3.new(255,255,0)
  172. GoForward.Position = UDim2.new(1,-50,0.5,-20)
  173. GoForward.ZIndex = 10
  174. GoBackward = Instance.new("TextButton",Background)
  175. GoBackward.Size = UDim2.new(0,40,0,40)
  176. GoBackward.Text = "<"
  177. GoBackward.TextScaled = true
  178. GoBackward.BackgroundColor3 = Color3.new(255,255,0)
  179. GoBackward.Position = UDim2.new(0,10,0.5,-20)
  180. GoBackward.ZIndex = 10
  181. GoForward.MouseButton1Click:connect(function()
  182.     ChangeWorld(true)
  183. end)
  184. GoBackward.MouseButton1Click:connect(function()
  185.     ChangeWorld(false)
  186. end)
  187. HD = false
  188. FD = false
  189. Jump = false]]
  190. mc = math.ceil
  191. Commands = {}
  192. --0.5,0.5,0.5
  193. function NewPlayer(Pos)
  194.     local NHealth = Pos:findFirstChild("Health")
  195.     local NRemote = Pos:findFirstChild("Remote")
  196.     local NChatted = Pos:findFirstChild("Chatted")
  197.     if NHealth and NRemote and NChatted and Pos.Parent and Pos.Parent:IsA("Player") then
  198.         local NPlayerInstance = Pos.Parent
  199.         local NPlayer = Instance.new("Frame",Background)
  200.         NPlayer.Size = UDim2.new(0,40,0,100)
  201.         NPlayer.Position = UDim2.new(0,Pos.Value.X,0,Pos.Value.Y-100)
  202.         local NHead = Instance.new("Frame",Background)
  203.         NHead.Size = UDim2.new(0,40,0,30)
  204.         local NEye = Instance.new("Frame",NHead)
  205.         NEye.BackgroundColor3 = Color3.new(0,0,0)
  206.         NEye.Position = UDim2.new(0,5,0,10)
  207.         NEye.Size = UDim2.new(0,10,0,10)
  208.         local C = Instance.new("TextLabel",Background)
  209.         C.TextColor3 = Color3.new(1,1,1)
  210.         C.TextStrokeColor3 = Color3.new(0,0,0)
  211.         C.TextStrokeTransparency = 0.5
  212.         C.Text = tostring(Pos.Parent)
  213.         C.ZIndex = 6
  214.         C.Size = UDim2.new(0,C.TextBounds.X,0,C.TextBounds.Y)
  215.         C.BackgroundTransparency = 1
  216.         local D = {}
  217.         D.F = NPlayer
  218.         D.Pos = Pos
  219.         D.H = NHead
  220.         D.C = C
  221.         D.World = NHealth.Value.Z
  222.         D.Chats = {}
  223.         for i,v in pairs(Pos:GetChildren()) do
  224.             D[v.Name]=v
  225.         end
  226.         D.ChatTxt = function(chat)
  227.             if not D.Deleted then
  228.                 local Chat = {}
  229.                 Chat.Pos = 0
  230.                 Chat.Gui = Instance.new("TextLabel",Background)
  231.                 Chat.Gui.Text = chat
  232.                 Chat.Age = 0
  233.                 Chat.Gui.Size = UDim2.new(0,Chat.Gui.TextBounds.X+30,0,Chat.Gui.TextBounds.Y+10)
  234.                 Chat.Gui.BackgroundColor3 = Color3.new(1,1,1)
  235.                 Chat.Gui.BackgroundTransparency = 0.5
  236.                 Chat.Gui.BorderSizePixel = 0
  237.                 for i,v in pairs(D.Chats) do
  238.                     v.Pos = v.Pos +30
  239.                 end
  240.                 table.insert(D.Chats,Chat)
  241.                 if #D.Chats > 3 then
  242.                     D.Chats[1].Gui:Destroy()
  243.                     table.remove(D.Chats,1)
  244.                 end
  245.             end
  246.         end
  247.         D.Player = NPlayerInstance
  248.         D.Deleted = false
  249.         function D:Destroy()
  250.             if not D.Deleted then
  251.                 for i,v in pairs(Players) do
  252.                     if v == D then
  253.                         table.remove(Players,i)
  254.                         v.F:Destroy()
  255.                         v.C:Destroy()
  256.                         v.H:Destroy()
  257.                         v.Deleted = true
  258.                         for i,v in pairs(v.Chats) do
  259.                             v.Gui:Destroy()
  260.                         end
  261.                     end
  262.                 end
  263.             end
  264.         end
  265.         NPlayerInstance.CharacterAdded:connect(function()
  266.             D:Destroy()
  267.             for i,v in pairs(NPlayerInstance:GetChildren()) do
  268.                 if v.Name == "IsPlaying" then
  269.                     v:Destroy()
  270.                 end
  271.             end
  272.         end)
  273.         D.Player.Chatted:connect(function(chat)
  274.             D.ChatTxt(chat)
  275.         end)
  276.         table.insert(Players,D)
  277.         --print("New Player: " ..tostring(Pos.Parent),Pos.Value)
  278.     end
  279. end
  280. function FindPlayer(Name)
  281.     local FoundName = nil
  282.     for i,v in pairs(Players) do
  283.         if v.Pos.Parent then
  284.             if v.Pos.Parent.Name == Name then
  285.                 FoundName = true
  286.             end
  287.         end
  288.     end
  289.     return FoundName
  290. end
  291. coroutine.resume(coroutine.create(function()
  292.     while wait(1) do
  293.         for i,d in pairs(Players) do
  294.             for i,v in pairs(d.Chats) do
  295.                 v.Age = v.Age +1
  296.                 if v.Age > 5 then
  297.                     v.Gui:Destroy()
  298.                     table.remove(d.Chats,i)
  299.                 end
  300.             end
  301.         end
  302.     end
  303. end))
  304. while wait() do
  305.     --[[if Worlds[CurrentWorld+1] then
  306.         GoForward.Visible = true
  307.     else
  308.         GoForward.Visible = false
  309.     end
  310.     if Worlds[CurrentWorld-1] then
  311.         GoBackward.Visible = true
  312.     else
  313.         GoBackward.Visible = false
  314.     end]]
  315.     --print(Worlds)
  316.     --print(RealWorld)
  317.     for i,v in pairs(game.Players:GetPlayers()) do
  318.         if v ~= Player then
  319.             if v:findFirstChild("IsPlaying") then
  320.                 if not FindPlayer(v.Name) then
  321.                     NewPlayer(v:findFirstChild("IsPlaying"))
  322.                 end
  323.             end
  324.         end
  325.     end
  326.     PBT.Size = clerp(PBT.Size,PBTS,0.1).p
  327.     PBT.CFrame = clerp(PBT.CFrame,PBTC,0.1)
  328.     if PBT.CFrame.Y > PBTC.Y+5 then
  329.         PBT.CFrame = PBTC
  330.     end
  331.     for _,World in pairs(Screens) do
  332.         local SZR = 100
  333.         if _ ~= CurrentWorld then
  334.             SZR = 250
  335.         end
  336.         RealWorld = World.World
  337.         World.BK.Size = UDim2.new(0,RealWorld.Size.X,0,RealWorld.Size.Y)
  338.         World.PG.Size = clerp(World.PG.Size,Vector3.new(1500/SZR,1500/SZR,1),0.1).p
  339.         World.PG.CFrame = clerp(World.PG.CFrame,CFrame.new(((1500/100)*-((_-CurrentWorld))),((1500/100)/2)+5,20),0.1)
  340.         --[[World.PG.CFrame = clerp(World.PG.CFrame,
  341.             CFrame.new(0,25,20)
  342.             *CFrame.Angles(0,0,math.rad(360*(_/#Screens))-math.rad(360*(CurrentWorld/#Worlds))+math.rad(180))
  343.             *CFrame.new(0,15,0)
  344.         ,0.1)]]
  345.         World.Title.Text = RealWorld.Name
  346.         if World.BK.Image ~= "http://www.roblox.com/asset/?id="..RealWorld.ID-1 then
  347.             World.BK.Image = "http://www.roblox.com/asset/?id="..RealWorld.ID-1
  348.         end
  349.         for i,v in pairs(RealWorld.Objects) do
  350.             v.B.Visible = true
  351.             v.B.Parent = v.SC
  352.         end
  353.         for i,v in pairs(Players) do
  354.             v.World = v.Health.Value.Z
  355.             if Worlds[v.World] == RealWorld then
  356.                 --[[if v.World ~= CurrentWorld then
  357.                     v.F.Visible = false
  358.                     v.H.Visible = false
  359.                     v.C.Visible = false
  360.                     for i,d in pairs(v.Chats) do
  361.                         d.Gui.Visible = false
  362.                     end
  363.                 else
  364.                     v.F.Visible = true
  365.                     v.H.Visible = true
  366.                     v.C.Visible = true
  367.                     for i,d in pairs(v.Chats) do
  368.                         d.Gui.Visible = true
  369.                     end
  370.                 end]]
  371.                 v.F.Position = UDim2.new(0,v.Pos.Value.X,0.5,v.Pos.Value.Y-400)
  372.                 v.F.Parent = World.SC
  373.                 v.H.Position = v.F.Position -UDim2.new(0,0,0,30)
  374.                 v.H.Rotation = v.Pos.Value.Z
  375.                 v.H.Parent = World.SC
  376.                 v.C.Position = v.F.Position -UDim2.new(0,0,0,90)
  377.                 v.C.Text = tostring(v.Pos.Parent)
  378.                 v.C.Parent = World.SC
  379.                 --print(v.Chatted)
  380.                 for _,d in pairs(v.Chats) do
  381.                     d.Gui.Position = v.F.Position-UDim2.new(0,(-5)+((#d.Gui.Text*5)/2+5),0,120+(d.Pos))
  382.                     d.Gui.Size = UDim2.new(0,(#d.Gui.Text*5)+10,0,20)
  383.                     d.Gui.Parent = World.SC
  384.                 end
  385.                 v.C.Size = UDim2.new(0,v.C.TextBounds.X,0,v.C.TextBounds.Y)
  386.                 --print(v.Count)
  387.                 --print(v.Health.Value.Z)
  388.                 if not v.Pos.Parent or not v.Pos.Parent:IsA("Player") or not v.Pos.Parent:IsDescendantOf(game.Players) then
  389.                     v:Destroy()
  390.                 end
  391.                 v.Count = v.Health.Value.Z
  392.             end
  393.         end
  394.     end
  395. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement