Guest User

Framework

a guest
Jan 2nd, 2020
9,906
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.18 KB | None | 0 0
  1. --[[
  2.    
  3.  ____                                                                       __        
  4. /\  _`\                                                                    /\ \        
  5. \ \ \L\_\ _ __     __       ___ ___       __    __  __  __    ___    _ __  \ \ \/'\    
  6.  \ \  _\//\`'__\ /'__`\   /' __` __`\   /'__`\ /\ \/\ \/\ \  / __`\ /\`'__\ \ \ , <    
  7.   \ \ \/ \ \ \/ /\ \L\.\_ /\ \/\ \/\ \ /\  __/ \ \ \_/ \_/ \/\ \L\ \\ \ \/   \ \ \\`\  
  8.    \ \_\  \ \_\ \ \__/.\_\\ \_\ \_\ \_\\ \____\ \ \___x___/'\ \____/ \ \_\    \ \_\ \_\
  9.     \/_/   \/_/  \/__/\/_/ \/_/\/_/\/_/ \/____/  \/__//__/   \/___/   \/_/     \/_/\/_/
  10.                                                                                        
  11.                                                                                        
  12.  
  13.     Written by sen_trix
  14.    
  15.    
  16.  
  17. Copyright <2020> <sen_trix>
  18.  
  19. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
  20.  
  21. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
  22.  
  23. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR      ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH  THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24.  
  25. --]]
  26.  
  27. local Player    = game.Players.LocalPlayer
  28. local Character
  29.  
  30. -- [[ Services ]] --
  31. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  32. local RunService        = game:GetService("RunService")
  33. local UserinputService  = game:GetService("UserInputService")
  34. local Camera            = workspace.CurrentCamera
  35.  
  36. local gun       = {
  37.     inventory   = {
  38.         "UMP-45"; -- Primary
  39.         "Deagle"; -- Secondary
  40.         "Knife";  -- Mele
  41.     };
  42.    
  43.     -- States just to tell what the framework is doing
  44.     states      = {
  45.         idle    = 1;
  46.         aiming  = 2;
  47.         reload  = 3;
  48.         shoot   = 4;
  49.         inspect = 5;
  50.     };
  51.    
  52.     animationTrack = {
  53.         idle = nil;
  54.         reload = nil;
  55.     };
  56.    
  57.     -- Weapons
  58.     weapon      = nil;
  59.     state       = nil;
  60.     module      = nil;
  61.    
  62.     -- CFrames
  63.     mainCF      = CFrame.new();
  64.     camCF       = CFrame.new();
  65. }
  66.  
  67. local keybind   = {
  68.     -- General keybinds that might need to be used
  69.     q = false;
  70.     e = false;
  71.    
  72.     mouse = {
  73.         mb1 = false; -- Left button
  74.         mb2 = false; -- Right button
  75.         mb3 = false; -- Scroll button
  76.     }
  77. }
  78.  
  79. local function onSpawn()
  80.     -- Load the first weapon in the inventory
  81.     loadWeapon(gun.inventory[1])
  82. end
  83.  
  84. local function update()
  85.     if not gun.weapon then coroutine.yield()    end
  86.    
  87.     gun.weapon:SetPrimaryPartCFrame(Camera.CFrame * gun.mainCF)
  88.    
  89.     -- [[ States ]] --
  90.     if (gun.state == gun.states.idle)then
  91.         gun.mainCF = gun.mainCF:lerp(gun.module.regularcf,.3)
  92.        
  93.         if not gun.animationTrack.idle.IsPlaying then
  94.             gun.animationTrack.idle:Play()
  95.         end
  96.     end
  97. end
  98.  
  99. function loadWeapon(weapon)
  100.     local Guns       = ReplicatedStorage:WaitForChild("Guns")
  101.     local GunModules = ReplicatedStorage:WaitForChild("GunModules")
  102.    
  103.     -- Assertation
  104.     assert(Guns[weapon], "Gun doesn't exist in ReplicatedStorage > Guns")
  105.     assert(GunModules[weapon], "Gun doesn't exist in ReplicatedStorage > GunModules")
  106.    
  107.     -- Update the weapon, state and module
  108.     gun.state = gun.states.idle
  109.     gun.weapon = Guns[weapon]:Clone()
  110.     gun.weapon.Parent = Camera
  111.     gun.module = require(GunModules[weapon])
  112.    
  113.     -- Load the animation Tracks
  114.     local GunHumanoid = gun.weapon:WaitForChild("Humanoid")
  115.     local animation   = Instance.new("Animation",script)
  116.    
  117.     animation.AnimationId = gun.module.idle
  118.     gun.animationTrack.idle = GunHumanoid:LoadAnimation(animation)
  119.    
  120.     animation:Destroy()
  121. end
  122.  
  123. RunService.RenderStepped:Connect(update)
  124. Player.CharacterAdded:Connect(onSpawn)
Advertisement
Add Comment
Please, Sign In to add comment