i made a dual render scope in the GUI editor

Author Topic: i made a dual render scope in the GUI editor  (Read 6258 times)

i know theres some sort of fov variable that forces your fov to whatever no matter how much you zoom in, but zooming in decreases your mouse speed as it would regularly

as for implementing it (the dual render) into code, it's a simple push and pop command so it's very easy to utilize


This is super cool so far. Interested to see how it progresses.

adjustable magnification



So far I've written a function that takes 4 arguments, allowing you to set the magnification, choose a scope overlay using an index number, and adjusting the render area that uses resolution. All I really want to do now is set it so that it doesn't squish and stretch at resolutions that aren't 16:9

Question: How do I make it so that opening a dialog doesn't freeze the player's aim and show a cursor lol?

what do you need a dialog window for?
I'd check what the speedometer/rearview mirror do if you're trying to display that without the cursor/display text without a cursor

I looked at speedometer, I can't find rear view mirror tbh
PlayGUI.add(DualRenderScope); does this:


canvas.pushDialog(DualRenderScope); works as expected:


calling PlayGUI.add(DualRenderScope); in the console after doing Canvas.pushDialog(DualRenderScope) and then Canvas.popDialog(DualRenderScope) produces intended results (able to move the mouse). Not sure what's wrong there.

This doesn't work either
Code: [Select]
canvas.pushDialog(DualRenderScope);
canvas.popDialog(DualRenderScope);
PlayGUI.add(DualRenderScope);

for some reason it's called zview, always forget that
https://blocklandglass.com/addons/rtb/view.php?id=1047

it uses
PlayGUI.add($zv);
like you were
potentially they added some settings?  this looks like it might do something with positioning
Code: [Select]
   horizSizing = "right";
   vertSizing = "bottom";
   position = getword(getres(),0)/4 SPC 0;
   extent = getword(getres(),0)/2 SPC getword(getres(),1)/5;

Yeah I was being silly, I just wasn't positioning the full GUI object only the bitmap and GameTSCtrl. I've got it working as intended now.

Here's what I've got so far, client side code is new to me, so I'd appreciate it if somebody could go through this and make sure there's nothing wrong with it or suggest improvements.

client.cs
Code: [Select]
// 1,2: 3.5, 2
// 3,4: 2.6, 1.5

$DRScopes_Version = 1;
$DRScopes_DefaultMouseSensitivity = $pref::Input::MouseSensitivity;
$Pref::DRScopesMouseSensitivityScale = 0.25;

function clientCmdDRScopes_renderDRScope(%fov, %bitmap, %renderW, %renderH)
{
// Delete and rebuild (Not sure how important this is)
if(isObject(DualRenderScope))
DualRenderScope.delete();
exec("./DualRenderScope.gui");

// Get and set the optic
%bitmapPath = "Add-Ons/Client_DualRenderScopes/DR_Optic" @ %bitmap @ ".png";
ScopeBitmap.setBitmap(%bitmapPath);

// Set magnification
ScopeRender.forceFOV = %fov;

// Calculate bitmap width based on the resolution height, should always be in 16:9 format
%bitmapH = getWord(getRes(), 1);
%bitmapW = (%bitmapH * 16) / 9;
ScopeBitmap.resize(0, 0, %bitmapW, %bitmapH);

// Set the size of the scope render area, adjusting for resoltuion
// This is usually done by defaults using values that I've set up per bitmap, but it can be overridden if required
if(%renderH $= "" || %renderW $= "")
{
switch(%bitmap)
{
case 1:
%renderW = 3.5;
%renderH = 2;
case 2:
%renderW = 3.5;
%renderH = 2;
case 3:
%renderW = 2.6;
%renderH = 1.5;
case 4:
%renderW = 2.6;
%renderH = 1.5;
default:
%renderW = 1;
%renderH = 1;
}
}

%H = mFloatLength(%bitmapH / %renderH, 3);
%W = mFloatLength(%bitmapW / %renderW, 3);
ScopeRender.resize(0, 0, %W, %H);

// Center the render area and bitmap
ScopeRender.setCentered();
ScopeBitmap.setCentered();

// Add the overlay to the screen and position/resize
PlayGUI.Add(DualRenderScope);
DualRenderScope.resize(0, 0, %bitmapW, %bitmapH);
DualRenderScope.setCentered();

// Mouse sensitivity
%fovScale = %fov / 50;
if(%fovScale > 1)
%fovScale = 1;

$pref::Input::MouseSensitivity = ($DRScopes_DefaultMouseSensitivity * $Pref::DRScopesMouseSensitivityScale) * %fovScale;

// vars
$DualScopeEngaged = true;
}
function clientCmdDRScopes_unRenderDRScope()
{
// Remove
if(!isObject(DualRenderScope) || !$DualScopeEngaged)
return;

PlayGUI.remove(DualRenderScope);
$pref::Input::MouseSensitivity = $DRScopes_DefaultMouseSensitivity;

$DualScopeEngaged = false;
}
function clientCmdDRScopesPing()
{
// Recieved ping from server
echo("Received DRScopes ping from server...");
commandToServer('DRScopes_PingRespond', $DRScopes_Version);
}

package DualRenderPackage
{
function toggleFirstPerson(%val)
{
clientCmdDRScopes_unRenderDRScope();
Parent::toggleFirstPerson(%val);
}

function toggleZoom(%val)
{
if(!$DualScopeEngaged || !%val)
{
Parent::toggleZoom(%val);
}
}

function disconnect(%a)
{
clientCmdDRScopes_unRenderDRScope();
Parent::disconnect(%a);
}
};
ActivatePackage(DualRenderPackage);


// Testing util
function rebuildScope()
{
exec("./client.cs");
}

And here's the supporting server.cs

Code: [Select]
function rebuildDRScopesServer(%client)
{
exec("./server.cs");
}

function serverCmdDRScopes_PingRespond(%client, %version)
{
%client.DRScopes_enabled = true;
%client.DRScopes_Version = %version;
echo("Recieved DRScopes response from" SPC %client.name);
}

package DRScopesPackage
{
function GameConnection::onClientEnterGame(%client)
{
Parent::onClientEnterGame(%client);
commandToClient(%client, 'DRScopesPing');
}
function GameConnection::onDeath(%client, %sourceObject, %sourceClient, %damageType, %damLoc)
{
%client.clearDRScope();
Parent::onDeath(%client, %sourceObject, %sourceClient, %damageType, %damLoc);
}
function Armor::onRemove(%this, %player)
{
if(isObject(%client = %player.client))
{
%client.clearDRScope();
}
Parent::onRemove(%this, %player);
}
};
activatePackage(DRScopesPackage);

function gameConnection::pushDRScope(%client, %fov, %bitmap, %renderW, %renderH)
{
if(!%client.DRScopes_enabled || !isObject(%client))
return;

commandToClient(%client, 'DRScopes_renderDRScope', %fov, %bitmap, %renderW, %renderH);
return;
}
function gameConnection::clearDRScope(%client)
{
commandToClient(%client, 'DRScopes_unRenderDRScope');
return;
}

To render a dual render scope for a client, you would use %client.pushDRScope(ADS FOV, bitmap index, <override render area width>, <override render area height>);

You should be able to check whether or not a client has the client mod installed with the %client.DRScopes_Enabled attribute

As for arguments why we should have this instead of pressing f or using the method where you switch the entire view of the player:
This way not your entire screen is zoomed in, so you have some view of your immediate surroundings and a zoomed in view of where you look at.
This gives you the ability to react faster to threats close to you.
Second of all and certainly not an argument i should forget, it does look cool and for some people they would argue this is more natural/realistic.

Really cool concept actually, hope to see this used at some point.

Example of adjustable magnification (adjustable with brick shift keys), and also using the DR in-tandem with a camera offset 3D weaponimage:


ive thought about this concept before and its super elegant, but the only thing that held me back was it required a client mod and the liklihood of anyone downloading it are too small for the amount of effort put into it really which is a shame because its really nice

It could be used for a prepackaged gamemode, perhaps