Making a zoom function for you SWEP Difficulty: Intermediate |
| Category: Gmod > Other/Misc | Author(s): wowzorz |

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 |
| Added: 10 months ago | Tags: swep, zoom, wowzorz, wowzorz1leeroy, ownage, pwnage, coolness, gmod |
Provide constructive feedback.
What is "constructive"?You cannot post yet!Get involved on FPSB by posting your thoughts. Give authors your feedback to help them develop.
To post in this submission
register or login.