Advertisement
Guest User

Client Script

a guest
Nov 21st, 2019
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 54.35 KB | None | 0 0
  1.  
  2. --[[
  3. Here is a copy of my weapon client script.
  4.  
  5. This script is in charge of any animations for the weapon, and rendering other characters .
  6.  
  7. I went through and commented out some functions to explain what they do
  8.  
  9. GAME LINK: https://www.roblox.com/games/496469360/Gun-Framework?refPageId=5db09d5f-b7e1-4629-889c-c561f25bd29c
  10. ]]
  11. math.randomseed(tick())
  12. local wfc = game.WaitForChild
  13. local ffc = game.FindFirstChild
  14. local cf = CFrame.new
  15. local fea = CFrame.fromEulerAnglesXYZ
  16. local v3 = Vector3.new
  17. local ffa = CFrame.fromAxisAngle
  18. local ca = CFrame.Angles
  19. local v2 = Vector2.new
  20. local atan = math.atan
  21. local abs = math.abs
  22. local atan2 = math.atan2
  23. local asin = math.asin
  24. local tan = math.tan
  25. local pi = math.pi
  26. local huge = math.huge
  27. local rad = math.rad
  28. local sqrt = math.sqrt
  29. local deg = math.deg
  30. local sin = math.sin
  31. local new = Instance.new
  32. local random = math.random
  33. local cos = math.cos
  34. local acos = math.acos
  35. local function isNaN(v) if tostring(v):find("NAN") or tostring(v):find("INF") then return true end return false end
  36. local sign = function(x) if x > 0 then return 1 elseif x < 0 then return -1 else return 0 end end
  37. local clamp = function(v, l, h) if v > h then return h elseif v < l then return l end return v end
  38. local biasedRandom = function() return random(900, 1100)/1000 end -- I'll do this later
  39. local srandom = function() return (random() - .5) * 2 end
  40. local draw = function(v) local p = Instance.new("Part", game.Workspace) p.Anchored = true p.Size = v3() p.CFrame = cf(v) end
  41. local ease = function(x, y, a) return x + (y - x) * a end
  42. local function sw(x) local s = x % 2 local x = s % 1 if s < 1 then return (x*x*(3 - 2*x) - .5)*2 end return (1 - x*x*(3 - 2*x) - .5)*2 end
  43.  
  44.  
  45. --public class Probability
  46. --{
  47. -- public static float InRangeOfExponentialPDF(float x, float min, float max)
  48. -- {
  49. -- /**
  50. -- * Use a linearly distributed random number (x) to get a
  51. -- * random number in the range of an exponential PDF.
  52. -- *
  53. -- * Parameters:
  54. -- * x - random number from a linearly distributed range in [0,1]
  55. -- * min/max - range of values in pdf
  56. -- */
  57. --
  58. -- float range = max - min;
  59. -- float density = range - (range * Mathf.Exp(-range * x)); // pdf
  60. -- return density + min;
  61. -- }
  62. --}
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75. local gs = function(s) return game:GetService(s.."Service") end
  76. local rs = gs("Run")
  77. local uis = gs("UserInput")
  78.  
  79. local cam = game.Workspace.CurrentCamera
  80. local player = game.Players.LocalPlayer
  81. local modules = wfc(game.ReplicatedStorage, "Modules")
  82. local events = wfc(game.ReplicatedStorage, "Events")
  83. local particles = wfc(game.ReplicatedStorage, "Particles")
  84. local spring = require(wfc(modules, "Spring"))
  85. local util = require(wfc(modules, "Util"))
  86.  
  87. local Ragdoll = require(script.Ragdoll)
  88. local Indicator = require(script.Indicator)
  89. local BulletHole = require(script.BulletHole)
  90.  
  91. local spring = {}
  92. local animate = {}
  93. local physics = {}
  94. local vector = {}
  95. local cframe = {}
  96. local network = {}
  97. local weapon = {}
  98. local camera = {}
  99. local ui = {}
  100. local input = {}
  101. local character = {}
  102. local robo = {}
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122. -- Custom tick
  123. -- can control time ;D
  124. local tick = {
  125. tick = tick;
  126. last = 0;
  127. lastReal = tick();
  128. speed = 1;
  129. }
  130.  
  131.  
  132. setmetatable(tick, {
  133. __call = function()
  134. return tick:Get()
  135. end
  136. })
  137.  
  138.  
  139. function tick:Get()
  140. local t = self.tick()
  141. local time = self.speed * (t - self.lastReal) + self.last
  142. self.last = time
  143. self.lastReal = t
  144.  
  145. return time
  146. end
  147.  
  148.  
  149. function tick:SetSpeed(speed)
  150. tick.speed = speed
  151. tick:Get()
  152. end
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176. do -- Spring Scope
  177. function spring.new(start, d, s)
  178. start = start or 0
  179. local t0 = tick()
  180. local p0 = start
  181. local v0 = 0 * start
  182. local t = start
  183. local d = d or 1
  184. local s = s or 1
  185.  
  186.  
  187. local function update(tick)
  188. local x = tick - t0
  189. local c0 = p0 - t
  190. if s == 0 then
  191. return p0, 0
  192. elseif d < 1 then
  193. local c = (1 - d*d)^.5
  194. local c1 = (v0/s + d*c0)/c
  195. local co = cos(c * s*x)
  196. local si = sin(c * s*x)
  197. local e = 2.718^(d*s*x)
  198. return t + (c0*co + c1*si)/e,
  199. s*((c*c1 - d*c0)*co - (c*c0 + d*c1)*si)/e
  200. else
  201. local c1 = v0/s + c0
  202. local e = 2.718^(s*x)
  203. return t + (c0 + c1*s*x)/e,
  204. s * (c1 - c0 - c1*s*x)/e
  205. end
  206. end
  207.  
  208.  
  209. return setmetatable({
  210. accelerate = function(_, a)
  211. local time = tick()
  212. local p, v = update(time)
  213. p0 = p
  214. v0 = v + a
  215. t0 = time
  216. end;
  217.  
  218. }, {
  219. __newindex = function(_, index, value)
  220. local time = tick()
  221. if index == "p" then
  222. local p, v = update(time)
  223. p0, v0 = value, v
  224. elseif index == "v" then
  225. local p, v = update(time)
  226. p0, v0 = p, value
  227. elseif index == "a" then
  228. local p, v = update(time)
  229. p0, v0 = p, v + value
  230. elseif index == "t" then
  231. p0, v0 = update(time)
  232. t = value
  233. elseif index == "d" then
  234. p0, v0 = update(time)
  235. d = value < 0 and 0 or value < 1 and value or 1
  236. elseif index == "s" then
  237. p0, v0 = update(time)
  238. s = value < 0 and 0 or value
  239. end
  240.  
  241. t0 = time
  242. end;
  243.  
  244. __index = function(_, index)
  245. if index == "p" then -- Position
  246. local p, v = update(tick())
  247. return p
  248. elseif index == "v" then -- Velocity
  249. local p, v = update(tick())
  250. return v
  251. elseif index == "a" then -- Acceleration
  252. local x = tick() - t0
  253. local c0 = p0 - t
  254. if s == 0 then
  255. return 0
  256. elseif d < 1 then
  257. local c =(1-d*d)^0.5
  258. local c1 =(v0/s+d*c0)/c
  259. return s * s *((d*d*c0 - 2*c*d*c1 - c*c*c0)*cos(c*s*x)
  260. +(d*d*c1 + 2*c*d*c0 - c*c*c1)*sin(c*s*x))
  261. /2.718^(d*s*x)
  262. else
  263. local c1 =v0/s + c0
  264. return s*s*(c0 - 2*c1 + c1*s*x)
  265. /2.718^(s*x)
  266. end
  267. elseif index == "t" then -- Target
  268. return t
  269. elseif index == "d" then -- Damp
  270. return d
  271. elseif index == "s" then -- Speed
  272. return s
  273. elseif index == "m" then -- Magnitude
  274. local p, v = update(tick())
  275. return p.magnitude
  276. end
  277. end;
  278. })
  279. end
  280. end
  281.  
  282.  
  283.  
  284.  
  285.  
  286. --
  287. local veloSpring = spring.new(v2(), .5, 13)
  288. local bounceSpring = spring.new(0, .4, 18)
  289. local aimSpring = spring.new(1, 1, 15)
  290. local magnitudeSpring = spring.new(0, 1, 12)
  291. --
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315. do -- Animation Scope
  316. setmetatable(animate, {
  317. __call = function(...)
  318. return animate.loadAnim(...)
  319. end;
  320. })
  321.  
  322. animate.running = {}
  323. animate.tweens = {
  324. linear = function(x) return x end;
  325. inQuad = function(x) return x*x end;
  326. inCubic = function(x) return x*x*x end;
  327. inQuart = function(x) return x*x*x*x end;
  328. inQuint = function(x) return x*x*x*x*x end;
  329. inSextic = function(x) return x*x*x*x*x*x end;
  330. inSeptic = function(x) return x*x*x*x*x*x*x end;
  331. inOctic = function(x) return x*x*x*x*x*x*x*x end;
  332.  
  333. outQuad = function(x) local m = x-1 return 1 - m*m end;
  334. outCubic = function(x) local m = x-1 return 1 + m*m*m end;
  335. outQuart = function(x) local m = x-1 return 1 - m*m*m*m end;
  336. outQuint = function(x) local m = x-1 return 1 + m*m*m*m*m end;
  337. outSextic = function(x) local m = x-1 return 1 - m*m*m*m*m*m end;
  338. outSeptic = function(x) local m = x-1 return 1 + m*m*m*m*m*m*m end;
  339. outOctic = function(x) local m = x-1 return 1 - m*m*m*m*m*m*m*m end;
  340.  
  341. inOutQuad = function(x) local m = x-1 local t = x*2 if t < 1 then return x*t else return 1 - m*m * 2 end end;
  342. inOutCubic = function(x) local m = x-1 local t = x*2 if t < 1 then return x*t*t else return 1 + m*m*m * 4 end end;
  343. inOutQuart = function(x) local m = x-1 local t = x*2 if t < 1 then return x*t*t*t else return 1 - m*m*m*m * 8 end end;
  344. inOutQuint = function(x) local m = x-1 local t = x*2 if t < 1 then return x*t*t*t*t else return 1 + m*m*m*m*m * 16 end end;
  345. inOutSextic = function(x) local m = x-1 local t = x*2 if t < 1 then return x*t*t*t*t*t else return 1 - m*m*m*m*m*m * 3 end end;
  346. inOutSeptic = function(x) local m = x-1 local t = x*2 if t < 1 then return x*t*t*t*t*t*t else return 1 + m*m*m*m*m*m*m * 64 end end;
  347. inOutOctic = function(x) local m = x-1 local t = x*2 if t < 1 then return x*t*t*t*t*t*t*t else return 1 - m*m*m*m*m*m*m*m * 128 end end;
  348.  
  349. smooth = function(x) return x*x*(3 - 2*x) end;
  350. smoother = function(x) x = x*x*(3 - 2*x) return x*x*(3 - 2*x) end;
  351. spring = function(x) return 1 + (-2.72^(-6.9*x) * cos(2*pi*x*-3.2)) end;
  352. softSpring = function(x) return 1 + (-2.72^(-7.5*x) * cos(2*pi*x*-1.6)) end;
  353.  
  354. inBack = function(x) local k = 1.70158 return x*x*(x*(k+1) - k) end;
  355. inOutBack = function(x) local m = x-1 local t = x*2 local k = 1.70158 * 1.525 if(x < 0.5) then return x*t*(t*(k+1) - k) else return 1 + 2*m*m*(2*m*(k+1) + k) end end;
  356. outBack = function(x) local m = x-1 local k = 1.70158 return 1 + m*m*(m*(k+1) + k) end;
  357. inCirc = function(x) return 1 - sqrt(1 - x*x) end;
  358. inOutCirc = function(x) local m = x-1 local t = x*2 if(t < 1) then return (1 - sqrt(1 - t*t))*0.5 else return (sqrt( 1 - 4*m*m) + 1) * 0.5 end end;
  359. outCirc = function(x) local m = x-1 return sqrt( 1 - m*m) end;
  360.  
  361. outBounce = function(x)
  362. local r = 1 / 2.75
  363. local k1 = 1 * r
  364. local k2 = 2 * r
  365. local k3 = 1.5 * r
  366. local k4 = 2.5 * r
  367. local k5 = 2.25 * r
  368. local k6 = 2.625 * r
  369. local k0 = 7.5625
  370. local t = k0
  371.  
  372. if x < k1 then return k0 * x*x
  373. elseif x < k2 then t = x - k3 return k0 * t*t + 0.75
  374. elseif x < k4 then t = x - k5 return k0 * t*t + 0.9375
  375. else t = x - k6 return k0 * t*t + 0.984375 end
  376. end;
  377. inBounce = function(x)
  378. x = 1 - x
  379. local r = 1 / 2.75
  380. local k1 = 1 * r
  381. local k2 = 2 * r
  382. local k3 = 1.5 * r
  383. local k4 = 2.5 * r
  384. local k5 = 2.25 * r
  385. local k6 = 2.625 * r
  386. local k0 = 7.5625
  387. local t = k0
  388.  
  389. if x < k1 then return 1 - (k0 * x*x)
  390. elseif x < k2 then t = x - k3 return 1 - (k0 * t*t + 0.75)
  391. elseif x < k4 then t = x - k5 return 1 - (k0 * t*t + 0.9375)
  392. else t = x - k6 return 1 - (k0 * t*t + 0.984375) end
  393. end;
  394. }
  395.  
  396.  
  397. animate.loadAnim = function(_, k)
  398. local this = {}
  399. this.data = k
  400. this.start = 0
  401.  
  402.  
  403. function this:Run()
  404. local t = tick()
  405. this.start = t
  406. this.starts = {}
  407.  
  408. for i, o in pairs(this.data) do
  409. this.starts[i] = o.object[o.prop]
  410. end
  411.  
  412. table.insert(animate.running, this)
  413. end;
  414.  
  415.  
  416. function this:Cancel()
  417.  
  418. end
  419.  
  420.  
  421. function this:Stop()
  422. for i, anim in pairs(animate.running) do
  423. if anim == this then
  424. animate.running[i] = nil
  425. end
  426. end
  427.  
  428. local data = this.data
  429. for i, o in pairs(data) do
  430. o.object[o.prop] = o.keys[#o.keys].cf
  431. end
  432. end
  433.  
  434.  
  435. return this
  436. end
  437.  
  438.  
  439. local function update()
  440. for _, anim in pairs(animate.running) do
  441. local t = tick()
  442. local elapsed = t - anim.start
  443. local data = anim.data
  444.  
  445. for i, o in pairs(data) do
  446. local key, it = o.keys[1], 1
  447. for iit, k in pairs(o.keys) do
  448. if elapsed < k.time and elapsed > key.time then
  449. key = k
  450. it = iit
  451. end
  452. end
  453.  
  454. local prev = o.keys[it - 1]
  455. local prevTime = prev and prev.time or 0
  456.  
  457. local next = o.keys[it + 1]
  458. if not next then
  459. anim:Stop()
  460. break
  461. end
  462.  
  463. local a = (elapsed - prevTime)/(key.time - prevTime)
  464. o.object[o.prop] = next.cf:lerp(key.cf, 1 - animate.tweens[key.style](a))
  465. end
  466.  
  467. end
  468. end
  469.  
  470.  
  471. rs:BindToRenderStep("Animation Update", 200, update)
  472. end
  473.  
  474.  
  475.  
  476.  
  477.  
  478.  
  479.  
  480.  
  481.  
  482.  
  483.  
  484.  
  485.  
  486.  
  487.  
  488.  
  489.  
  490.  
  491.  
  492.  
  493.  
  494. do -- Physics Scope
  495. local Meta = {__index = physics}
  496. local PhysicObjects = {}
  497.  
  498. physics.Gravity = -9.86
  499. physics.Position = v3()
  500. physics.Rotation = v3()
  501. physics.Velocity = v3()
  502. physics.RotVelocity = v3()
  503. physics.LastUpdate = 0
  504. physics.Attached = nil
  505. physics.Enabled = true
  506.  
  507.  
  508. function physics.new(part, timeout)
  509. local self = setmetatable({}, Meta)
  510. self.LastUpdate = tick()
  511. self.TimeOut = tick() + timeout
  512.  
  513. if part then
  514. self:SetAttached(part, true)
  515. end
  516.  
  517. table.insert(PhysicObjects, self)
  518. return self
  519. end
  520.  
  521.  
  522. function physics:Update(time)
  523. if not self.Enabled or not self.Attached then return end
  524.  
  525. if self.TimeOut and tick() >= self.TimeOut then
  526. self:Destroy()
  527. return
  528. end
  529.  
  530. local dt = (time - self.LastUpdate) * tick.speed
  531. self.LastUpdate = time
  532.  
  533. local v = self.Velocity
  534. local p = self.Position
  535. local r = self.Rotation
  536. local rV = self.RotVelocity
  537. local g = self.Gravity
  538.  
  539. local cV = v + v3(0, g * dt, 0)
  540. local cP = p + cV
  541. local cR = r + rV * dt
  542.  
  543. self.Velocity = cV
  544. self.Position = cP
  545. self.Rotation = cR
  546.  
  547. self.Attached.CFrame = self:GetCFrame()
  548. end
  549.  
  550.  
  551. function physics:GetCFrame()
  552. local r = self.Rotation
  553. return cf(self.Position) * fea(r.X, r.Y, r.Z)
  554. end
  555.  
  556.  
  557. function physics:Toggle(enabled)
  558. self.Enabled = enabled
  559. end
  560.  
  561.  
  562. function physics:SetAttached(part, currentCFrame)
  563. self.Attached = part
  564.  
  565. if currentCFrame then
  566. local cframe = part.CFrame
  567. self.Position = cframe.p
  568. self.Rotation = v3(cframe:toEulerAnglesXYZ())
  569. end
  570. end
  571.  
  572.  
  573. function physics:Destroy()
  574. for index, obj in ipairs(PhysicObjects)do
  575. if obj == self then
  576. table.remove(PhysicObjects, index)
  577.  
  578. if self.Attached then
  579. self.Attached:Destroy()
  580. end
  581. break
  582. end
  583. end
  584. end
  585.  
  586.  
  587. game:GetService("RunService").Heartbeat:connect(function()
  588. local time = tick()
  589.  
  590. for _, obj in next, PhysicObjects do
  591. obj:Update(time)
  592. end
  593. end)
  594. end
  595.  
  596. -- old
  597.  
  598. --do -- Phyiscs Scope
  599. -- local gravity = -9.86
  600. -- physics.objects = {}
  601. --
  602. --
  603. -- function physics.new(attached)
  604. -- local this = {
  605. -- velocity = v3();
  606. -- position = v3();
  607. -- rotation = v3();
  608. -- rotVelocity = v3();
  609. -- gravity = gravity;
  610. --
  611. -- attached = nil;
  612. -- enabled = true;
  613. -- }
  614. --
  615. --
  616. -- function this.step(dt)
  617. -- if not this.enabled then return end
  618. --
  619. -- local v = this.velocity
  620. -- local p = this.position
  621. -- local r = this.rotation
  622. -- local rV = this.rotVelocity
  623. -- local g = this.gravity
  624. --
  625. -- local cV = v + v3(0, g * dt, 0)
  626. -- local cP = p + cV
  627. -- local cR = r + rV * dt
  628. --
  629. -- this.velocity = cV
  630. -- this.position = cP
  631. -- this.rotation = cR
  632. -- end
  633. --
  634. --
  635. -- function this:toCFrame()
  636. -- local r = this.rotation
  637. -- return cf(this.position) * ca(r.x, r.y, r.z)
  638. -- end
  639. --
  640. --
  641. -- function this:Toggle(bool)
  642. -- this.enabled = bool
  643. -- end
  644. --
  645. --
  646. -- function this:SetAttached(part, useCurrent)
  647. -- this.attached = part
  648. --
  649. -- if useCurrent then
  650. -- this.position = part.CFrame.p
  651. -- this.rotation = v3(part.CFrame:toEulerAnglesXYZ()) -- im cheating
  652. -- end
  653. -- end
  654. --
  655. --
  656. -- if attached then
  657. -- this:SetAttached(attached, true)
  658. -- end
  659. --
  660. -- table.insert(physics.objects, this)
  661. --
  662. -- return this
  663. -- end
  664. --
  665. --
  666. -- local function physicsStep(dt)
  667. -- for i = 1, #physics.objects do
  668. -- local po = physics.objects[i]
  669. -- po.step(dt)
  670. --
  671. -- if po.attached then
  672. -- po.attached.CFrame = po:toCFrame()
  673. -- end
  674. -- end
  675. -- end
  676. --
  677. --
  678. -- rs.Heartbeat:connect(physicsStep)
  679. --end
  680.  
  681.  
  682.  
  683.  
  684.  
  685.  
  686.  
  687.  
  688.  
  689.  
  690.  
  691.  
  692.  
  693.  
  694.  
  695.  
  696.  
  697.  
  698.  
  699.  
  700.  
  701.  
  702.  
  703.  
  704.  
  705.  
  706.  
  707.  
  708.  
  709.  
  710.  
  711.  
  712.  
  713.  
  714.  
  715.  
  716.  
  717.  
  718.  
  719.  
  720.  
  721.  
  722. do -- Vector Scope
  723. function vector.clamp(v, h, l)
  724. return v3(
  725. clamp(v.x, h, l),
  726. clamp(v.y, h, l),
  727. clamp(v.z, h, l)
  728. )
  729. end
  730. end
  731.  
  732.  
  733.  
  734.  
  735.  
  736.  
  737.  
  738.  
  739.  
  740.  
  741.  
  742.  
  743.  
  744.  
  745.  
  746.  
  747.  
  748.  
  749.  
  750. do -- cfame scope
  751. function cframe.squashRotMatrix(c, scale)
  752. local matrix = {c:components()}
  753. for i = 4, 12 do
  754. matrix[i] = matrix[i] * scale
  755. end
  756.  
  757. return cf(unpack(matrix))
  758. end
  759. end
  760.  
  761.  
  762.  
  763.  
  764.  
  765.  
  766.  
  767.  
  768.  
  769.  
  770.  
  771.  
  772.  
  773.  
  774.  
  775.  
  776.  
  777.  
  778.  
  779.  
  780.  
  781.  
  782.  
  783.  
  784.  
  785.  
  786. do -- Network module
  787. local this = network;
  788. local updateStep = 1/60 -- 1/5
  789.  
  790. -- player.Chatted:connect(function(msg)
  791. -- if msg:sub(1, 4) == "/rep" then
  792. -- if tonumber(msg:sub(6, string.len(msg)))then
  793. -- updateStep = tonumber(msg:sub(6, string.len(msg)))
  794. -- end
  795. -- end
  796. -- end)
  797.  
  798. local bounceEvent = events.Bounce
  799. local requests = {}
  800. local players = {}
  801. local update = false
  802. local updateTick = tick()
  803.  
  804. local dataPack = {
  805. [1] = {Name = "position"; Default = v3()};
  806. [2] = {Name = "rotation"; Default = v2()};
  807. [3] = {Name = "joints"; Default = {cf(0, 1.5, 0); cf(-.5, -2, 0); cf(.5, -2, 0); cf(-1.5, 0, 0); cf(1.5, 0, 0)}};
  808. }
  809.  
  810. local bounceOut, bounceIn, bounceDataLength = {}, {}, 0
  811. for i, data in pairs(dataPack) do
  812. bounceIn[i] = data.Name
  813. bounceOut[data.Name] = i;
  814. bounceDataLength = bounceDataLength + 1
  815. end
  816.  
  817. function network:bounce(name, data)
  818. requests[bounceOut[name]] = data
  819. if not update then update = true end -- noticed setting value to same is more cpu than checking a value
  820. end
  821.  
  822.  
  823. function network:send(name, data)
  824. events[name]:FireServer(data)
  825. end
  826.  
  827.  
  828. function network:fastbounce(name, data)
  829. events.FastBounce[name]:FireServer(data)
  830. end
  831.  
  832.  
  833. function network:connect(event, func)
  834. events.FastBounce[event].OnClientEvent:connect(func)
  835. end
  836.  
  837.  
  838. bounceEvent.OnClientEvent:connect(function(player, data)
  839. local p = players[player.Name]
  840. if not p then
  841. players[player.Name] = {}
  842. p = players[player.Name]
  843. end
  844.  
  845. for i = 1, bounceDataLength do
  846. if data[i] then
  847. p[bounceIn[i]] = data[i]
  848. end
  849. end
  850. end)
  851.  
  852.  
  853. rs:BindToRenderStep("bounce", Enum.RenderPriority.Last.Value, function()
  854. if update and tick() - updateTick > updateStep then
  855. bounceEvent:FireServer(requests)
  856. requests = {}
  857. update = false
  858. updateTick = tick()
  859. end
  860. end)
  861.  
  862. local function addPlayer(player)
  863. local data = {}
  864.  
  865. data.player = player
  866.  
  867. for _, x in pairs(dataPack)do
  868. data[x.Name] = x.Default
  869. end
  870.  
  871. players[player.Name] = data
  872. end
  873.  
  874. game.Players.PlayerAdded:connect(addPlayer)
  875. game.Players.PlayerRemoving:connect(function(player) players[player.Name] = nil end)
  876. for _, plr in ipairs(game.Players:GetPlayers()) do addPlayer(plr) end
  877.  
  878. network.players = players
  879. end
  880.  
  881.  
  882.  
  883.  
  884.  
  885.  
  886.  
  887.  
  888.  
  889.  
  890.  
  891.  
  892.  
  893.  
  894.  
  895.  
  896.  
  897.  
  898.  
  899.  
  900.  
  901.  
  902. do -- Character Scope
  903. character.char = player.Character or player.CharacterAdded:wait()
  904. character.distance = 0
  905. character.lastPosition = wfc(character.char, "HumanoidRootPart").CFrame.p
  906.  
  907. character.speedSpring = spring.new(16, 1, 12)
  908. character.heightSpring = spring.new(0, 1, 17)
  909. character.state = "idle"
  910. character.stance = "stand"
  911. character.alive = false
  912. character.lastJump = 0
  913. character.jumpTime = .7
  914. character.lastSlide = 0
  915. character.slideTime = .7
  916. character.speeds = {
  917. idle = 17;
  918. sprint = 24;
  919. aim = 12; }
  920. character.stanceMult = {
  921. stand = 1;
  922. crouch = .6;
  923. prone = .2; }
  924. character.stances = {
  925. stand = 0;
  926. crouch = -1.2;
  927. prone = -2.2; }
  928.  
  929.  
  930. function character:SetStance(stance)
  931. if not character.char then return end
  932. local hrp = ffc(character.char, "HumanoidRootPart")
  933. if not hrp then return end
  934.  
  935. if not weapon.equipped then return end
  936.  
  937. local t = tick()
  938.  
  939. if stance == character.stance then
  940. stance = "stand"
  941. end
  942.  
  943. local ground = character:CheckGround()
  944.  
  945. if stance == "crouch" and input.keysDown.leftshift and not(t - character.lastSlide < character.slideTime) and ground then
  946. weapon:SetState("idle", true)
  947. character.lastSlide = t
  948. character.pushForce.Force = hrp.CFrame.lookVector * v3(1, 0, 1) * 3200
  949. weapon:Push(v3(0, -1, -.7).unit, 3.4343563425)
  950.  
  951. spawn(function()
  952. wait(.13)
  953. character.pushForce.Force = v3()
  954. end)
  955. end
  956.  
  957. if character.stance == "crouch" and stance ~= "crouch" then
  958. weapon:SetState("idle")
  959. end
  960. character.stance = stance
  961. character.heightSpring.t = character.stances[stance]
  962. weapon:SetStance(stance)
  963. end
  964.  
  965.  
  966. function character:CheckGround()
  967. local hrp = ffc(character.char, "HumanoidRootPart")
  968. if not hrp then return end
  969.  
  970. local dRay = Ray.new(hrp.CFrame.p, v3(0, -3.2, 0))
  971. local dHit, dPos = game.Workspace:FindPartOnRayWithIgnoreList(dRay, {game.Workspace.Ignore; character.char; cam; weapon.model;})
  972.  
  973. return dHit, dPos
  974. end
  975.  
  976.  
  977. function character:Jump()
  978. local t = tick()
  979. local hrp = ffc(character.char, "HumanoidRootPart")
  980.  
  981. if not hrp then return end
  982. if t - character.lastJump < character.jumpTime then return else character.lastJump = t end
  983.  
  984. local ignore = {game.Workspace.Ignore; character.char; cam; weapon.model;}
  985. local bp = hrp.CFrame.p - v3(0, .1, 0)
  986. local lv = hrp.CFrame.lookVector
  987. local bv = hrp.Velocity
  988. local speed = character.speedSpring.p
  989.  
  990. local ground = character:CheckGround()
  991.  
  992. if ground then
  993. local mRay = Ray.new(bp - v3(0, .7, 0), lv * 3.9)
  994. local mHit, mPos = game.Workspace:FindPartOnRayWithIgnoreList(mRay, ignore)
  995.  
  996. local uRay = Ray.new(bp + v3(0, 2.718/1.8, 0), lv * 7 + v3(0, 6, 0))
  997. local uHit, uPos = game.Workspace:FindPartOnRayWithIgnoreList(uRay, ignore)
  998.  
  999. -- util.drawRay(mRay.Origin, mPos)
  1000. -- util.drawRay(uRay.Origin, uPos)
  1001.  
  1002. if mHit and not uHit then
  1003. weapon.vaultSpring:accelerate(18)
  1004. hrp.Velocity = bv + v3(0, 30, 0) + lv * v3(0, 0, 40)
  1005.  
  1006. spawn(function()
  1007. wait(.1)
  1008. hrp.Velocity = bv + v3(0, 5, 0)
  1009. end)
  1010. else
  1011. hrp.Velocity = bv + v3(0, (400 * 3)^.5, 0)
  1012. end
  1013. end
  1014.  
  1015. end
  1016.  
  1017.  
  1018. local function stateChange(state, lastState)
  1019. state = state.Name:lower()
  1020.  
  1021. if state == "landed" then
  1022. weapon:Push(v3(0, -1, 0), .7)
  1023. end
  1024. end
  1025.  
  1026.  
  1027. local function filterChild(child)
  1028. if child:IsA("BasePart") then
  1029. child.Transparency = 1
  1030. elseif child:IsA("Clothing") or child:IsA("Hat") then
  1031. child:Destroy()
  1032. end
  1033. end
  1034.  
  1035.  
  1036. local function characterAdded(char)
  1037. character.char = char
  1038.  
  1039. spawn(function()
  1040. wfc(char, "Left Arm"):Destroy()
  1041. wfc(char, "Right Arm"):Destroy()
  1042.  
  1043. local head = wfc(char, "Head")
  1044. local humanoid = wfc(char, "Humanoid")
  1045. local hrp = wfc(char, "HumanoidRootPart")
  1046.  
  1047. humanoid.AutoRotate = false
  1048. humanoid.JumpPower = 0
  1049.  
  1050. repeat wait()
  1051. if ffc(head, "face") then
  1052. head.face:Destroy()
  1053. end
  1054. until not ffc(head, "face")
  1055.  
  1056. for _, child in ipairs(char:GetChildren()) do
  1057. filterChild(child)
  1058. end
  1059.  
  1060. --character.controlForce = new("BodyThrust", hrp)
  1061. --character.controlForce.MaxForce = v3(1, 0, 1) * 1000
  1062. character.pushForce = new("BodyForce", hrp)
  1063. character.pushForce.Force = v3()
  1064.  
  1065. weapon:Toggle(true)
  1066.  
  1067. char.DescendantAdded:connect(filterChild)
  1068. humanoid.StateChanged:connect(stateChange)
  1069. humanoid.Died:connect(function() weapon:Toggle(false) end)
  1070. end)
  1071. end
  1072.  
  1073.  
  1074. local function update()
  1075. if not ffc(character.char, "HumanoidRootPart") then return end
  1076. if not ffc(character.char, "Humanoid") then return end
  1077.  
  1078. local hrp = character.char.HumanoidRootPart
  1079. local humanoid = character.char.Humanoid
  1080. local speed = character.speedSpring.p
  1081.  
  1082. local position = hrp.CFrame.p * v3(1, 0, 1)
  1083. character.distance = character.distance + (position - character.lastPosition).magnitude * .9
  1084. character.lastPosition = position
  1085.  
  1086. local velocity = hrp.Velocity * v3(1, 0, 1)
  1087. magnitudeSpring.t = velocity.magnitude > 0 and velocity.magnitude or 0
  1088.  
  1089. local w, a, s, d = input.keysDown.w, input.keysDown.a, input.keysDown.s, input.keysDown.d
  1090. local dir = v2()
  1091.  
  1092. if w and not s then
  1093. dir = v2(dir.x, 1)
  1094. elseif s and not w then
  1095. dir = v2(dir.x, -1)
  1096. else
  1097. dir = v2(dir.x, 0)
  1098. end
  1099.  
  1100. if a and not d then
  1101. dir = v2(-1, dir.y)
  1102. elseif d and not a then
  1103. dir = v2(1, dir.y)
  1104. else
  1105. dir = v2(0, dir.y)
  1106. end
  1107.  
  1108. if dir == v2() then
  1109. character.speedSpring.t = 0
  1110. else
  1111. character.speedSpring.t = character.speeds[character.state] * character.stanceMult[character.stance]
  1112. end
  1113.  
  1114. -- Buggy custom movement
  1115. -- local direction = v3(dir.x, 0, -dir.y)
  1116. -- local velocity = hrp.Velocity * v3(1, 0, 1)
  1117. --
  1118. -- character.controlForce.Force = (direction.magnitude > 1 and direction.unit or direction) * 1900)
  1119. -- hrp.Velocity = v3(0, hrp.Velocity.y, 0) + (velocity.magnitude > 0 and velocity.unit * clamp(velocity.magnitude, 0, speed) or velocity)
  1120.  
  1121.  
  1122. humanoid.WalkSpeed = speed * tick.speed
  1123. end
  1124.  
  1125.  
  1126. characterAdded(character.char)
  1127. player.CharacterAdded:connect(characterAdded)
  1128. rs:BindToRenderStep("CharacterUpdate", 150, update)
  1129. end
  1130.  
  1131.  
  1132.  
  1133.  
  1134.  
  1135.  
  1136.  
  1137.  
  1138.  
  1139.  
  1140.  
  1141.  
  1142.  
  1143.  
  1144.  
  1145.  
  1146.  
  1147.  
  1148.  
  1149.  
  1150.  
  1151.  
  1152.  
  1153.  
  1154. do -- Weapon Scope
  1155. local base = new("Part", game.Workspace)
  1156. base.Size = v3(.2, .2, .2)
  1157. base.Anchored = true
  1158. base.CanCollide = false
  1159. base.Transparency = 1
  1160.  
  1161. weapon.base = base
  1162.  
  1163. weapon.weapons = {
  1164. require(game.ReplicatedStorage.Weapons["Anaconda"]);
  1165. require(game.ReplicatedStorage.Weapons["G36"]);
  1166. require(game.ReplicatedStorage.Weapons["G17"]);
  1167. require(game.ReplicatedStorage.Weapons["AK-74B"]);
  1168. }
  1169.  
  1170. weapon.equipSpring = spring.new(1, 1, 9)
  1171. weapon.positionSpring = spring.new(v3(), .7, aimSpring.s)
  1172. weapon.rotationSpring = spring.new(cf().lookVector, weapon.positionSpring.d, weapon.positionSpring.s)
  1173. weapon.swaySpring = spring.new(v2(), .6, 13)
  1174. weapon.sprintSpring = spring.new(0, weapon.positionSpring.d, weapon.positionSpring.s+1)
  1175. weapon.tiltSpring = spring.new(v2(), 1, 12)
  1176. weapon.pushSpring = spring.new(v3(), 1, 7)
  1177. weapon.vaultSpring = spring.new(0, 1, weapon.positionSpring.s)
  1178.  
  1179. weapon.rRotSpring = spring.new(v3(), .7, 13)
  1180. weapon.rKickSpring = spring.new(v2(), 1, 25)
  1181. weapon.rCamRotSpring = spring.new(v3(), 1, 10)
  1182. weapon.rCamKickSpring = spring.new(v2(), 1, 23)
  1183.  
  1184. weapon.firing = false
  1185. weapon.lastfire = tick()
  1186. weapon.shown = true
  1187.  
  1188.  
  1189. function weapon:SetStance(stance)
  1190.  
  1191. end
  1192.  
  1193.  
  1194. function weapon:EjectShell()
  1195. local shell = weapon.model.Eject:Clone()
  1196. shell.Parent = game.Workspace.Ignore
  1197. shell.Transparency = 0
  1198.  
  1199. local dir = shell.CFrame.lookVector
  1200. local po = physics.new(shell, .7)
  1201. po.Velocity = dir * .7 + v3(0, .1, 0) + v3(1, 0, 1) * srandom()/6
  1202. po.RotVelocity = v3(pi * srandom(), pi * srandom())
  1203. po.Gravity = -3
  1204. -- po:Update(0)
  1205. end
  1206.  
  1207.  
  1208. function weapon:Push(d, m)
  1209. weapon.pushSpring:accelerate(d * m)
  1210. end
  1211.  
  1212.  
  1213. function weapon:SetState(state, override)
  1214. if not weapon.shown then return end
  1215. if not input.keysDown then return end
  1216.  
  1217. if state == "idle" then
  1218. if input.right then
  1219. state = "aim"
  1220. elseif input.keysDown.leftshift and not override then
  1221. state = "sprint"
  1222. end
  1223. end
  1224.  
  1225. if state == "idle" and input.left then
  1226. weapon.firing = true
  1227. end
  1228.  
  1229. if state == "aim" then
  1230. aimSpring.t = 0
  1231. else
  1232. aimSpring.t = 1
  1233. end
  1234.  
  1235. if state == "sprint" then
  1236. weapon.sprintSpring.t = 1
  1237. weapon.firing = false
  1238. else
  1239. weapon.sprintSpring.t = 0
  1240. end
  1241.  
  1242. local stateCf = weapon.equipped[state]
  1243. if stateCf then
  1244. stateCf = stateCf[1]
  1245. else
  1246. stateCf = weapon:GetAimSpot()
  1247. end
  1248.  
  1249. character.speedSpring.t = character.speeds[state]
  1250. ui.crossSpring.t = ui.crossAmounts[state]
  1251. weapon.positionSpring.t = stateCf.p
  1252. weapon.rotationSpring.t = stateCf.lookVector
  1253. character.state = state
  1254. weapon.lastFire = tick()
  1255. end
  1256.  
  1257.  
  1258. function weapon:SetMode(v)
  1259. -- Fire Mode
  1260. -- Three round burst
  1261. -- Single shot
  1262. -- Automatic
  1263. end
  1264.  
  1265.  
  1266. function weapon.makeArms()
  1267. if weapon.left then weapon.left:Destroy() end
  1268. if weapon.right then weapon.right:Destroy() end
  1269.  
  1270. weapon.left = game.ReplicatedStorage.Arm:Clone()
  1271. weapon.left.Parent = game.Workspace.Ignore
  1272. util.weldModel(weapon.left, weapon.left.PrimaryPart)
  1273.  
  1274. weapon.right = weapon.left:Clone()
  1275. weapon.right.Parent = game.Workspace.Ignore
  1276. end
  1277.  
  1278.  
  1279. function weapon:Toggle(bool)
  1280. weapon.shown = bool
  1281.  
  1282. if not weapon.shown then
  1283. weapon.firing = false
  1284. end
  1285. end
  1286.  
  1287.  
  1288. function weapon:Load(slot)
  1289. if slot == weapon.loaded then return end
  1290. if weapon.model then weapon.model:Destroy() end
  1291.  
  1292. weapon.loaded = slot
  1293. weapon.equipped = weapon.weapons[slot]
  1294.  
  1295. if not weapon.equipped then return end
  1296. weapon.model = weapon.equipped.model:Clone()
  1297. weapon.model.Parent = game.Workspace
  1298.  
  1299. local flash = ffc(weapon.model.Barrel, "Flash")
  1300. if not flash then
  1301. flash = particles.Flash:Clone()
  1302. flash.Parent = weapon.model.Barrel
  1303. end
  1304.  
  1305. flash.Texture = weapon.equipped.FlashImg
  1306.  
  1307. BulletHole.SetDecal(weapon.equipped.BulletHole.Texture)
  1308. BulletHole.SetSize(weapon.equipped.BulletHole.Size)
  1309.  
  1310. local wep = weapon.equipped
  1311.  
  1312. if ffc(weapon.model, "slide") then
  1313. util.weldModel(weapon.model, weapon.model.PrimaryPart, ffc(weapon.model, "sights"))
  1314. util.weld(weapon.model.sights, weapon.model.slide)
  1315. else
  1316. util.weldModel(weapon.model, weapon.model.PrimaryPart)
  1317. end
  1318.  
  1319. for i, v in pairs(weapon.model:GetChildren()) do
  1320. if v:IsA("BasePart") then
  1321. v.Anchored = false
  1322. v.CanCollide = false
  1323. end
  1324. end
  1325.  
  1326.  
  1327. local weld = new("Motor6D", base)
  1328. weld.Part0 = base
  1329. weld.Part1 = weapon.model.PrimaryPart
  1330.  
  1331. weapon:SetState("idle")
  1332. weapon.firing = false
  1333.  
  1334. if ffc(weapon.model, "slide") and weapon.equipped.slideAnimation then
  1335. weapon.slideAnim = animate({{
  1336. object = wfc(weapon.model.PrimaryPart, "slide");
  1337. prop = "C1";
  1338. keys = {
  1339. {
  1340. time = 0;
  1341. style = "linear";
  1342. cf = cf(0, 0, 0);
  1343. };
  1344. {
  1345. time = .1;
  1346. style = "linear";
  1347. cf = cf(0, 0, .3);
  1348. };
  1349. {
  1350. time = .2;
  1351. style = "linear";
  1352. cf = cf();
  1353. };
  1354. };
  1355. };})
  1356. end
  1357.  
  1358.  
  1359. weapon.rRotSpring.d = wep.recoilRotDamp or weapon.rRotSpring.d
  1360. weapon.rRotSpring.s = wep.recoilRotSpeed or weapon.rRotSpring.s
  1361. weapon.rKickSpring.d = wep.recoilKickDamp or weapon.rKickSpring.d
  1362. weapon.rKickSpring.s = wep.recoilKickSpeed or weapon.rKickSpring.s
  1363. weapon.rCamRotSpring.d = wep.camRecoilRotDamp or weapon.rCamRotSpring.d
  1364. weapon.rCamRotSpring.s = wep.camRecoilRotSpeed or weapon.rCamRotSpring.s
  1365. weapon.rCamKickSpring.d = wep.camRecoilKickDamp or weapon.rCamKickSpring.d
  1366. weapon.rCamKickSpring.s = wep.camRecoilKickSpeed or weapon.rCamKickSpring.s
  1367. end
  1368.  
  1369.  
  1370. function weapon:Scroll(v)
  1371. local slot = weapon.loaded + v
  1372.  
  1373. if slot > #weapon.weapons then
  1374. slot = slot - #weapon.weapons
  1375. elseif slot == 0 then
  1376. slot = #weapon.weapons
  1377. end
  1378.  
  1379. weapon.equipSpring.t = 1
  1380. weapon.equipSpring.p = 0
  1381. weapon:Load(slot)
  1382. end
  1383.  
  1384.  
  1385. function weapon:GetAimSpot()
  1386. if not weapon.equipped then return end
  1387. if not weapon.model then return end
  1388. if not ffc(weapon.model, "Sight") then return end
  1389. if not weapon.model.PrimaryPart then return end
  1390.  
  1391. return weapon.model.Sight.CFrame:inverse() * weapon.model.PrimaryPart.CFrame
  1392. end
  1393.  
  1394.  
  1395. local function BulletRayCast()
  1396. local rays = 0
  1397. local hit, pos, normal
  1398.  
  1399. local start = weapon.model.Barrel.CFrame.p
  1400. local last = start
  1401.  
  1402. local xaxis = (weapon.model.Barrel.CFrame * ca(srandom() * rad(.1), srandom() * rad(.1), 0)).lookVector * 100
  1403. local yaxis = weapon.model.Barrel.CFrame:vectorToWorldSpace(v3(1, 0, 0)):Cross(xaxis).unit
  1404.  
  1405. local grav = -.2
  1406. local v0 = 0 -- initial velocity
  1407. local x0 = 0 -- initial position
  1408.  
  1409. local t = 0
  1410. repeat -- EgoMoose
  1411. local yvalue = (grav/2) * t^2 + t * v0 + x0
  1412. local nextPos = start + xaxis * t + yaxis * yvalue
  1413.  
  1414. local ray = Ray.new(last, (nextPos - last))
  1415. hit, pos, normal = game.Workspace:FindPartOnRayWithIgnoreList(ray, {game.Workspace.Ignore; character.char; cam; weapon.model;})
  1416.  
  1417. rays = rays + 1
  1418. last = nextPos
  1419. t = t + 0.5
  1420.  
  1421. -- util.drawRay(ray.Origin, pos)
  1422. -- draw(pos)
  1423. until hit or rays > 10
  1424.  
  1425. return hit, pos , normal
  1426. end
  1427.  
  1428.  
  1429. function weapon:LateFire()
  1430. if weapon.equipped.eject then
  1431. weapon:EjectShell()
  1432. end
  1433. end
  1434.  
  1435.  
  1436. function weapon.fire()
  1437. if not weapon.shown then return end
  1438. if not weapon.equipped then return end
  1439. if not weapon.firing then return end
  1440. if character.state == "sprint" then weapon:SetState("idle", true) end
  1441. if tick() - weapon.lastfire < weapon.equipped.rof then return end
  1442.  
  1443. local wepRecoil = weapon.equipped.recoil
  1444. local camRecoil = weapon.equipped.camRecoil
  1445. weapon.rRotSpring.a = (v3(biasedRandom() * wepRecoil.y, biasedRandom() * wepRecoil.z * srandom(), biasedRandom() * wepRecoil.z * srandom()))
  1446. weapon.rKickSpring.a = (v2(biasedRandom() * wepRecoil.x, biasedRandom() * wepRecoil.x))
  1447. weapon.rCamRotSpring.a = (v3(biasedRandom() * camRecoil.y, biasedRandom() * camRecoil.z * srandom(), biasedRandom() * camRecoil.z * srandom()))
  1448. weapon.rCamKickSpring.a = (v2(biasedRandom() * camRecoil.x, biasedRandom() * camRecoil.x))
  1449.  
  1450. weapon.lastfire = tick()
  1451.  
  1452. if weapon.slideAnim then
  1453. weapon.slideAnim:Run()
  1454. end
  1455.  
  1456. local fireSound = new("Sound", weapon.model.PrimaryPart)
  1457. fireSound.Name = "Fire"
  1458. fireSound.SoundId = "rbxassetid://"..weapon.equipped.shoot
  1459. fireSound:Play()
  1460. fireSound.Volume = .7
  1461. fireSound.Pitch = .95
  1462. delay(fireSound.TimeLength, function()
  1463. fireSound:Destroy()
  1464. end)
  1465.  
  1466. local flash = ffc(weapon.model.Barrel, "Flash")
  1467. if flash then
  1468. flash:Emit(1)
  1469. end
  1470.  
  1471. local hit, pos, normal = BulletRayCast()
  1472.  
  1473. if hit then
  1474. -- local particleBase = game.ReplicatedStorage.Particles.Centered:Clone()
  1475. -- particleBase.Parent = game.Workspace.Ignore
  1476. -- particleBase.CFrame = cf(pos)
  1477. -- local particle = game.ReplicatedStorage.Particles.Ground:Clone()
  1478. -- particle.Acceleration = -cam.CFrame.lookVector * 5 + v3(0, -40, 0)
  1479. -- particle.Parent = particleBase
  1480. -- local color = hit.BrickColor.Color
  1481. -- particle.Color = ColorSequence.new(Color3.new(color.r - .05, color.g - .05, color.b - .05), Color3.new(color.r - .15, color.g - .15, color.b - .15))
  1482. -- spawn(function()
  1483. -- wait()
  1484. -- particle:Emit(5)
  1485. -- end)
  1486. --
  1487. -- delay(particle.Lifetime.Max, function()
  1488. -- particle:Destroy()
  1489. -- particleBase:Destroy()
  1490. -- end)
  1491.  
  1492. local target = ffc(game.Players, hit.Parent.Name)
  1493. if not target then -- might hit the torso
  1494. target = ffc(game.Players, hit.Name)
  1495. end
  1496. local t = false
  1497. if hit.Parent:FindFirstChild("Humanoid") then
  1498. t = true
  1499. events.Shoot:FireServer(hit.Parent.Humanoid, weapon.equipped.damage)
  1500. end
  1501.  
  1502. if target and not t then
  1503. events.Shoot:FireServer(target, weapon.equipped.damage)
  1504. ui:Hit()
  1505. end
  1506. end
  1507.  
  1508. BulletHole.draw(pos, normal)
  1509.  
  1510. if weapon.equipped.fireType == "semi" then
  1511. weapon.stopFiring()
  1512. end
  1513.  
  1514.  
  1515. return true
  1516. end
  1517.  
  1518.  
  1519. function weapon.stopFiring()
  1520. if not input.keysDown then return end
  1521.  
  1522. weapon.firing = false
  1523.  
  1524. if input.keysDown.leftshift and not input.right then
  1525. weapon:SetState("sprint")
  1526. end
  1527. end
  1528.  
  1529. function weapon.startFiring()
  1530. if not weapon.equipped then return end
  1531.  
  1532. weapon.firing = true
  1533. if weapon.fire() then
  1534. weapon:LateFire()
  1535. end
  1536. end
  1537.  
  1538.  
  1539. -- shouldnt be affected by low refresh rate?
  1540. local function updateSway()
  1541. local deltaChange = input.lastDelta - input.delta
  1542. --weapon.swaySpring.t = -v2(rad(deltaChange.x), rad(deltaChange.y)) * .3
  1543. weapon.swaySpring.a = -v2(rad(deltaChange.x), rad(deltaChange.y)) * .3
  1544. input.lastDelta = input.delta
  1545. input.delta = v2()
  1546. end
  1547.  
  1548.  
  1549. local function update()
  1550. if not character.char then return end
  1551. if not weapon.equipped then return end
  1552. if not ffc(character.char, "HumanoidRootPart") then return end
  1553.  
  1554. if not weapon.left or not weapon.right then weapon.makeArms() end
  1555. if not weapon.left.PrimaryPart or not weapon.right.PrimaryPart then weapon.makeArms() end
  1556.  
  1557. local lateFire = weapon.fire()
  1558.  
  1559. local t = tick()
  1560. local ticks = tick.speed
  1561. local dist = character.distance
  1562. local hrp = character.char.HumanoidRootPart
  1563. local aim = aimSpring.p
  1564. local altAim = aim + .2
  1565. local halfAim = aim + .5 > 1 and 1 or aim + .5
  1566. local tilt = weapon.tiltSpring.p * altAim
  1567. local vault = weapon.vaultSpring.p
  1568. local position = weapon.positionSpring.p
  1569. local rotation = weapon.rotationSpring.p
  1570. local speed = character.speedSpring.p
  1571. local equip = weapon.equipSpring.p
  1572. local sway = weapon.swaySpring.p * altAim
  1573. local push = weapon.pushSpring.p
  1574. local sprint = weapon.sprintSpring.p
  1575. local magnitude = magnitudeSpring.p
  1576. local shock = bounceSpring.p * altAim
  1577. local sprintType = weapon.equipped.sprintAnim or "default"
  1578.  
  1579. cam.FieldOfView = 71 + weapon.equipped.fov * (1 - aim)
  1580.  
  1581. local offset = cf(position) * ca(asin(rotation.y), atan2(rotation.x, rotation.z) + pi, 0)
  1582.  
  1583. local velocity do
  1584. local mag = magnitude
  1585. local unit = (mag > .2 and hrp.Velocity.unit or v3())
  1586. local loc = hrp.CFrame:vectorToObjectSpace(unit)
  1587. local velo = veloSpring.p * 8 * altAim
  1588.  
  1589. velocity = ffa(v3(0, 0, 1), -rad(velo.x)) * ffa(v3(1, 0, 0), rad(velo.y) * .3) * ffa(v3(1, 0, 0), rad(shock))
  1590. end
  1591.  
  1592. local bob do
  1593. local s = 1.32 * altAim * magnitude/16
  1594. local m = sprint/2
  1595. local y = cos(dist)/32/2
  1596. if sign(y) == -1 then y = y*1.2 end
  1597.  
  1598. local sprintAnim = cf()
  1599. if sprintType == "default" then
  1600. sprintAnim = ca(0, -sin(dist/2)/7*m*s*altAim, m*rad(50)) * cf(sin(dist/2)/7*m*s, y*m*s, sin(dist/2)/6*m*s)
  1601. elseif sprintType == "pistol" then
  1602. s = s + 2 * sprint
  1603. sprintAnim = ca(pi/3*sprint*(1 - vault), 0, 0) * cf(cos(dist/2)/32/2*s*sprint, 0, 0)
  1604. end
  1605.  
  1606. bob = ca(cos(dist-2)/32/6*s, sin(dist/2)/32/4*s, cos(dist/2)/32/2*s) * cf(cos(dist/2)/32/2*s, y*s, 0) * sprintAnim
  1607. end
  1608.  
  1609. local breath do
  1610. local s = 1 * altAim * altAim
  1611. local t = t * .7
  1612.  
  1613. breath = ca(sin(t*2)/32/5*s, cos(t)/32/4*s, cos(t/2)/32/3*s) * cf(0, sin(t*2+1)/32/6*s, 0)
  1614. end
  1615.  
  1616. local recoil do
  1617. local s = 2.6 * halfAim
  1618. local r = 14 * halfAim
  1619. local kick = weapon.rKickSpring.p/2
  1620. local rot = weapon.rRotSpring.p/6
  1621.  
  1622. recoil = ca(rad(rot.x)/7*r*s, rot.y/32/18*s*r, rad(rot.y)/6*s*r) * cf(0, kick.y*s/7, kick.x*1.2*s)
  1623. end
  1624.  
  1625.  
  1626. local swayCf = cf(0, 1, 0) * ca(0, 0, sway.x/2) * ca(sway.y, sway.x, sway.x) * cf(sway.x/2.5, -1, 0)
  1627.  
  1628.  
  1629. base.CFrame = cam.CFrame * (cf(push.x, push.y, push.z) * offset:lerp(weapon.equipped.vault[1], vault) * swayCf * velocity * bob * recoil * breath):lerp(weapon.equipped.equip, 1 - equip)
  1630.  
  1631. if not weapon.shown then
  1632. base.CFrame = base.CFrame * cf(0, 0, 50)
  1633. end
  1634.  
  1635. do -- Arms
  1636. if not weapon.left then return end
  1637. if not weapon.right then return end
  1638.  
  1639. weapon.left.PrimaryPart.CFrame = (base.CFrame * weapon.equipped.idle[2]:lerp(weapon.equipped.sprint[2], sprint)):lerp(cam.CFrame * weapon.equipped.vault[2], vault)
  1640. weapon.right.PrimaryPart.CFrame = base.CFrame * weapon.equipped.rightArm
  1641. end
  1642.  
  1643. if lateFire then
  1644. weapon:LateFire()
  1645. end
  1646. end
  1647.  
  1648.  
  1649. weapon:Load(1)
  1650. rs:BindToRenderStep("WeaponUpdate", 250, update)
  1651. rs.Heartbeat:connect(updateSway)
  1652. end
  1653.  
  1654.  
  1655.  
  1656.  
  1657.  
  1658.  
  1659.  
  1660.  
  1661.  
  1662.  
  1663.  
  1664.  
  1665.  
  1666.  
  1667.  
  1668.  
  1669.  
  1670.  
  1671.  
  1672.  
  1673. do -- Camera Scope
  1674. local rotation = v2()
  1675. camera.offset = cf()
  1676.  
  1677.  
  1678. local function deltaCoef(fov)
  1679. return -atan(tan(rad(fov)/2)/2.72)/(32 * pi)
  1680. end
  1681.  
  1682.  
  1683. local function update()
  1684. if not character.char then return end
  1685. if not ffc(character.char, "HumanoidRootPart") then return end
  1686.  
  1687. local dist = character.distance/1.7-- * (2 * pi * .75)
  1688. local hrp = character.char.HumanoidRootPart
  1689.  
  1690. uis.MouseBehavior = "LockCenter"
  1691. uis.MouseIconEnabled = false
  1692. cam.CameraType = "Scriptable"
  1693.  
  1694. local base = cf(character.char.HumanoidRootPart.CFrame.p)
  1695. local delta = input.delta * deltaCoef(cam.FieldOfView)
  1696. local ticks = tick.speed
  1697. local magnitude = magnitudeSpring.p
  1698. local aim = aimSpring.p
  1699. local height = character.heightSpring.p
  1700. local altAim = aimSpring.p + .2
  1701.  
  1702. rotation = rotation + v2(delta.x, delta.y)
  1703. rotation = v2(rotation.x, clamp(rotation.y, -rad(89), rad(89)))
  1704.  
  1705. local velocity do
  1706. local mag = hrp.Velocity.magnitude
  1707. local unit = (mag > .2 and hrp.Velocity.unit or v3())
  1708. local loc = hrp.CFrame:vectorToObjectSpace(unit)
  1709.  
  1710. veloSpring.t = (v2(loc.x, loc.z)/15 * mag^.5)
  1711. local velo = veloSpring.p * v2(2, .6)
  1712.  
  1713. local bounceTarget = (-loc.y/15 * mag)
  1714. bounceSpring.t = bounceTarget
  1715. local bounce = bounceSpring.p
  1716.  
  1717. velocity = ffa(v3(0, 0, 1), -rad(velo.x)) * ffa(v3(1, 0, 0), rad(velo.y)) * ffa(v3(1, 0, 0), rad(bounce)/5)
  1718. end
  1719.  
  1720. local bob do
  1721. local s = .2 * altAim * magnitude/12
  1722. bob = ca(cos(dist*2-2)/32/6*s, sin(dist)/32/4*s, -cos(dist)/32/2*s)
  1723. --ca(sin(dist*2)/32/16*s, cos(dist)/32/16*s, sin(dist)/32/16/2*s)
  1724. end
  1725.  
  1726. local recoil do
  1727. local s = 1.8 + (aim)/2
  1728. local r = 8
  1729. local kick = weapon.rCamKickSpring.p/2
  1730. local rot = weapon.rCamRotSpring.p/6
  1731.  
  1732. recoil = cf(0, 0, 0) * ca(rad(rot.x)/2*s*r, rot.y/32/18*s*r, -rad(rot.y)/7*s*r)
  1733. end
  1734.  
  1735. camera.offset = recoil
  1736. cam.CFrame = base * cf(0, 1.6 + height, 0) * ffa(v3(0, 1, 0), rotation.x) * ffa(v3(1, 0, 0), rotation.y) * velocity * bob * recoil
  1737. character.char.HumanoidRootPart.CFrame = cf(character.char.HumanoidRootPart.CFrame.p) * ffa(v3(0, 1, 0), atan2(cam.CFrame.lookVector.x, cam.CFrame.lookVector.z) + pi)
  1738.  
  1739. local joints = {cf(0, 1.5, 0); cf(-.5, -2, 0); cf(.5, -2, 0); cf(-1.5, 0, 0); cf(1.5, 0, 0)};
  1740.  
  1741. local baseCF = character.char.HumanoidRootPart.CFrame
  1742. local leftArmShoulder = v3(-1.5, 0, 0)
  1743. local rightArmShoulder = v3(1.5, .3, 0)
  1744.  
  1745. joints[4] = cf(leftArmShoulder, baseCF:toObjectSpace(weapon.base.CFrame).p) * cf(0, 0, -1) * ffa(v3(1, 0, 0), math.pi/2)
  1746. joints[5] = cf(rightArmShoulder, baseCF:toObjectSpace(weapon.base.CFrame).p) * cf(0, 0, -1) * ffa(v3(1, 0, 0), math.pi/2)
  1747.  
  1748. network:bounce("joints", joints)
  1749. network:bounce("position", character.char.HumanoidRootPart:GetRenderCFrame().p)
  1750. network:bounce("rotation", v2(rotation.Y, rotation.x))
  1751. end
  1752.  
  1753.  
  1754. rs:BindToRenderStep("CameraUpdate", 200, update)
  1755. end
  1756.  
  1757.  
  1758.  
  1759.  
  1760.  
  1761.  
  1762.  
  1763.  
  1764.  
  1765.  
  1766.  
  1767.  
  1768.  
  1769.  
  1770.  
  1771.  
  1772.  
  1773.  
  1774.  
  1775. do -- UI Scope
  1776. local playerGui = wfc(player, "PlayerGui")
  1777. local screen = wfc(playerGui, "Screen")
  1778.  
  1779. do -- Crosshair
  1780. ui.crossAmounts = {
  1781. sprint = .4;
  1782. walk = .3;
  1783. idle = .25;
  1784. crouch = .2;
  1785. prone = .17;
  1786. aim = 0;
  1787. }
  1788. ui.crossSpring = spring.new(ui.crossAmounts.idle, 1, 17)
  1789. local crosshair = wfc(screen, "Crosshair")
  1790.  
  1791.  
  1792. local function update()
  1793. if not weapon.shown then
  1794. crosshair.Visible = false
  1795. else
  1796. local kick = weapon.rKickSpring.p
  1797. local rot = weapon.rRotSpring.p
  1798. local crossSize = ui.crossSpring.p
  1799.  
  1800. if ui.crossSpring.t == 0 then
  1801. rot = rot * 0
  1802. kick = kick * 0
  1803. end
  1804.  
  1805. crossSize = crossSize + rot.x/12
  1806. local sizeY = cam.ViewportSize.y * crossSize
  1807. crosshair.Rotation = deg(rot.y)/16*.7
  1808. crosshair.Size = UDim2.new(0, sizeY, crossSize, 0)
  1809. crosshair.Position = UDim2.new(.5, -sizeY/2, .5 - crossSize/2, 0)
  1810.  
  1811. local transparency = 1 - clamp(crossSize/.1, 0, 1)
  1812. for _, v in pairs(crosshair:GetChildren()) do
  1813. v.Transparency = transparency
  1814. end
  1815. end
  1816. end
  1817.  
  1818.  
  1819. rs:BindToRenderStep("Crosshair Update", 280, update)
  1820. end
  1821.  
  1822.  
  1823.  
  1824.  
  1825.  
  1826.  
  1827. do -- Hit marker
  1828. local marker = wfc(screen, "Hitmarker")
  1829. local endTime = tick()
  1830.  
  1831.  
  1832. function ui:Hit()
  1833. endTime = tick() + .07
  1834.  
  1835. local sound = new("Sound", screen)
  1836. sound.SoundId = "rbxassetid://131864673"
  1837. sound:Play()
  1838. sound.Volume = 1
  1839. delay(sound.TimeLength, function()
  1840. sound:Destroy()
  1841. end)
  1842. end
  1843.  
  1844.  
  1845. local function update()
  1846. if tick() > endTime then
  1847. marker.Visible = false
  1848. else
  1849. marker.Visible = true
  1850. end
  1851. end
  1852.  
  1853. rs:BindToRenderStep("Marker Update", 280, update)
  1854. end
  1855.  
  1856.  
  1857.  
  1858.  
  1859.  
  1860.  
  1861. end
  1862.  
  1863.  
  1864.  
  1865.  
  1866.  
  1867.  
  1868.  
  1869.  
  1870.  
  1871.  
  1872.  
  1873.  
  1874.  
  1875.  
  1876.  
  1877.  
  1878.  
  1879.  
  1880.  
  1881.  
  1882.  
  1883.  
  1884.  
  1885. do -- Input Scope
  1886. input.delta = v2()
  1887. input.lastDelta = v2()
  1888. input.direction = v2()
  1889. input.left = false
  1890. input.right = false
  1891. input.keysDown = {}
  1892.  
  1893.  
  1894. local inputEvents = {
  1895. mouse = {
  1896. left = {
  1897. down = function()
  1898. input.left = true
  1899. weapon.startFiring()
  1900. end;
  1901.  
  1902. up = function()
  1903. input.left = false
  1904. weapon.stopFiring()
  1905. end;
  1906. };
  1907.  
  1908. right = {
  1909. down = function()
  1910. input.right = true
  1911. weapon:SetState("aim")
  1912. end;
  1913.  
  1914. up = function()
  1915. input.right = false
  1916. weapon:SetState("idle")
  1917. end;
  1918. };
  1919.  
  1920. moved = function(inp)
  1921. input.delta = v2(inp.Delta.x, inp.Delta.y)
  1922. end;
  1923.  
  1924. wheel = function(inp)
  1925. weapon:Scroll(inp.Position.z)
  1926. end;
  1927. };
  1928.  
  1929. leftshift = {
  1930. down = function()
  1931. character:SetStance("stand")
  1932. weapon:SetState("sprint")
  1933. end;
  1934.  
  1935. up = function()
  1936. weapon:SetState("idle")
  1937. end;
  1938. };
  1939.  
  1940. space = {
  1941. down = function()
  1942. character:Jump()
  1943. end
  1944. };
  1945.  
  1946.  
  1947. c = {
  1948. down = function()
  1949. character:SetStance("crouch")
  1950. end;
  1951. };
  1952. }
  1953.  
  1954.  
  1955. uis.InputBegan:connect(function(inp, gpe)
  1956. if gpe then return end
  1957.  
  1958. local type = inp.UserInputType.Name
  1959. local key = inp.KeyCode.Name:lower()
  1960.  
  1961. if type == "Keyboard" then
  1962. if key == "unknown" then return end
  1963.  
  1964. input.keysDown[key] = true
  1965.  
  1966. if key == "leftcontrol" then
  1967. key = "c"
  1968. end
  1969.  
  1970. if inputEvents[key] and inputEvents[key].down then
  1971. inputEvents[key].down()
  1972. end
  1973. elseif type == "MouseButton1" then
  1974. inputEvents.mouse.left.down()
  1975. elseif type == "MouseButton2" then
  1976. inputEvents.mouse.right.down()
  1977. end
  1978. end)
  1979.  
  1980.  
  1981.  
  1982. uis.InputEnded:connect(function(inp, gpe)
  1983. if gpe then return end
  1984.  
  1985. local type = inp.UserInputType.Name
  1986. local key = inp.KeyCode.Name:lower()
  1987.  
  1988. if type == "Keyboard" then
  1989. if key == "unknown" then return end
  1990.  
  1991. input.keysDown[key] = false
  1992.  
  1993. if key == "leftcontrol" then
  1994. key = "c"
  1995. end
  1996.  
  1997. if inputEvents[key] and inputEvents[key].up then
  1998. inputEvents[key].up()
  1999. end
  2000. elseif type == "MouseButton1" then
  2001. inputEvents.mouse.left.up()
  2002. elseif type == "MouseButton2" then
  2003. inputEvents.mouse.right.up()
  2004. end
  2005. end)
  2006.  
  2007.  
  2008.  
  2009. uis.InputChanged:connect(function(inp, gpe)
  2010. if gpe then return end
  2011.  
  2012. local type = inp.UserInputType.Name
  2013.  
  2014. if type == "MouseMovement" then
  2015. inputEvents.mouse.moved(inp)
  2016. elseif type == "MouseWheel" then
  2017. inputEvents.mouse.wheel(inp)
  2018. end
  2019. end)
  2020. end
  2021.  
  2022.  
  2023.  
  2024.  
  2025.  
  2026.  
  2027.  
  2028.  
  2029.  
  2030.  
  2031.  
  2032.  
  2033.  
  2034.  
  2035.  
  2036.  
  2037.  
  2038.  
  2039.  
  2040.  
  2041.  
  2042.  
  2043.  
  2044.  
  2045. do -- Characters Module
  2046. local roboMeta = {__index = robo}
  2047. local roboWorkspace = Instance.new("Folder")
  2048. roboWorkspace.Name = "Characters"
  2049. roboWorkspace.Parent = workspace
  2050.  
  2051. local gunWorkspace = Instance.new("Folder")
  2052. gunWorkspace.Name = "Guns"
  2053. gunWorkspace.Parent = cam
  2054.  
  2055. robo.list = {}
  2056.  
  2057. --
  2058. local easeSpeed = .2
  2059. local breath = 0
  2060. local lastUpdate = tick()
  2061. --
  2062.  
  2063. -- player.Chatted:connect(function(msg)
  2064. -- if msg:sub(1, 5) == "/ease" then
  2065. -- if tonumber(msg:sub(7, string.len(msg)))then
  2066. -- easeSpeed = tonumber(msg:sub(7, string.len(msg)))
  2067. -- end
  2068. -- end
  2069. -- end)
  2070.  
  2071. local lowPolyModels = game.ReplicatedStorage["Weapon Models"]
  2072. local weaponData = game.ReplicatedStorage.Weapons
  2073.  
  2074.  
  2075. local function GunSetup(name) -- Initialize weapons
  2076. local t = {}
  2077. t.Data = require(weaponData[name])
  2078. t.Model = lowPolyModels[name]:Clone()
  2079.  
  2080. t.childrens = {}
  2081. t.offsets = {}
  2082. t.count = 0
  2083.  
  2084. t.base = t.Model.Base
  2085.  
  2086. local baseCF = t.base.CFrame
  2087.  
  2088. local function RecrusiveWeld(mod)
  2089. for _,x in ipairs(mod:GetChildren())do
  2090. if x:IsA("BasePart")then
  2091. if x ~= t.Base then
  2092. table.insert(t.childrens, x)
  2093. table.insert(t.offsets, baseCF:inverse() * x.CFrame)
  2094. end
  2095. else
  2096. RecrusiveWeld(x)
  2097. end
  2098. end
  2099. end
  2100. RecrusiveWeld(t.Model)
  2101.  
  2102. t.count = #t.childrens
  2103.  
  2104. return t
  2105. end
  2106.  
  2107.  
  2108. function robo.new(player, char, status) -- replicates the other players since it is client sided
  2109. local rootCF = wfc(char, "HumanoidRootPart"):GetRenderCFrame()
  2110.  
  2111. local robot = game.ReplicatedStorage.ReplicatedCharacter:Clone()
  2112. robot.Name = player.Name
  2113. robot.Parent = roboWorkspace
  2114.  
  2115. for _,x in ipairs(robot:GetChildren())do
  2116. x.BrickColor = player.TeamColor
  2117. end
  2118. robot.BrickColor = player.TeamColor
  2119.  
  2120. local stats = ffc(player, "Stats")
  2121. local status = ffc(player, "Status")
  2122.  
  2123. local primary = GunSetup(stats.Primary.Gun.Value);
  2124. local secondary = GunSetup(stats.Secondary.Gun.Value);
  2125.  
  2126. local self = setmetatable({
  2127. player = player;
  2128. stats = stats;
  2129. status = status;
  2130. current = nil;
  2131. guns = {primary, secondary};
  2132. data = network.players[player.Name];
  2133. char = robot;
  2134. body = {ffc(robot, "Head"), ffc(robot, "Left Leg"), ffc(robot, "Right Leg"), ffc(robot, "Left Arm"), ffc(robot, "Right Arm")};
  2135. cf = rootCF;
  2136. position = rootCF.p;
  2137. lastPosition = rootCF.p;
  2138. rotation = 0;
  2139. distance = 0;
  2140. view = 0;
  2141. joints = {cf(0, 1.5, 0); cf(-.5, -2, 0); cf(.5, -2, 0); cf(-1.5, 0, 0); cf(1.5, 0, 0)}; -- neck, lhip, rhip, lshoulder, rshoulder
  2142. }, roboMeta)
  2143.  
  2144. Indicator.new(player, status, ffc(robot, "Head"))
  2145.  
  2146. char:Destroy()
  2147. player.Character = nil
  2148.  
  2149. self:equip()
  2150.  
  2151. table.insert(robo.list, self)
  2152. return self
  2153. end
  2154.  
  2155.  
  2156. do -- Meta part
  2157. function robo:equip()
  2158. if self.current then
  2159. self.current.Model.Parent = nil
  2160. self.current = nil
  2161. end
  2162. local equipped = self.status.Equipped.Value
  2163.  
  2164. local new = self.guns[equipped] or self.guns[1]
  2165. new.Model.Parent = gunWorkspace
  2166.  
  2167. self.current = new
  2168. end
  2169.  
  2170.  
  2171. function robo:update(dt)
  2172. if self.dead then return end
  2173. local char = self.char
  2174. local body = self.body
  2175.  
  2176. local data = self.data
  2177. if not data then
  2178. data = network.players[player.Name]
  2179. if not data then
  2180. return
  2181. else
  2182. self.data = data
  2183. end
  2184. end
  2185.  
  2186. local pos = ease(self.position, data.position, easeSpeed)
  2187. local rot = ease(self.rotation, data.rotation.Y, easeSpeed)--self.rotation + (data.rotation.Y - self.rotation) * easeSpeed
  2188. local view = ease(self.view, data.rotation.X, easeSpeed)
  2189. local cframe = cf(pos) * ffa(v3(0, 1, 0), rot)
  2190. local realJoints = self.joints
  2191. local dataJoints = data.joints
  2192.  
  2193. self.cf = cframe
  2194. self.position = pos
  2195. self.rotation = rot
  2196. self.view = view
  2197.  
  2198. do
  2199. local d = self.distance
  2200. local p = self.position
  2201. local l = self.lastPosition
  2202. local x1, z1 = p.x, p.z
  2203. local x2, z2 = l.x, l.z
  2204. local x, z = (x2 - x1), (z2 - z1)
  2205.  
  2206. self.distance = d + (x*x + z*z)^.5 * .9
  2207. end
  2208.  
  2209. local d = self.distance * .9
  2210. local bobY = -abs(sin(d))/5
  2211. local bodyOffset = cf(0, breath + bobY/3, 0)
  2212.  
  2213. local velocityTilt
  2214. local velocity do
  2215. local v = self.position - self.lastPosition
  2216. local x, z = v.x, v.z
  2217. local mag = (x*x + z*z)^.5
  2218.  
  2219. if not (mag > 0) then
  2220. velocity = v3()
  2221. velocityTilt = cf()
  2222. else
  2223. local charCf = char.CFrame
  2224. local unit = v/mag
  2225. velocity = unit * (mag/dt)
  2226. mag = mag
  2227. local lvelo = charCf:vectorToObjectSpace(velocity)
  2228. --(charCf - charCf.p):inverse() * velocity
  2229. velocityTilt = ffa(v3(1, 0, 0), lvelo.z * mag) * ffa(v3(0, 0, 1), -lvelo.x * mag)
  2230. end
  2231. end
  2232.  
  2233.  
  2234. self.lastPosition = self.position
  2235.  
  2236.  
  2237. for i = 1, 5 do
  2238. realJoints[i] = realJoints[i]:lerp(dataJoints[i], easeSpeed)
  2239. body[i].CFrame = cframe * velocityTilt * realJoints[i] * bodyOffset
  2240. end
  2241.  
  2242. char.CFrame = cframe * velocityTilt * bodyOffset
  2243.  
  2244.  
  2245. if not self.current then return end
  2246.  
  2247. local gunCF = body[1].CFrame * ffa(v3(1, 0, 0), view) * self.current.Data.idle[1] * cf(cos(d)/4, bobY, 0)
  2248. local gun = self.current
  2249.  
  2250. local childrens = gun.childrens
  2251. local offsets = gun.offsets
  2252.  
  2253. gun.base.CFrame = gunCF
  2254. for i = 1, gun.count do
  2255. childrens[i].CFrame = gunCF * offsets[i]
  2256. end
  2257. end
  2258.  
  2259. function robo:die()
  2260. self.dead = true
  2261. local ragdoll = Ragdoll.new(self.char)
  2262. local dir = ragdoll.CFrame.lookVector
  2263.  
  2264. local killer = ffc(self.status.Health, "Killer")
  2265. if killer then
  2266. local pos
  2267. if game.Players.LocalPlayer.Name == killer.Name then
  2268. local plr = game.Players.LocalPlayer
  2269. if plr.Character and plr.Character:FindFirstChild("HumanoidRootPart")then
  2270. pos = plr.Character.HumanoidRootPart.Position
  2271. end
  2272. else
  2273. if ffc(roboWorkspace, killer.Name)then
  2274. pos = roboWorkspace[killer.Name].Position
  2275. end
  2276. end
  2277.  
  2278. if pos then
  2279. dir = CFrame.new(pos, ragdoll.Position).lookVector
  2280. end
  2281. end
  2282.  
  2283. if dir then
  2284. ragdoll.Velocity = dir * 30
  2285. end
  2286.  
  2287. self:remove()
  2288. end
  2289.  
  2290.  
  2291. function robo:remove()
  2292. self.char:Destroy()
  2293. for _,x in ipairs(self.guns)do
  2294. x.Model:Destroy()
  2295. end
  2296. for i, r in ipairs(robo.list) do
  2297. if r == self then
  2298. table.remove(robo.list, i)
  2299. end
  2300. end
  2301. end
  2302. end
  2303.  
  2304.  
  2305. function robo.step()
  2306. local t = tick()
  2307. local dt = t - lastUpdate
  2308.  
  2309. breath = cos(t)/8 - .12
  2310.  
  2311. for _, client in next, robo.list do
  2312. client:update(dt)
  2313. end
  2314. end
  2315.  
  2316.  
  2317. function robo.find(player)
  2318. for _, self in next, robo.list do
  2319. if self.player == player then
  2320. return self
  2321. end
  2322. end
  2323. end
  2324.  
  2325.  
  2326. local function playerAdded(plr)
  2327.  
  2328. local status = wfc(plr, "Status")
  2329. local health = wfc(status, "Health")
  2330.  
  2331. local robot = nil
  2332. plr.CharacterAdded:connect(function(c)
  2333. wait(.1)
  2334. if robot then
  2335. robot:remove()
  2336. end
  2337. robot = robo.new(plr, c, status)
  2338. end)
  2339. if plr.Character then
  2340. robot = robo.new(plr, plr.Character, status)
  2341. end
  2342.  
  2343. health.Changed:connect(function()
  2344. if health.Value <= 0 then
  2345. if robot then
  2346. robot:die()
  2347. end
  2348. end
  2349. end)
  2350. end
  2351.  
  2352.  
  2353. local function playerRemoving(plr)
  2354. local robot = robo.find(plr)
  2355. if robot then
  2356. robot:remove()
  2357. end
  2358. end
  2359.  
  2360.  
  2361. game.Players.PlayerAdded:connect(playerAdded)
  2362. game.Players.PlayerRemoving:connect(playerRemoving)
  2363. for _, plr in ipairs(game.Players:GetPlayers())do
  2364. if plr ~= player then
  2365. playerAdded(plr)
  2366. end
  2367. end
  2368.  
  2369.  
  2370. rs:BindToRenderStep("Characters", 2000, robo.step)
  2371. end
  2372.  
  2373.  
  2374.  
  2375.  
  2376.  
  2377.  
  2378.  
  2379.  
  2380. weapon:SetState("idle")
  2381.  
  2382.  
  2383. if player.Name == "BloxyFists" or player.Name == "Player1" then
  2384. player.Chatted:connect(function(msg)
  2385. if msg:sub(1, 5) == "/tick" then
  2386. if tonumber(msg:sub(7, string.len(msg)))then
  2387. tick:SetSpeed(tonumber(msg:sub(6, 10)))
  2388. end
  2389. end
  2390. end)
  2391. end
  2392.  
  2393.  
  2394.  
  2395. tick:SetSpeed(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement