GUI/Scope
From TDN
|
Introduction
This little scripting guide will make use of a keyboard command to turn on an off a little section of the hud to allow for the simulation of binoculars or other types of scopes. While this is a specific style of game function, you could look into switching between GUI files under the same type of instructions below.
Overview
Change the Zoom function to the following; this has been setup to turn off all the GUI content from the SDK FPS kit, while leaving the chat hud.
Basic Zoom
Looking in ~/client/scripts/default.bind.cs you will find moveMap.bind(keyboard, e, toggleZoom); which is maped to the toggleZoom function. This sets the field of view from 90 to 45, effectively zooming in. You will need to place the binoculars image in your GUI folder, and then add it to your playGUI.gui. Like so:
new GuiBitmapCtrl(PlayerZoom) {
Profile = "GuiDefaultProfile";
HorizSizing = "center";
VertSizing = "center";
position = "0 0";
Extent = "1040 768";
MinExtent = "8 2";
Visible = "0";
bitmap = "~/data/gui/hud/bino.png";
wrap = "0";
};
The next step, will be to expand the toggleZoom function to the following, so open your ~/client/scripts/default.bind.cs and replace the function. You will need to name your GUI objects according to this script, such as the healthbar, etc.
//------------------------------------------------------------------------------
// Zoom and FOV functions
//------------------------------------------------------------------------------
if($Pref::player::CurrentFOV $= "")
$Pref::player::CurrentFOV = 45;
function setZoomFOV(%val)
{
if(%val)
toggleZoomFOV();
}
function toggleZoom( %val )
{
if ($firstPerson == 1) // --> no zoom when 3rd person
{
if ( %val )
{
$ZoomOn = true;
setFov( $Pref::player::CurrentFOV );
PlayerZoom.Visible = 1; // show crosshair for zoom
Crosshair.Visible = 0; // make normal crosshair invisible
CenterPrintText.Visible = 0;
BottomPrintText.Visible = 0;
HealthBar.Visible = 0;
HealthGui.Visible = 0;
EnergyBar.Visible = 0;
MainChatHud.Visible = 0;
}
else
{
$ZoomOn = false;
setFov( $Pref::player::DefaultFov );
PlayerZoom.Visible = 0; // make zoomcrosshair invisible
Crosshair.Visible = 1;
CenterPrintText.Visible = 1;
BottomPrintText.Visible = 1;
HealthBar.Visible = 1;
HealthGui.Visible = 1;
EnergyBar.Visible = 1;
MainChatHud.Visible = 1;
}
}
}
moveMap.bind(keyboard, r, setZoomFOV);
moveMap.bind(keyboard, e, toggleZoom);
The outcome of this is that your GUI elements will be turned off, and your 'bino' image will be visible, simulating this scope effect. You need to create various art to create the simulation of a sight, but this would be the beginning.
Sniper and Binoculars
If you wish to get a Sniper zoom and a pair of binoculars actively, yet if you press one or the other while in a set mode, you will then switch to the other mode. The following functions sets out to do this, just replace them in your ~/client/scripts/default.bind.cs (Curretly the HUD names do not match the above, so check these):
function toggleFirstPerson(%val) // Makes sure that you can zoom in third person
{
if (%val)
{
$firstPerson = !$firstPerson;
if ($firstPerson)
{
if ($ZoomOn)
{
setFov($Pref::player::CurrentFov);
if ($BinocularZoom)
BinocularsHUD.visible = true;
if ($SniperZoom)
ZoomReticleHUD.visible = true;
}
else
{
ReticleHUD.visible = true;
setFov($Pref::player::DefaultFov);
}
}
else
{
ReticleHUD.visible = false;
ZoomReticleHUD.visible = false;
BinocularsHUD.visible = false;
setFov($Pref::player::DefaultFov);
}
}
}
function toggleZoom( %val )
{
if ( %val )
{
if ($BinocularZoom != true)
{
$ZoomOn = true;
$BinocularZoom = false;
$SniperZoom = true;
ReticleHUD.visible = 0;
BinocularsHUD.visible = 0;
ZoomReticleHUD.visible = 1;
setFov( $Pref::player::CurrentFOV );
}
}
else
{
if ($SniperZoom == true)
{
$ZoomOn = false;
$BinocularZoom = false;
$SniperZoom = false;
ZoomReticleHUD.visible = 0;
BinocularsHUD.visible = 0;
ReticleHUD.visible = 1;
setFov( $Pref::player::DefaultFov );
}
}
}
function toggleBinoculars( %val )
{
if ( %val )
{
if ($SniperZoom != true)
{
$ZoomOn = true;
$SniperZoom = false;
$BinocularZoom = true;
ReticleHUD.visible = 0;
ZoomReticleHUD.visible = 0;
BinocularsHUD.visible = 1;
setFov( $Pref::player::CurrentFOV );
}
}
else
{
if ($BinocularZoom == true)
{
$ZoomOn = false;
$SniperZoom = false;
$BinocularZoom = false;
BinocularsHUD.visible = 0;
ZoomReticleHUD.visible = 0;
ReticleHUD.visible = 1;
setFov( $Pref::player::DefaultFov );
}
}
}
moveMap.bind(keyboard, r, setZoomFOV);
moveMap.bind(keyboard, e, toggleZoom);
moveMap.bind(keyboard, b, toggleBinoculars);
Make sure you set the new keys in ~/client/config.cs to activate all the new keys you haven't added (ie. R and B).
Resources
Topic: Scoped crosshair for the zoom key / help needed
Categories: TGE | GUI | Tutorial



