Game Development Community

Zooming

by Van der planken Roel · in Technical Issues · 10/16/2002 (1:40 pm) · 5 replies

hello I need some help in scripting a zoom function
my team manage it when we put the zoom key (e) we get a croshair change to out scope and if we loose the key it will be normal and not zoomed in...
the code looks like this

function toggleZoom( %val, %weaponName )
{
if ($firstPerson == 1) // --> no zoom when 3rd person
{
if ( %val )
{
if(%weaponName $= "HwsrImage")
{
$ZoomOn = true;
setFov( $Pref::player::CurrentFOV );
zoomcrosshair.Visible = 1; // show crosshair for zoom
playerReticle.Visible = 0; // make normal crosshair invisible
else
{
$ZoomOn = false;
setFov( $Pref::player::DefaultFov );
zoomcrosshair.Visible = 0; // make zoomcrosshair invisible
playerReticle.Visible = 1; // show normal crosshair
}
else
{
$ZoomOn = false;
setFov( $Pref::player::DefaultFov );
zoomcrosshair.Visible = 0; // make zoomcrosshair invisible
playerReticle.Visible = 1; // show normal crosshair
}
}
}
}


Now I know that I can not use %weaponName but it is just to ilustrate what I want.. I would that only my sniper rifles can zoom and all the rest has no zoom zo their will no zoom for the other weapons. how can I manage this..

another problem we have at this moment is the FOV. when you press e you zoom in when you loose you zoom out.. but it would be nice to have more zoom depths.. anyone that would love to help??

#1
10/16/2002 (2:38 pm)
This will test to see if the weapon you have is able to zoom based on the images datablock, if you want the gun to zoom you must put ' canZoom = true; ' in the guns image. If not then it wont zoom at all.

//------------------------------------------------------------------------------
// Zoom and FOV functions
//------------------------------------------------------------------------------

if($Pref::player::CurrentFOV $= "")
   $Pref::player::CurrentFOV = 45;

function setZoomFOV(%val)
{
   if(%val)
      toggleZoomFOV();
}

function serverCmdGetCurrentWeapon(%client)
{
      %player = %client.player;
      %weapon = %player.getMountedImage($WeaponSlot);
   
      if(%weapon)               // Testing to see if we are packing.
         if(%weapon.canZoom)    // Testing the image to see if we can zoom
            applyZoom();        // it is so we apply the zoom. If not we dont do anything.
}

function applyZoom()
{
   $ZoomOn = true;
   setFov( $Pref::player::CurrentFOV );
   zoomcrosshair.Visible = 1; // show crosshair for zoom.
   playerReticle.Visible = 0; // make normal crosshair invisible.
}
      
function toggleZoom( %val )
{
   if ( %val )
      commandToServer('GetCurrentWeapon');
   else
   {
      $ZoomOn = false;
      setFov( $Pref::player::DefaultFov );
      zoomcrosshair.Visible = 0; // make zoom crosshair invisible.
      playerReticle.Visible = 1; // show the normal one again.
   }
}

function toggleZoomFOV()
{
   if($pref::player::currentFOV == $pref::player::defaultFov / 2)
      $pref::player::currentFOV = $pref::player::defaultFov / 5;
   else
      $pref::player::currentFOV = $pref::player::currentFOV / 2;

   if($pref::player::currentFOV < 4)
      $pref::player::currentFOV = $pref::player::defaultFov / 2;

   if($ZoomOn)
      setFov( $pref::player::currentFOV );
}

moveMap.bind(keyboard, z, setZoomFOV);
moveMap.bind(keyboard, e, toggleZoom);
#2
10/17/2002 (6:58 am)
Tank you verry much
#3
10/17/2002 (2:33 pm)
Some changes to move the applyZoom off the server as where it was in the script would cause the server client to zoom not the client who pressed the zoom button
//------------------------------------------------------------------------------
// Zoom and FOV functions
//------------------------------------------------------------------------------

if($Pref::player::CurrentFOV $= "")
   $Pref::player::CurrentFOV = 45;

function setZoomFOV(%val)
{
   if(%val)
      toggleZoomFOV();
}

function serverCmdGetCurrentWeapon(%client)
{
      %player = %client.player;
      %weapon = %player.getMountedImage($WeaponSlot);
   
      if(%weapon)               // Testing to see if we are packing.
         if(%weapon.canZoom)    // Testing the image to see if we can zoom
            commandToClient('applyZoom');   // it is so we apply the zoom. If not we dont do anything.
}

function clientCmdapplyZoom()
{
   $ZoomOn = true;
   setFov( $Pref::player::CurrentFOV );
   zoomcrosshair.Visible = 1; // show crosshair for zoom.
   playerReticle.Visible = 0; // make normal crosshair invisible.
}
      
function toggleZoom( %val )
{
   if ( %val )
      commandToServer('GetCurrentWeapon');
   else
   {
      $ZoomOn = false;
      setFov( $Pref::player::DefaultFov );
      zoomcrosshair.Visible = 0; // make zoom crosshair invisible.
      playerReticle.Visible = 1; // show the normal one again.
   }
}

function toggleZoomFOV()
{
   if($pref::player::currentFOV == $pref::player::defaultFov / 2)
      $pref::player::currentFOV = $pref::player::defaultFov / 5;
   else
      $pref::player::currentFOV = $pref::player::currentFOV / 2;

   if($pref::player::currentFOV < 4)
      $pref::player::currentFOV = $pref::player::defaultFov / 2;

   if($ZoomOn)
      setFov( $pref::player::currentFOV );
}

moveMap.bind(keyboard, z, setZoomFOV);
moveMap.bind(keyboard, e, toggleZoom);
#4
10/17/2002 (6:41 pm)
Oops, thanks Harold.
#5
10/18/2002 (7:29 am)
tank you both...
you only made one mistake
function serverCmdGetCurrentWeapon(%client)
{
%player = %client.player;
%weapon = %player.getMountedImage($WeaponSlot);

if(%weapon) // Testing to see if we are packing.
if(%weapon.canZoom) // Testing the image to see if we can zoom
commandToClient(%client, 'applyZoom'); // it is so we apply the zoom. If not we dont do anything.
}

in the serverCmdGetCurrentWeapon(%Client)
the last line is commandToClient(%client, 'applyZoom');
you forgot the %client...

tank you all...