• Zooming Function
    3 replies, posted
Hello everyone, Im using a basic third person script: [CODE]if ( CLIENT ) then hook.Add( "ShouldDrawLocalPlayer", "ThirdPersonDrawPlayer", function() if LocalPlayer():Alive() then return true end end ) hook.Add( "CalcView", "ThirdPersonView", function( ply, pos, angles, fov ) if ply:Alive() then local view = {} view.origin = pos - ( angles:Forward() * zoom ) + ( angles:Right() * 4 ) + ( angles:Up() * 1 ) view.angles = ply:EyeAngles() + Angle( 1, 1, 0 ) view.fov = fov return GAMEMODE:CalcView( ply, view.origin, view.angles, view.fov ) end end ) end[/CODE] and Im trying to simulate zooming with: [CODE]hook.Add("Think", "zooming", function() local scrollDown = input.IsMouseDown( MOUSE_WHEEL_DOWN ) local scrollUp = input.IsMouseDown( MOUSE_WHEEL_UP ) zoom = 100 if scrollDown then zoom = ( zoom + 5 ) elseif scrollUp then zoom = ( zoom - 5 ) end end)[/CODE] What am I missing? Thanks in advance.
I think you can't put "zoom = 100" into the think hook because it would put it back to 100 every second its called.
[QUOTE=soliv;48618778]I think you can't put "zoom = 100" into the think hook because it would put it back to 100 every second its called.[/QUOTE] That is a problem with the script, but it is not the main reason this is not working. From my testing, scrollDown and scrollUp are never true. I initially thought that maybe a think hook just didn't work with inputs, but then I replaced the scrolldown with the k key and it worked. For some reason detecting whether the scroll wheel is being scrolled isn't possible or very hard, at least with the method you are using. I think the best way to accomplish what you want is to check if the binds invprev and invnext are pressed. Although this will only use the scrollwheel for those who have the scrollwheel bound to invprev and invnext, it will allow most people to use the scrollwheel to zoom and it's better than having to use some other keys. Another problem with this is the fact that you will constantly be scrolling through weapons, but your implementation would have done the same thing. Here is the code: [CODE]if ( CLIENT ) then local zoom = 100 hook.Add( "ShouldDrawLocalPlayer", "ThirdPersonDrawPlayer", function() if LocalPlayer():Alive() then return true end end ) hook.Add( "CalcView", "ThirdPersonView", function( ply, pos, angles, fov ) if ply:Alive() then local view = {} view.origin = pos - ( angles:Forward() * zoom ) + ( angles:Right() * 4 ) + ( angles:Up() * 1 ) view.angles = ply:EyeAngles() + Angle( 1, 1, 0 ) view.fov = fov return GAMEMODE:CalcView( ply, view.origin, view.angles, view.fov ) end end ) hook.Add("PlayerBindPress", "zooming", function(ply, bind, pressed) if not pressed then return end if string.find(bind, "invnext") then zoom = ( zoom + 5 ) return false elseif string.find(bind, "invprev") then zoom = ( zoom - 5 ) return false end end ) end[/CODE] You can return true in the bind presses if you want to prevent them from switching weapons with the scroll wheel.
[QUOTE=roastchicken;48619999]That is a problem with the script, but it is not the main reason this is not working. From my testing, scrollDown and scrollUp are never true. I initially thought that maybe a think hook just didn't work with inputs, but then I replaced the scrolldown with the k key and it worked. For some reason detecting whether the scroll wheel is being scrolled isn't possible or very hard, at least with the method you are using. I think the best way to accomplish what you want is to check if the binds invprev and invnext are pressed. Although this will only use the scrollwheel for those who have the scrollwheel bound to invprev and invnext, it will allow most people to use the scrollwheel to zoom and it's better than having to use some other keys. Another problem with this is the fact that you will constantly be scrolling through weapons, but your implementation would have done the same thing. Here is the code: [CODE]if ( CLIENT ) then local zoom = 100 hook.Add( "ShouldDrawLocalPlayer", "ThirdPersonDrawPlayer", function() if LocalPlayer():Alive() then return true end end ) hook.Add( "CalcView", "ThirdPersonView", function( ply, pos, angles, fov ) if ply:Alive() then local view = {} view.origin = pos - ( angles:Forward() * zoom ) + ( angles:Right() * 4 ) + ( angles:Up() * 1 ) view.angles = ply:EyeAngles() + Angle( 1, 1, 0 ) view.fov = fov return GAMEMODE:CalcView( ply, view.origin, view.angles, view.fov ) end end ) hook.Add("PlayerBindPress", "zooming", function(ply, bind, pressed) if not pressed then return end if string.find(bind, "invnext") then zoom = ( zoom + 5 ) return false elseif string.find(bind, "invprev") then zoom = ( zoom - 5 ) return false end end ) end[/CODE] You can return true in the bind presses if you want to prevent them from switching weapons with the scroll wheel.[/QUOTE] Thanks so much! Luckily for me, I don't have a weapons in my gamemode (Or at least the default weapon selection that is). Worked like a charm, thanks again.
Sorry, you need to Log In to post a reply to this thread.