Ads keep us online. Without them, we wouldn't exist. We don't have paywalls or sell mods - we never will. But every month we have large bills and running ads is our only way to cover them. Please consider unblocking us. Thank you from GameBanana <3

Making a zoom function for you SWEP - A Tutorial for Garry's Mod

Programs needed --------------------- Garry's Mod 10 NotePad or NotePad++ --------------------- In this tutorial you will learn how to make your SWEP have a zoom function for the right click. I also recommend that you have made or practiced making simple SWEPs before trying this. Also this tutorial just explains how to add a zoom to an existing SWEP. --------------------- Step 1. You are going to want to copy this into NotePad or NP++ function SWEP:SecondaryAttack() if(Zoom == 0) then if(SERVER) then self.Owner:SetFOV( 45, 0 ) end Zoom = 1 else if(Zoom == 1) then if(SERVER) then self.Owner:SetFOV( 25, 0 ) end Zoom = 2 else if(SERVER) then self.Owner:SetFOV( 0, 0 ) end Zoom = 0 end end end --------------------- Step 2. Then right under that put this. function SWEP:Holster() self.Owner:SetFOV( 0, 0 ) ScopeLevel = 0 return true end --------------------- Step 3. you also have to put this in your code, but its doesnt amtter where it is as long as its not in a function. Zoom = 0 --------------------- Now let me explaing what this all does. for the right click, which is the secondary function its asking what level of zoom the SWEP is on, after it finds out it changes it to +1, like if its set to 0 then its changed to 1, if its 1 its changed to 2, but for 2 its changed back to 0. The function Holster is telling the SWEP that when its put away make the players view correct, and make the zoom level 0. Full Code: Zoom = 0 function SWEP:SecondaryAttack() if(Zoom == 0) then if(SERVER) then self.Owner:SetFOV( 45, 0 ) end Zoom = 1 else if(Zoom == 1) then if(SERVER) then self.Owner:SetFOV( 25, 0 ) end Zoom = 2 else if(SERVER) then self.Owner:SetFOV( 0, 0 ) end Zoom = 0 end end end function SWEP:Holster() self.Owner:SetFOV( 0, 0 ) ScopeLevel = 0 return true end --------------------- Any questions send me a PM
  • dalton0419 avatar
    dalton0419 Joined 13y ago
    Offline
    13y
    Improvements: You should make all your tutorials step by step so we are actually learning about making sweps instead of just copying them.
    Bananite
    URL to post:
  • dalton0419 avatar
    dalton0419 Joined 13y ago
    Offline
    13y
    Improvements: You should make all your tutorials step by step so we are actually learning about making sweps instead of just copying them.
    Bananite
    URL to post:
  • AxoNinja avatar
    AxoNinja Joined 14y ago
    Offline
    201 points Ranked 65,850th
    14y
    Awsome tutorial but it would have been better with html. 10/10 though. it helped me alot
    http://nitrohost.clanteam.com/ avatar
    Mantra
    http://nitrohost.clanteam.com/
    URL to post: