Advertisement
tyridge77

Atmosphere

Jun 8th, 2013
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 14.79 KB | None | 0 0
  1. --UDim2 variables
  2.  
  3. local UDim2_new = UDim2.new;
  4. local OriginalTween = UDim2_new(0,0,0,0)
  5. local NegativeTween = UDim2_new(-1.5,0,0,0);
  6.  
  7. --Mathematical Variables
  8.  
  9. local math_random = math.random;
  10. local math_abs = math.abs;
  11. local math_rad = math.rad;
  12. local math_cos = math.cos;
  13. local math_sin = math.sin;
  14.  
  15. -- Coroutines
  16. local coroutine_resume = coroutine.resume;
  17. local coroutine_create = coroutine.create;
  18.  
  19. --Table Manipulation
  20.  
  21. local table_insert = table.insert;
  22.  
  23. --Instancing
  24.  
  25. local Instance_new = Instance.new;
  26.  
  27. --Vector3 Variables
  28.  
  29. local Vector3_new = Vector3.new;
  30.  
  31. --Mathematical Variables
  32.  
  33. local math_min = math.min;
  34.  
  35. --CFrame Variables
  36.  
  37. local CFrame_new = CFrame.new;
  38.  
  39. --Rays
  40.  
  41. local Ray_new = Ray.new;
  42.  
  43.  
  44. -- Bools
  45.  
  46.  
  47. local frozen = false;
  48.  
  49.  
  50.  
  51.  
  52.  
  53. --Color
  54.  
  55. local Color3_new = Color3.new;
  56. ------------------------------------------------Client Variables
  57.  
  58. -------------------------------------- NULL Variables
  59.  
  60.  
  61. local Player = game.Players.LocalPlayer;
  62. local mouse = Player:GetMouse();
  63. local gui = script.Parent;
  64. local cam = Workspace.CurrentCamera;
  65. local char = Player.Character
  66. wait(1)
  67. local human,torso,head = char:WaitForChild("Humanoid"),char:WaitForChild("Torso"),char:WaitForChild("Head");
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78. ----------------------------------------------- String Variables
  79.  
  80.  
  81.  
  82. local pat = "(.-)%s"
  83. local FootStep = 'Terrain_Grass'
  84. local soundbase = {
  85. ['Terrain_Grass'] = 'http://www.roblox.com/asset/?id=17385522',
  86. ['Terrain_Wood'] = 'http://www.roblox.com/asset/?id=12814239',
  87. ['Terrain_Tile'] = 'http://www.roblox.com/asset/?id=25641879',
  88. ['Terrain_Wind'] = '',
  89. ['Terrain_Carpet'] = 'http://www.roblox.com/asset/?id=16720281',
  90. ['Terrain_Metal'] = 'http://www.roblox.com/asset/?id=11450310'
  91. }
  92. local pitchbase = {
  93. ['Terrain_Wood'] = {.4,.45,.5,.55,.6,.65},
  94. ['Terrain_Grass'] = {2,2.25,2.5,2.55,2.6,2.65},
  95. ['Terrain_Tile'] = {0.45,0.5,0.55,0.6,0.66,0.7,0.75},
  96. ['Terrain_Carpet'] = {2,2.1,2.2,2.3,2.4,2.5},
  97. ['Terrain_Metal'] = {2,2.01,2.02,2.03,2.04,2.05}
  98. }
  99. local volumebase = {
  100. ['Terrain_Grass'] = .2,
  101. ['Terrain_Wood'] = .1,
  102. ['Terrain_Tile'] = .05,
  103. ['Terrain_Wind'] = .3,
  104. ['Terrain_Carpet'] = .3,
  105. ['Terrain_Metal'] = 1
  106. }
  107. local volumebaseorig = volumebase;
  108. local volumebasesprint =
  109. {
  110. ['Terrain_Grass'] = .5,
  111. ['Terrain_Wood'] = .3,
  112. ['Terrain_Tile'] = .5,
  113. ['Terrain_Wind'] = .5,
  114. ['Terrain_Carpet'] = .5,
  115. ['Terrain_Metal'] = 1
  116. }
  117. local freqnote = [=[
  118.  
  119. Cricket frequency:
  120. 18.5
  121.    
  122. DarkForest frequency:
  123.  
  124. 51.5
  125.  
  126.  
  127. ogre frequency:
  128.  
  129. 8
  130.  
  131.  
  132. choir frequency:
  133.  
  134. 90.5
  135.  
  136. tuba frequency:
  137.  
  138.  
  139. 20.5
  140.  
  141.  
  142.  
  143. flute frequency:
  144.  
  145.  
  146. 16.5
  147.  
  148. ]=]
  149. local FrequencyBase = {
  150. ["cricket"] ={[0.3] = 18,[0.35] = 15.5,[0.4] = 14.5};  
  151. }
  152. local SoundDatabase = {
  153. ["cricket"] = 'http://www.roblox.com/Asset?ID=86300687        .3-.35-.4-.45-.5-.55-.',
  154. ["darkforest"] = 'http://www.roblox.com/Asset?ID=86300687     .1-.',
  155. ["ogre"] = 'rbxasset://sounds/uuhhh.wav                       .15-.2-.25-.3-.',
  156. ["choir"] = 'http://www.roblox.com/asset/?id=1372258          .7-.-.75-.8',
  157. ["fightmusic"] = 'http://www.roblox.com/asset?id=58479849    .7-.',
  158. ["thememusic"] = 'http://www.roblox.com/asset/?id=5985787    1-.',
  159. ["tuba"] = 'http://www.roblox.com/asset/?id=47697530         1-.',
  160. ["flute"] = 'http://www.roblox.com/asset/?id=52155103        .6-.65-.7-.75-.8-.',
  161. ["crowd1"] = 'http://www.roblox.com/asset/?id=15632562       .65-.7-.75-.8-.',
  162. ["crowd2"] = 'http://www.roblox.com/asset/?id=15632569       .65-.7-.75-.8-.',
  163. ["crowd3"] = 'http://www.roblox.com/asset/?id=15632575       .65-.7-.75-.8-.',
  164. ["crowd4"] = 'http://www.roblox.com/asset/?id=15632575       .65-.7-.75-.8-.',
  165. ["crow"] = 'http://www.roblox.com/asset/?id=64488575         .9-.95-1-.'
  166. }
  167. local ids = {
  168. 'http://www.roblox.com/Asset?ID=86300687',
  169. 'http://www.roblox.com/Asset?ID=86300687',
  170. 'rbxasset://sounds/uuhhh.wav',
  171. 'http://www.roblox.com/asset/?id=1372258',
  172. 'http://www.roblox.com/asset?id=58479849',
  173. 'http://www.roblox.com/asset/?id=5985787',
  174. 'http://www.roblox.com/asset/?id=47697530',
  175. 'http://www.roblox.com/asset/?id=52155103',
  176. 'http://www.roblox.com/asset/?id=15632562',
  177. 'http://www.roblox.com/asset/?id=15632569',
  178. 'http://www.roblox.com/asset/?id=15632575',
  179. 'http://www.roblox.com/asset/?id=15632575',
  180. 'http://www.roblox.com/asset/?id=17385522',
  181. 'http://www.roblox.com/asset/?id=12814239',
  182. 'http://www.roblox.com/asset/?id=25641879',
  183. 'http://www.roblox.com/asset/?id=16720281',
  184. 'http://www.roblox.com/asset/?id=11450310'
  185. }
  186.  
  187.  
  188. ------------------------------------------------ NULL Variables
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195. local Scanner = nil;
  196. local touching = nil;
  197. local PreparedSound = nil;
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212. ------------------------------------------------ Integer variables
  213.  
  214.  
  215.  
  216.  
  217.  
  218. local pitch = .7;
  219. local vol = .3;
  220. local O_S_R = .45;
  221. local I_S_R = .25;
  222. local O_W_S = '7';
  223. local I_W_S = '18';
  224. local Speed_Render = O_S_R;
  225. local laststep = 0;
  226. local maxchance = 5;
  227.  
  228.  
  229.  
  230. ----------------------------------------------- Instancing variables
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241. local Sound = Instance_new('Sound',gui);
  242. Sound.Volume = .3;
  243. Sound.Name = Player.Name..' Sound Animation';
  244. local Last_Part = Workspace:WaitForChild("Terrain_Grass");
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260. --------------------------------------------------MAIN FUNCTIONS
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268. -- UI related functions
  269.  
  270.  
  271.  
  272.  
  273.  
  274.  
  275. local scrgui = script:WaitForChild("ScreenGui");
  276. local cover = scrgui:WaitForChild("Cover");
  277. function StartLoadingAnimation()
  278.     cover:TweenPosition(OriginalTween,'Out','Linear',.5,true,nil);
  279.     Spawn(function()
  280.         LoadingStop = true
  281.         local function SubtractColor3(a, b)
  282.             local R = a.r + b.r
  283.             local G = a.g + b.g
  284.             local B = a.b + b.b
  285.             return Color3_new(R, G, B)
  286.         end
  287.         local function MultiplyColor3(Num, Color)
  288.             local R = Color.r * Num
  289.             local G = Color.g * Num
  290.             local B = Color.b * Num
  291.             return Color3_new(R, G, B)
  292.         end
  293.         local function InverseColor3(Color)  
  294.             return Color3_new(1-Color.r, 1-Color.g, 1-Color.b)
  295.         end
  296.         local function StartRing(Color, Radius, StartPos, Size)  
  297.             Color = InverseColor3(Color)
  298.             Spawn(function()
  299.                 while LoadingStop do
  300.                     local EndNum = StartPos+360
  301.                     local IncreaseVal = 8
  302.                     for i=StartPos, EndNum, IncreaseVal do
  303.                         if LoadingStop then
  304.                             local XPos = ((math_cos(math_rad(i))) * Radius)
  305.                             local YPos = ((math_sin(math_rad(i))) * Radius)
  306.                             local f = Instance_new("Frame", scrgui.LoadingFrame)
  307.                             f.Position = UDim2_new(0.5, XPos, 0.5, YPos)
  308.                             f.Name = "Pixel"
  309.                             f.Size = UDim2_new(0,Size,0,Size)
  310.                             f.BackgroundTransparency = 0
  311.                             f.BorderSizePixel = 0
  312.                             f.ZIndex = 8
  313.                             f.BackgroundColor3 = Color3_new(1,1,1)
  314.                             f:TweenSize(UDim2_new(0,0,0,0), "Out", "Sine",1.5, true)
  315.                             Spawn(function()
  316.                                 for i=0, 1, 0.025 do
  317.                                     i = math_sin(math_rad(90)*i)
  318.                                     if LoadingStop then
  319.                                         f.Transparency = i
  320.                                         f.BackgroundColor3 = SubtractColor3(Color3_new(1,1,1), MultiplyColor3(1-i, Color))
  321.                                     end
  322.                                     wait()
  323.                                 end
  324.                                 wait()
  325.                                 f:Destroy()
  326.                             end)
  327.                             wait()
  328.                         end
  329.                     end
  330.                 end
  331.             end)
  332.         end
  333.            
  334.         local function TransistLoadingFrame(Start, End, reverse, Color)
  335.             Color = InverseColor3(Color)
  336.             if not reverse then
  337.                 for i=Start, End, 0.01 do
  338.                     if LoadingStop then
  339.                         i = math_sin(math_rad(90)*i)
  340.                         scrgui.LoadingFrame.Loading.TextColor3 = SubtractColor3(Color3_new(1,1,1), MultiplyColor3(1-i, Color))
  341.                         wait()
  342.                     end
  343.                 end
  344.                 else
  345.                 for i=End, Start, -0.01 do
  346.                     if LoadingStop then
  347.                         i = math_sin(math_rad(90)*i)
  348.                         scrgui.LoadingFrame.Loading.TextColor3 = SubtractColor3(Color3_new(1,1,1), MultiplyColor3(1-i, Color))
  349.                         wait()
  350.                     end
  351.                 end
  352.             end
  353.         end
  354.         StartRing(Color3_new(0.0666667, 0.0666667, 0.0666667), 90, 360,12)
  355.         StartRing(Color3_new(0.0666667, 0.0666667, 0.0666667), 110, 120,12)
  356.         StartRing(Color3_new(0.0666667, 0.0666667, 0.0666667), 100, 240,12)
  357.         scrgui.LoadingFrame.Loading.TextTransparency = 1
  358.         scrgui.LoadingFrame.Loading.TextColor3 = Color3_new(1,1,1)
  359.         scrgui.LoadingFrame.Visible = true
  360.         for i=1, 0, -0.01 do
  361.             i = math_sin(math_rad(90)*i)
  362.             scrgui.LoadingFrame.Loading.TextTransparency = i
  363.             wait()
  364.         end
  365.         Spawn(function()
  366.             while LoadingStop do
  367.                 TransistLoadingFrame(0, 0.7, false, Color3_new(1,0,0))
  368.                 TransistLoadingFrame(0, 0.7, true, Color3_new(1,0,0))
  369.                 wait(1)
  370.                 TransistLoadingFrame(0, 0.7, false, Color3_new(0,1,0))
  371.                 TransistLoadingFrame(0, 0.7, true, Color3_new(0,1,0))
  372.                 wait(1)
  373.                 TransistLoadingFrame(0, 0.7, false, Color3_new(0,0,1))
  374.                 TransistLoadingFrame(0, 0.7, true, Color3_new(0,0,1))
  375.                 wait(1)
  376.             end
  377.         end)
  378.         repeat wait() until not LoadingStop
  379.         for i=0, 1, 0.03 do
  380.             i = math_sin(math_rad(90)*i)
  381.             scrgui.LoadingFrame.Loading.TextTransparency = i
  382.             wait()
  383.         end
  384.             cover:TweenPosition(NegativeTween,'Out','Elastic',.5,true,nil);
  385.     end)
  386. end
  387. StartLoadingAnimation()
  388. for i = 1,#ids do wait(.1)
  389.     game:GetService("ContentProvider"):Preload(ids[i]);
  390. end
  391. repeat wait(1) until Workspace:FindFirstChild(Player.Name);
  392. LoadingStop = false;
  393. human.WalkSpeed = O_W_S;
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.  
  404.  
  405. -- World Space UI
  406.  
  407.  
  408.  
  409.  
  410.  
  411.  
  412.  
  413. function PlayDialog(event,perpetrator)
  414.     human.WalkSpeed = 0;
  415.     Player.CameraMode = 'LockFirstPerson';
  416.     wait(.5)
  417.     LerpCamera(head,perpetrator.Head);
  418. end
  419.  
  420.  
  421.  
  422.  
  423.  
  424. --- Character related functions
  425.  
  426.  
  427.  
  428.  
  429.  
  430.  
  431.  
  432. function WaitForDistance(part,radius)
  433.     repeat wait(0.1) until (torso.Position-part.Position).Magnitude <= radius;
  434. end
  435. local DynamicFunctions = {
  436. ["Sound"] = function(partt)  
  437.     local running = true;
  438.     local pos = torso.Position;
  439.     local quitest,name,closest = 0,partt.Name,10000000
  440.     local freq = 0;
  441.     local a, b, c, d, e, f, g = name:match("^(.-)|(.-)|(.-)|(.-)|(.-)|(.-)|(.-)|?$");
  442.     local loudest,Radius,frequency = tonumber(e),tonumber(f),tonumber(g)
  443.     local s = Instance_new("Sound",gui);    s.Name = d;
  444.     local id = SoundDatabase[d:lower()]:lower()
  445.     local pitch_data = {};
  446.     local remainder = id:gsub(pat,"");
  447.     for w in remainder:gmatch("(%.?%d+)-") do
  448.         table_insert(pitch_data,tonumber(w));
  449.     end
  450.     local function setfrequency()
  451.         local randompitch = pitch_data[math_random(1,#pitch_data)]
  452.         local delimiter = math_min(unpack(pitch_data));
  453.         local increase = 0;
  454.         for index,value in pairs(pitch_data) do
  455.             increase = index > 1 and increase + .5 or 0;
  456.             if value == randompitch then
  457.                 return frequency+increase;  
  458.             end
  459.         end
  460.     end
  461.     s.SoundId = id:match(pat);
  462.     s.Volume = 0;
  463.     s.Pitch = pitch_data[math_random(1,#pitch_data)];
  464.     freq = setfrequency();
  465.     wait(.5)
  466.     s:Play();
  467.     local clopart = nil;
  468.     local part, hitpoint =
  469.     Workspace:FindPartOnRay(Ray_new(pos, CFrame_new(pos, partt.Position).lookVector * (pos - partt.Position).magnitude),char)
  470.     coroutine_resume(coroutine_create(function()
  471.         while(running) do wait(freq)
  472.             print("Freq for "..s.Name.." is "..freq)
  473.             s.Pitch = pitch_data[math_random(1,#pitch_data)];
  474.             freq = setfrequency();
  475.             s:Play();
  476.         end
  477.     end))        
  478.     while(running) do wait(0)    
  479.         local pos = torso.Position            
  480.         local dist = (pos - partt.Position).magnitude
  481.         if dist < closest then
  482.             clopart = partt
  483.             closest = dist
  484.         end
  485.         if partt then
  486.             local percentile = (dist/Radius) - .3
  487.             if Radius - dist < -20 then
  488.                 s:Stop()
  489.                 wait()
  490.                 s:Destroy()
  491.                 running = false;
  492.                 else
  493.                 s.Volume = 1-percentile  >= loudest and s.Volume or 1-percentile;
  494.             end
  495.         end
  496.     end
  497. end,
  498. ["RandomEvent"] = function(partt)
  499.     print("RandomEvent")
  500.     local name = partt.Name;               --part contains randomevent event perpetrator radius chance
  501.     local a, b, c, d, e, f, g = name:match("^(.-)|(.-)|(.-)|(.-)|(.-)|(.-)|(.-)|?$");
  502.     local chance,radius = tonumber(g),tonumber(f);
  503.     local perpetrator = Workspace:findFirstChild(e);
  504.     if (math_random(chance,maxchance)) ~= chance then return end
  505.     WaitForDistance(partt,radius);
  506.     PlayDialog(d,perpetrator);
  507. end
  508. }
  509. function WalkSound()
  510.     --if Beat_Adjust and Is_Adjusting == false then coroutine_resume(coroutine_create(Beat_Adjust)) end
  511.     local pitches = pitchbase[FootStep] ~= nil and pitchbase[FootStep] or pitchbase['Terrain_Grass']
  512.     Sound.SoundId,Sound.Volume = soundbase[FootStep],volumebase[FootStep];
  513.     Sound.Pitch = pitches[math_random(1,#pitches)]
  514.     Sound:Play()
  515. end
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533. -- Camera related functions
  534.  
  535.  
  536.  
  537.  
  538.  
  539.  
  540.  
  541.  
  542.  
  543.  
  544.  
  545.  
  546.  
  547.  
  548.  
  549.  
  550. function LerpCamera(Part1, Part2)
  551.     Chatting = true
  552.     cam.CameraType="Scriptable"
  553.     local camPart=Instance.new("Part", game.Workspace)
  554.     camPart.Name, camPart.Anchored, camPart.Transparency,camPart.CanCollide="StartPart", true, 1,false
  555.     camPart.CFrame= CFrame_new(Part1.Position + (Part1.CFrame.lookVector * 2))
  556.     local dist=(camPart.Position-Part2.Position).magnitude
  557.     for i=0.5, dist, 0.5 do
  558.         local pos=camPart.Position:Lerp(Part2.Position, i/dist)
  559.         cam.CoordinateFrame=CFrame_new(camPart.Position, pos)
  560.         Wait(0.03)
  561.     end
  562.     game.Debris:AddItem(camPart,1)
  563. end
  564. function TweenCam(Status)
  565.     local Add_Tab = {
  566.     CFrame_new(0.02,.02,0),
  567.     CFrame_new(0,.02,0.02)
  568.     }
  569.     local Minus_Tab = {
  570.     CFrame_new(-.02,-.02,0),
  571.     CFrame_new(0,-.02,-.02)
  572.     }
  573.     for i = 1, 3 do wait(0)
  574.         CF = Status == 'Minus' and cam.CoordinateFrame * Minus_Tab[math_random(1,2)] or
  575.         cam.CoordinateFrame * Add_Tab[math_random(1,2)]
  576.         cam.CoordinateFrame = CF;
  577.     end
  578. end
  579.  
  580.  
  581.  
  582.  
  583.  
  584. --------------------------------------------------------- EVENT HANDLING
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.  
  592.  
  593.  
  594.  
  595. local StepListener = game:GetService("RunService").Stepped:connect(function()
  596.     local pos = torso.Position
  597.     local offvel = torso.Velocity*1/15
  598.     local hit,ray = workspace:FindPartOnRay(Ray_new(pos+offvel,Vector3_new(0,-3.1,0)),char)
  599.     if hit and soundbase[hit.Name] then
  600.         FootStep = hit.Name
  601.     end
  602.     local moving = math_abs(torso["Right Shoulder"].CurrentAngle-torso["Right Shoulder"].DesiredAngle) > .1
  603.     if tick()-laststep > Speed_Render and torso.Velocity.magnitude > 5 and hit and moving then
  604.         laststep = tick()
  605.         WalkSound()
  606.     end
  607. end)
  608. local KeyDownListener = mouse.KeyDown:connect(function(key)
  609.     local time = 100;
  610.     if key == "\48" and frozen == false and torso.Velocity.magnitude > 5 then
  611.         IsSprinting = true;
  612.         Speed_Render,volumebase = I_S_R,volumebasesprint;
  613.         human.WalkSpeed = I_W_S;
  614.         repeat wait(.1) time = time - 1;
  615.             TweenCam("Minus")
  616.             wait(.1)
  617.             TweenCam("Add")
  618.         until IsSprinting == false or time <=0
  619.         Speed_Render,volumebase = O_S_R,volumebaseorig;
  620.         human.WalkSpeed = O_W_S
  621.     end
  622. end)
  623. local KeyUpListener = mouse.KeyUp:connect(function(key)
  624.     if  key == "\48"  and frozen == false then
  625.         IsSprinting = false
  626.     end
  627. end)
  628. local TouchListener = char.Head.Touched:connect(function(hit)
  629.     if touching or frozen == true then return end
  630.     touching = true
  631.     local passed = hit.Name;
  632.         if(passed:match("%w+|%w+|(%w+)|%w+|%w+|%w+|%w+|?")) then
  633.             DynamicFunctions[passed:match("%w+|%w+|(%w+)|%w+|%w+|%w+|%w+|?")](hit)
  634.         end
  635.     wait(.1)
  636.     touching = false  
  637. end)
  638. local changing = false;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement