Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.05 KB | None | 0 0
  1. --[[
  2. This is a rewritten version of the original GodVR script that I wrote
  3. Everything is subject to change
  4. The0neThe0nly
  5. TODO:
  6. + Add two "hitboxes"
  7. + Find a better way to scale hats/head mesh
  8. - Add more tools
  9. + CFrame touched event fix
  10. + Chat bubbles
  11. Tool Entry Format:
  12. {{name, BrickColor, init func, exit func, contact func, trigger func}, {name, BrickColor, property func, contact func, trigger func}, ...}
  13. - Each function's first argument must be a table for the hand being used
  14. - Contact function takes part object as second argument
  15. - Trigger function takes input object as second argument
  16. Arm Format:
  17. {{handObj, handSurface, handText, handLight}, toolState, Enum.UserCFrame.Hand, triggered}
  18. --]]
  19.  
  20. local function empty() end
  21. local camera = workspace.CurrentCamera
  22. local scale = 1
  23. local left = {{nil, nil, nil, nil}, 1, Enum.UserCFrame.LeftHand, false}
  24. local right = {{nil, nil, nil, nil}, 1, Enum.UserCFrame.RightHand, false}
  25. local headMarker, hats, basecframe
  26.  
  27. local tools = {{"Default", BrickColor.new("White"), empty, empty, empty, empty},
  28. {"Collide", BrickColor.new("White"), (function(hand) hand[1][1].Transparency = 0 hand[1][1].CanCollide = true end), (function(hand) hand[1][1].Transparency = 0.5 hand[1][1].CanCollide = false end), empty, empty},
  29. {"Grab", BrickColor.new("Really black"), empty, empty, (function(hand, part)
  30. local x = Instance.new("BodyPosition", camera)
  31. x.MaxForce = Vector3.new(100000, 100000, 100000)
  32. while hand[4] and (part.Parent:FindFirstChild("Torso") ~= nil or not part.Anchored) do
  33. wait()
  34. if part.Parent:FindFirstChild("Torso") ~= nil then
  35. x.Parent = part.Parent.Torso
  36. x.Position = hand[1][1].CFrame.p
  37. elseif not part.Anchored then
  38. x.Parent = part
  39. x.Position = hand[1][1].CFrame.p
  40. end
  41. end
  42. x:Destroy()
  43. end), empty},
  44. {"Kill", BrickColor.new("Really red"), empty, empty, (function(hand, part)
  45. if part.Parent:FindFirstChild("Humanoid") ~= nil then
  46. if part.Parent:FindFirstChild("ForceField") ~= nil then
  47. part.Parent["ForceField"]:Destroy()
  48. end
  49. part.Parent:BreakJoints()
  50. end
  51. end), empty},
  52. {"Vicinity Explode", BrickColor.new("Deep orange"), empty, empty, (function(hand, part)
  53. if part.Parent:FindFirstChild("Torso") ~= nil or not part.Anchored then
  54. local x = Instance.new("Explosion", workspace)
  55. if part.Parent:FindFirstChild("Torso") ~= nil then
  56. x.Position = part.Parent.Torso.Position
  57. elseif not part.Anchored then
  58. x.Position = part.Position
  59. end
  60. end
  61. end), empty},
  62. {"Explode", BrickColor.new("Deep orange"), (function(hand) local x = Instance.new("Fire", hand[1][1]) x.Heat = 3 x.Size = scale end), (function(hand) hand[1][1].Fire:Destroy() end), empty, (function(hand, input)
  63. while input.Position.z == 1 do
  64. wait()
  65. local x = Instance.new("Explosion", workspace)
  66. x.Position = Vector3.new(hand[1][1].CFrame.x-(0.4*scale), hand[1][1].CFrame.y, hand[1][1].CFrame.z)
  67. end
  68. end)},
  69. {"Trip", BrickColor.new("New Yeller"), empty, empty, (function(hand, part)
  70. if part.Parent:FindFirstChild("Humanoid") ~= nil and not part.Parent.Humanoid.PlatformStand then
  71. part.Parent.Humanoid.PlatformStand = true -- this is not a good way to trip people
  72. wait(1)
  73. part.Parent.Humanoid.PlatformStand = false
  74. end
  75. end), empty},
  76. {"Scale", BrickColor.new("Parsley green"), empty, empty, empty, (function(hand, input)
  77. local newscale = 0
  78. local ypos = hand[1][1].CFrame.y
  79. while input.Position.z == 1 do
  80. wait()
  81. newscale = ((hand[1][1].CFrame.y-ypos)/scale)*10
  82. hand[1][3].Text = "Scale: "..tostring(scale)
  83. if newscale >= 0 then
  84. if scale < 1 then
  85. newscale = math.ceil(hand[1][1].CFrame.y-ypos)/10
  86. if (newscale+scale) > 1 then
  87. newscale = 1 - scale
  88. end
  89. else
  90. newscale = math.ceil(newscale)
  91. end
  92. hand[1][3].Text = hand[1][3].Text.."\n+"..tostring(newscale)
  93. else
  94. if scale <= 1 then
  95. newscale = math.floor(hand[1][1].CFrame.y-ypos)/10
  96. else
  97. newscale = math.floor(newscale)
  98. end
  99. hand[1][3].Text = hand[1][3].Text.."\n-"..tostring(math.abs(newscale))
  100. end
  101. end
  102. scale = scale + newscale
  103. if scale < 0.3 then
  104. scale = 0.3
  105. end
  106. right[1][1].Size = Vector3.new(0.4, 0.4, 1)*scale
  107. left[1][1].Size = Vector3.new(0.4, 0.4, 1)*scale
  108. headMarker.Mesh.Scale = Vector3.new(1, 1, 1)*scale
  109. for i=1,#hats do
  110. wait()
  111. hats[i].Mesh.Scale = Vector3.new(1, 1, 1)*scale
  112. end
  113. camera.CoordinateFrame = CFrame.new(camera:GetRenderCFrame().x, camera:GetRenderCFrame().y+(newscale), camera:GetRenderCFrame().z)
  114. camera.HeadScale = scale
  115. hand[1][3].Text = "Scale: "..tostring(scale)
  116. end)}
  117. }
  118.  
  119. local InputService = game:GetService("UserInputService")
  120. local RunService = game:GetService("RunService")
  121. local character = workspace:WaitForChild(game.Players.LocalPlayer.Name)
  122. local VRService = game:GetService("VRService")
  123.  
  124. local function switch(hand) -- no need for input arg
  125. tools[hand[2]][4](hand) -- exit
  126. if hand[2] ~= #tools then
  127. hand[2] = hand[2] + 1
  128. else
  129. hand[2] = 1
  130. end
  131. hand[1][3].Text = tools[hand[2]][1]
  132. hand[1][1].BrickColor = tools[hand[2]][2]
  133. hand[1][4].Color = tools[hand[2]][2].Color
  134. tools[hand[2]][3](hand) -- init
  135. end
  136.  
  137. local function gripped(hand, input)
  138. while input.Position.z == 1 do
  139. wait()
  140. local controllerCFrame = camera.CoordinateFrame*VRService:GetUserCFrame(hand[3])
  141. local positionChange = (controllerCFrame * CFrame.new(0*scale, 0*scale, (-0.1*scale)-1)).p - controllerCFrame.p
  142. --camera.CoordinateFrame = CFrame.new(positionChange.x, 0, positionChange.z) * camera.CoordinateFrame
  143. camera.CoordinateFrame = CFrame.new(positionChange.x, positionChange.y, positionChange.z) * camera.CoordinateFrame
  144. end
  145. end
  146.  
  147. local function triggered(hand, input) -- lol
  148. tools[hand[2]][6](hand, input)
  149. while input.Position.z == 1 do
  150. wait()
  151. hand[4] = true
  152. end
  153. hand[4] = false
  154. end
  155.  
  156. wait(1) -- hack
  157. if VRService.VREnabled and not workspace.FilteringEnabled then
  158.  
  159. VRService:SetTouchpadMode(Enum.VRTouchpad.Left, Enum.VRTouchpadMode.Touch) -- WIP hotfix
  160. VRService:SetTouchpadMode(Enum.VRTouchpad.Right, Enum.VRTouchpadMode.Touch)
  161.  
  162. pcall(function() game.Players.LocalPlayer.TeamColor = game.Teams.Gods.TeamColor end) -- if in my test game
  163. camera.CameraType = Enum.CameraType.Scriptable
  164. basecframe = character.Head.CFrame
  165. camera.CoordinateFrame = CFrame.new(basecframe.x, basecframe.y+(scale-1), basecframe.z) -- this is a terrible way to do this
  166. camera.HeadScale = scale
  167. InputService.MouseIconEnabled = false
  168. --game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Chat, false)
  169. game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Health, false)
  170. game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
  171.  
  172. local colors = character:WaitForChild("Body Colors"):clone()
  173. hats = {}
  174. for i,v in pairs(character:GetChildren()) do
  175. wait()
  176. if v:IsA("Accoutrement") then
  177. table.insert(hats, v.Handle:clone())
  178. end
  179. end
  180. headMarker = character.Head:clone()
  181. for i,v in pairs(headMarker:GetChildren()) do
  182. wait()
  183. if v:IsA("Sound") or v:IsA("Weld") then
  184. v:Destroy()
  185. end
  186. end
  187. character:ClearAllChildren()
  188. colors.Parent = character
  189. headMarker.Anchored = true
  190. headMarker.LocalTransparencyModifier = 1
  191. headMarker.Mesh.Scale = Vector3.new(1, 1, 1) * scale
  192. headMarker.Parent = character
  193. for i=1,#hats do
  194. wait()
  195. hats[i].Anchored = true
  196. hats[i].LocalTransparencyModifier = 1
  197. hats[i].Mesh.Scale = hats[i].Mesh.Scale * scale
  198. hats[i].Parent = headMarker
  199. end
  200. headMarker.CanCollide = false
  201. local hand1Marker = Instance.new("Part", character)
  202. hand1Marker.Name = "RightHand"
  203. hand1Marker.BrickColor = tools[1][2]
  204. hand1Marker.Transparency = 0.5
  205. hand1Marker.Anchored = true
  206. hand1Marker.CanCollide = false
  207. hand1Marker.Locked = true
  208. hand1Marker.TopSurface = "Smooth"
  209. hand1Marker.BottomSurface = "Smooth"
  210. hand1Marker.Size = Vector3.new(0.4, 0.4, 1)*scale
  211. right[1][1] = hand1Marker
  212. local hand2Marker = right[1][1]:clone()
  213. hand2Marker.Name = "LeftHand"
  214. hand2Marker.Parent = character
  215. left[1][1] = hand2Marker
  216. local surfaceR = Instance.new("SurfaceGui", camera)
  217. surfaceR.Adornee = right[1][1]
  218. surfaceR.Face = "Top"
  219. right[1][2] = surfaceR
  220. local surfaceL = right[1][2]:clone()
  221. surfaceL.Parent = camera
  222. surfaceL.Adornee = left[1][1]
  223. left[1][2] = surfaceL
  224. local txtR = Instance.new("TextLabel", right[1][2])
  225. txtR.BackgroundTransparency = 1
  226. txtR.Rotation = 180
  227. txtR.Size = UDim2.new(1, 0, 1, 0)
  228. txtR.Font = "ArialBold"
  229. txtR.FontSize = "Size96"
  230. txtR.Text = tools[1][1]
  231. txtR.TextColor3 = Color3.new(1, 1, 1)
  232. txtR.TextStrokeTransparency = 0.5
  233. right[1][3] = txtR
  234. local txtL = right[1][3]:clone()
  235. txtL.Parent = left[1][2]
  236. left[1][3] = txtL
  237. local plR = Instance.new("PointLight", right[1][1])
  238. plR.Brightness = math.huge
  239. plR.Range = scale + 6
  240. plR.Shadows = true
  241. right[1][4] = plR
  242. local plL = right[1][4]:clone()
  243. plL.Parent = left[1][1]
  244. left[1][4] = plL
  245.  
  246. right[1][1].Touched:connect(function(part) tools[right[2]][5](right, part) end)
  247. left[1][1].Touched:connect(function(part) tools[left[2]][5](left, part) end)
  248.  
  249. RunService.Heartbeat:connect(function() -- 60 hz...?
  250. local HeadCFrame = VRService:GetUserCFrame(Enum.UserCFrame.Head)
  251. local RightHandCFrame = VRService:GetUserCFrame(right[3])
  252. local LeftHandCFrame = VRService:GetUserCFrame(left[3])
  253.  
  254. local scaledLeftHandCFrame = CFrame.new(LeftHandCFrame.p*(scale-1))*LeftHandCFrame
  255. local scaledRightHandCFrame = CFrame.new(RightHandCFrame.p*(scale-1))*RightHandCFrame
  256. local mainCFrame1 = camera.CoordinateFrame * scaledRightHandCFrame
  257. local mainCFrame2 = camera.CoordinateFrame * scaledLeftHandCFrame
  258.  
  259. right[1][1].CFrame = mainCFrame1
  260. left[1][1].CFrame = mainCFrame2
  261. headMarker.CFrame = camera:GetRenderCFrame()
  262. for i=1,#hats do
  263. hats[i].CFrame = camera:GetRenderCFrame()
  264. hats[i].CFrame = camera:GetRenderCFrame()
  265. end
  266. end)
  267.  
  268. local function handleInput(input) -- no gameProcessed for now
  269. if input.UserInputState == Enum.UserInputState.Begin then
  270. print(input.KeyCode)
  271. if input.KeyCode == Enum.KeyCode.ButtonR3 then -- Right Touchpad
  272. switch(right)
  273. elseif input.KeyCode == Enum.KeyCode.ButtonL3 then -- Left Touchpad
  274. switch(left)
  275. elseif input.KeyCode == Enum.KeyCode.ButtonR2 then -- Right Trigger
  276. triggered(right, input)
  277. elseif input.KeyCode == Enum.KeyCode.ButtonL2 then -- Left Trigger
  278. triggered(left, input)
  279. elseif input.KeyCode == Enum.KeyCode.ButtonR1 then -- Right Grip
  280. gripped(right, input)
  281. elseif input.KeyCode == Enum.KeyCode.ButtonL1 then -- Left Grip
  282. gripped(left, input)
  283. end
  284. elseif input.UserInputState == Enum.UserInputState.End then
  285. -- nothing for now
  286. elseif input.UserInputState == Enum.UserInputState.Change then
  287. -- nothing for now
  288. end
  289. end
  290.  
  291. InputService.InputBegan:connect(handleInput)
  292. InputService.InputEnded:connect(handleInput)
  293. InputService.InputChanged:connect(handleInput)
  294. elseif not VRService.VREnabled then
  295. error("\nYou don't have a VR headset plugged in or one was not detected\nVRService.VREnabled: "..tostring(VRService.VREnabled))
  296. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement