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
// 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
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