Advertisement
tyridge77

BrokenShinsClient

Aug 20th, 2013
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.40 KB | None | 0 0
  1. NOTE = [=[
  2. The client script for the Gladiatorial game I'm designing, communicates with the server to perform simple tasks
  3. ]=]
  4.  
  5.  
  6.  
  7.  
  8.  
  9. wait(1)
  10. --Services
  11.  
  12. local Players = game:GetService('Players');
  13. local ControllerService = game:GetService('ControllerService');
  14. local Lighting = game:GetService('Lighting');
  15. Spectating = true;
  16.  
  17. -- Lighting
  18.  
  19. local Items = Lighting.Items;
  20. local Weapons = Items.Weapons;
  21. -- Workspace
  22. local SpectatorSpawn = Workspace.SpectatorSpawn;
  23. local Cam = Workspace.CurrentCamera;
  24. local PoolCommunication = Workspace:WaitForChild('PoolCommunication');
  25. local PoolNote = PoolCommunication.Note;
  26. local Head1,Head2 = PoolCommunication.Head1,PoolCommunication.Head2;
  27. local InBattle = PoolCommunication.InBattle;
  28. local Spawn1,Spawn2 = Workspace.Spawn1,Workspace.Spawn2;
  29. local Exit1,Exit2 = Workspace.Exit1,Workspace.Exit2;
  30. local Reputation = PoolCommunication.Reputation;
  31. local Swap = PoolCommunication.Swap;
  32. -- Player
  33.  
  34. local Player = Players.LocalPlayer;
  35. repeat wait(0) until Player:FindFirstChild('Begin');
  36. local Begin = Player.Begin;
  37.  
  38. local PlayerName = Player.Name;
  39.  
  40.  
  41.  
  42. -- UI
  43.  
  44. local PlayerGui = Player.PlayerGui;
  45. local Scripts = PlayerGui:WaitForChild('Scripts');
  46. local MainUI = PlayerGui:WaitForChild('Main');
  47. local Title = MainUI.Title;
  48. local Note = MainUI.Note;
  49. local NoteLabel = Note.TextLabel
  50. local Slide,Join,Spectate = Title.Slide,Title.Join,Title.Spectate;
  51. local StatsF = MainUI.Stats;
  52. local FatigueL,HealthL = StatsF.Fatigue,StatsF.Health;
  53. local SpectateF = MainUI.Spectate;
  54. local Char1B,Char2B = SpectateF.Char1,SpectateF.Char2;
  55. local Mouse = Player:GetMouse();
  56. Title.Visible = true
  57. local Stats = Lighting.Stats:Clone(); Stats.Parent = Player;
  58. local Fatigue = Stats.Fatigue;
  59. local Health = Stats.Health;
  60. local MaxHealth = Stats.Health.MaxHealth;
  61.  
  62. -- Character
  63.  
  64. local Char = Player.Character;
  65. local Torso = Char.Torso;
  66. local Human = Char.Humanoid;
  67. local Head = Char.Head;
  68.  
  69. --Other
  70. local CFrame_fromEulerAnglesXYZ = CFrame.fromEulerAnglesXYZ;
  71. local math_random = math.random;
  72. local math_pi = math.pi;
  73. local Instance_new = Instance.new;
  74. local coroutine_resume,coroutine_create = coroutine.resume,coroutine.create;
  75.  
  76. -- UDim Variables
  77.  
  78. local UDim2_new = UDim2.new;
  79. local TitleOut = UDim2_new(0.25, 0, 0.300000012, 0);
  80. local TitleIn = UDim2_new(-0.52, 0, 0.300000012, 0);
  81. local NoteMiddle = UDim2_new(.25, 0, 0.0250000004, 0);
  82. local NoteOut = UDim2_new(1, 0, 0.0250000004, 0);
  83. local NoteIn = UDim2_new(-1, 0, 0.0250000004, 0);
  84. -- CFrame Variables
  85.  
  86. local CFrame_new = CFrame.new;
  87. local SpectateArena = CFrame_new(71.4063721, 217.901276, 612.066406, 0.534695625, 0.11910519, -0.836609006, 7.45057971e-009, 0.990017414, 0.140945449, 0.845044672, -0.0753629208, 0.52935797);
  88. local SpectateSpawn1 = CFrame_new(91.0122452, 213.525925, 528.652954, 0.161178812, -0.0930062011, 0.982533097, 9.31322575e-010, 0.995549738, 0.0942383409, -0.986925244, -0.015189223, 0.160461515);
  89. local SpectateSpawn2 = CFrame_new(190.143463, 215.344849, 613.225708, -0.20315595, 0.0812921226, -0.975765944, -0, 0.99654758, 0.0830234587, 0.979146421, 0.01686671, -0.202454552);
  90. Cam.CameraType = 'Scriptable';
  91. Cam.CoordinateFrame = SpectateArena;
  92.  
  93.  
  94. -- String Variables
  95.  
  96. local Status = 'Inactive';
  97. local Rep = 'Bad'
  98.  
  99. -- Functions
  100. local function GiveWeapons(txt,b)
  101.     local item = Weapons[txt];
  102.     local weld = Instance_new("Weld")
  103.     obj = item:clone()
  104.     obj.Parent = Workspace --p.Character
  105.     weld.Parent = obj.Handle
  106.     weld.Part0 = Char[item.Slot.Value]
  107.     weld.Part1 = obj.Handle
  108.     weld.C0 = item.OS.Value
  109.     weld.Name = "Pre"
  110.     Scripts[b].Value = obj             
  111. end
  112. function giveweaponslots()
  113.     local tbs = script.BackSlot:clone()
  114.     tbs.Parent = Char
  115.     local wb = Instance_new("Weld", tbs)
  116.     wb.Part0 = tbs
  117.     tbs.CFrame = Char.Torso.CFrame
  118.     wb.Part1 = Char.Torso
  119.     wb.C0 = CFrame_new(-.45, 0, -.65) * CFrame_fromEulerAnglesXYZ(0, 0, math_pi/12)
  120.        
  121.     local tbs2 = script.BackSlot:clone()
  122.     tbs2.Parent = Char
  123.     tbs2.Name = "OffSlot"
  124.     local wb2 = Instance_new("Weld", tbs2)
  125.     wb2.Part0 = tbs2
  126.     tbs2.CFrame = Char.Torso.CFrame
  127.     wb2.Part1 = Char.Torso
  128.     wb2.C0 = CFrame_new(.45, 0, -.65) * CFrame_fromEulerAnglesXYZ(0, 0, -math_pi/12)
  129.        
  130.     local tss = script.SideSlot:clone()
  131.     tss.Parent = Char
  132.     local ws = Instance_new("Weld", tss)
  133.     ws.Part0 = tss
  134.     tss.CFrame = Char["Left Arm"].CFrame
  135.     ws.Part1 = Char.Torso
  136.     ws.C0 = CFrame_new(1.15, .65, .95) * CFrame_fromEulerAnglesXYZ(math_pi/4, 0, 0)
  137.        
  138.     local b = script.SideSlot:clone()
  139.     b.Parent = Char
  140.     b.Name = "HandSlot"
  141.     local w = Instance_new("Weld", b)
  142.     w.Part0 = Char["Right Arm"]
  143.     w.Part1 = b
  144.     w.C0 = CFrame_new(0,-1.10,0) * CFrame_fromEulerAnglesXYZ(-math_pi/2,0,0)
  145.        
  146.     local b2 = script.SideSlot:clone()
  147.     b2.Parent = Char
  148.     b2.Name = "HandSlot2"
  149.     local w = Instance_new("Weld", b2)
  150.     w.Part0 = Char["Left Arm"]
  151.     w.Part1 = b2
  152.     w.C0 = CFrame_new(0,-1.10,0) * CFrame_fromEulerAnglesXYZ(-math_pi/2,0,0)
  153.        
  154.     --[[thairp = hairp:clone()
  155.     thairp.CFrame = head.CFrame
  156.     local hpw = Instance_new("Weld", head)
  157.     hpw.Part0 = head
  158.     hpw.Part1 = thairp
  159.     hpw.C0 = CFrame_new(0,.3,0)
  160.     thairp.Parent = Char]]
  161. end
  162. local function LookAtEntrance(Entrance,Head)
  163.     Cam:Interpolate(Entrance,Head.CFrame,2);
  164. end
  165. local function TweenIn()
  166.     Title:TweenPosition(TitleIn,'Out','Linear',.1,true,nil)
  167. end
  168. local function TweenOut()
  169.     Title:TweenPosition(TitleOut,'Out','Linear',.25,true,nil);
  170. end
  171. local function Notify(text)
  172.     coroutine_resume(coroutine_create(function()
  173.     if Tweening then repeat wait(0) until not Tweening end
  174.     NoteLabel.Text = text;
  175.     Tweening = true
  176.     Note:TweenPosition(NoteMiddle,'Out','Linear',.25,true,nil)
  177.     wait(2)
  178.     Note:TweenPosition(NoteOut,'Out','Linear',.5,true,nil)
  179.     wait(.6)
  180.     Note.Position = NoteIn;
  181.     Tweening = nil
  182.     end))
  183. end
  184. local function Transmit(text)
  185.     Status = text
  186.     if PoolCommunication:FindFirstChild(PlayerName) then
  187.        PoolCommunication:FindFirstChild(PlayerName):Destroy();
  188.     end
  189.     wait(1)
  190.     local val = Instance_new('StringValue',PoolCommunication);
  191.     val.Name = PlayerName;
  192.     val.Value = text;
  193. end
  194. local function SpectateInterpolate()
  195.     Interpolating = true;
  196.     while Interpolating do wait(.1);
  197.         if CamTarget then
  198.             Cam:Interpolate(CFrame_new(CamTarget.Position + -(CamTarget.CFrame.lookVector*20) + Vector3.new(0,8,0)),CamTarget.CFrame,.2)
  199.         end
  200.     end
  201. end
  202. local function RegenStats()
  203.     local maxhealth = Health.MaxHealth.Value;
  204.     local maxfatigue = Fatigue.MaxFatigue.Value;
  205.     local healthinc = 1;
  206.     local fatigueinc = 4;
  207.     Regening = true;
  208.     while Regening do
  209.        local healthval = Health.Value;
  210.        local fatigueval = Fatigue.Value;
  211.        Health.Value =
  212.        healthval + healthinc <= maxhealth and healthval + healthinc or healthval;
  213.        Fatigue.Value =
  214.        fatigueval + fatigueinc <= maxfatigue and fatigueval + fatigueinc or fatigueval;
  215.        wait(2)
  216.     end
  217. end
  218.  
  219. -- World Events
  220.  
  221. local NoteListener = PoolNote.Changed:connect(function()
  222.     Notify(PoolNote.Value);
  223. end)
  224. local function ConnectSpectateListener()
  225.     SpectateListener = InBattle.Changed:connect(function()
  226.         if InBattle.Value == true  and Spectating then
  227.         --if Status == 'Inactive' then return end
  228.         TweenIn();
  229.         while Head1.Value == nil do wait(1) Notify('|Error with object value|') end
  230.         LookAtEntrance(SpectateSpawn1,Exit1);
  231.         repeat wait(1) until Swap.Value == true
  232.         LookAtEntrance(SpectateSpawn2,Exit2);
  233.         repeat wait(1) until Swap.Value == false
  234.         CamTarget = Head1.Value and Head1.Value or nil
  235.         SpectateF.Visible = true
  236.         SpectateInterpolate();
  237.         elseif InBattle.Value == false then print('Reseting');
  238.             Torso.CFrame = SpectatorSpawn.CFrame;
  239.             Cam.CameraType = 'Scriptable';
  240.             Cam.CoordinateFrame = SpectateArena;
  241.             wait(1)
  242.             TweenOut();
  243.         end
  244.     end)
  245. end
  246. ConnectSpectateListener()
  247. local BeginListener = Begin.Changed:connect(function()
  248.     Transmit('Spectating');
  249.     if SpectateListener then Spectating = nil end
  250.     if Head == Head2.Value then
  251.        Human.WalkSpeed = 0;
  252.         LookAtEntrance(SpectateSpawn1,Exit1);
  253.         repeat wait(1) until Swap.Value == true
  254.        Human.WalkSpeed = 16;
  255.     end
  256.     local goal;
  257.     local begin = Begin.Value;
  258.     Torso.CFrame = begin.CFrame;
  259.     Cam.CameraType = 'Custom'
  260.     Player.CameraMode = 'LockFirstPerson';
  261.     if begin == Spawn1 then
  262.         goal = Exit1;
  263.     else
  264.         goal = Exit2;
  265.     end
  266.     repeat wait(0) until (Torso.Position-goal.Position).Magnitude < 5
  267.     Reputation.Value = Player.Name..'/'..Rep;
  268.     giveweaponslots();
  269.     GiveWeapons('Rusty Sword','Blade');
  270.     GiveWeapons('Wooden Shield','OffHand')
  271.     Notify('Press E To Unsheath');
  272.     Notify('Z for emotes');
  273.     RegenStats();
  274.    
  275. end)
  276. -- UI Events
  277.  
  278. local SlideClick = Slide.MouseButton1Click:connect(function()
  279.     TweenOut();
  280. end)
  281. local JoinClick = Join.MouseButton1Click:connect(function()
  282.     TweenIn();
  283.     Notify('Joining pool...');
  284.     Transmit('SpectatingReady');
  285. end)
  286. local SpectateClick = Spectate.MouseButton1Click:connect(function()
  287.     TweenIn();
  288.     Notify('Spectating only...')
  289.     Transmit('Spectating');
  290. end)
  291. local Char1BC = Char1B.MouseButton1Down:connect(function()
  292.     if Head1.Value then CamTarget = Head1.Value
  293.     end
  294. end)
  295. local Char2BC = Char2B.MouseButton1Down:connect(function()
  296.     if Head2.Value then CamTarget = Head2.Value
  297.     end
  298. end)
  299. local HealthTxt = 'Health: ';
  300. local FatigueTxt = 'Fatigue: '
  301. local UpdateHealth = Health.Changed:connect(function()
  302.     HealthL.Text = HealthTxt..Health.Value;
  303. end)
  304. local UpdateFatigue = Fatigue.Changed:connect(function()
  305.     FatigueL.Text = FatigueTxt..Fatigue.Value;
  306. end)
  307.     FatigueL.Text = HealthTxt..Fatigue.Value;
  308.     HealthL.Text = FatigueTxt..Health.Value;
  309. Notify(PoolNote.Value);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement