Search
Username:
Password:
Register or Reset Password
Remove the ads!
  
Making a zoom function for you SWEP
Difficulty: Intermediate
Category: Gmod > Other/MiscAuthor(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 agoTags: swep, zoom, wowzorz, wowzorz1leeroy, ownage, pwnage, coolness, gmod
Feedback (1)
AxoNinja .
http://nitrohost.clanteam.com/phpBB2/Y2M
Posted 10 months ago
Awsome tutorial but it would have been better with html. 10/10 though. it helped me alot
Add Feedback
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.
Assessment
The community's verdict.
User Rating [+]
10/10
bScore
10.0/10
You cannot assess yet!
Moderating FPSB is in your hands - when you assess a submission your vote determines its success or failure.

To vote on this submission register or login.
Stamps
This Tutorial in a nutshell...
Handy & Useful
You cannot stamp yet!
Stamps let you apply characteristics to submissions to help others understand them.

To stamp this submission register or login.

Added by...
Wowzorz .
I'm done.
Ranked 3106th ( 7) with 513 points.

[+] Donate
Related Tutorials