Author Topic: Weapon FOV saving and loading?  (Read 2180 times)

Alright bit of a back story before i begin; for the record i am an idiot when it comes to coding languages and how they work and im slowly learning, so as this is an issue that i would really love to get resolved soon im going to ask for a little spoon feeding, but at the same time id enjoy if you took a little bit of time to walk me through stuff or show me how it works ect for the future.

Annnnyways
Basically whats going on is that the coding template that im using, courtesy of NEKram, sets FOV to 90 or whatever i specify in the code. Now in the code i can alter FOV for magnified optics, but when you unmount the optic image i have to set the FOV back to specific value.

What i want to do is be able to get the players default FOV and set it back to that FOV value when the player unmounts the optic image.

Heres what i use now:
Code: [Select]
package AK74MSights
{
function armor::onTrigger(%this,%obj,%triggerNum,%val)
{
%client = %obj.client;
if(%obj.getMountedImage(0) $= AK74MImage.getID() && %triggerNum == 4 && %val)
{
%newAmmo = %obj.toolAmmo[%obj.currTool];
%obj.mountImage(AK74MSCImage, 0);
%client.setControlCameraFov(80);
%obj.toolAmmo[%obj.currTool] = %newAmmo;
}
else if(%triggerNum == 4 && %obj.getMountedImage(0) $= AK74MSCImage.getID() && %val)
{
%newAmmo = %obj.toolAmmo[%obj.currTool];
%obj.mountImage(AK74MImage, 0);
%client.setControlCameraFov(90);
%obj.toolAmmo[%obj.currTool] = %newAmmo;
}
Parent::onTrigger(%this,%obj,%triggerNum,%val);
}
function servercmdDropTool(%client,%slot)
{
if(%client.player.getMountedImage(0) $= AK74MSCImage.getID())
{
%client.player.unmountImage(0);
%client.setControlCameraFov(90);
if($BKT::CH)
{
crossHair.setBitmap("base/client/ui/crosshair.png");
}
}
return Parent::servercmdDropTool(%client,%slot);
}
};
activatePackage(AK74MSights);
Code: [Select]
function AK74MSCImage::onMount(%this, %obj, %slot, %client)  
{
%obj.client.setControlCameraFov(80);
commandToClient(%obj.client,'bottomPrint',"<just:right><font:impact:24><color:FF0000>|||  <font:impact:34>\c6" @ %obj.toolAmmo[%obj.currTool]+0 @ " / " @ %obj.client.quantity["AmmoMedium"]+0 @ "", 4, 2, 3, 4);
}

function AK74MSCImage::onUnMount(%this, %obj, %slot, %client)  
{
%obj.client.setControlCameraFov(90);
}

I would be very appreciative if you guys could solve this for me and possibly teach me a few things as well. Bare with me and thanks in advance.

I do this sometimes

%client.Zoom = %client.getControlCameraFov();

in the onTrigger method, i suggest you assign Zoom immediately before scoping in/switching images, and then when you switch back, just setControlCameraFov to the %client.Zoom which was set before. Some content creators assign it onSpawn and that might be the better option, but then when you change your FOV after spawning and scope, it will revert back to an older fov from before you changed your settings
« Last Edit: April 25, 2017, 09:28:40 PM by PhantOS »

I do this sometimes

%client.Zoom = %client.getControlCameraFov();

in the onTrigger method, i suggest you assign Zoom immediately before scoping in/switching images, and then when you switch back, just setControlCameraFov to the %client.Zoom which was set before. Some content creators assign it onSpawn and that might be the better option, but then when you change your FOV after spawning and scope, it will revert back to an older fov from before you changed your settings

Could you provide me with an example? Just to make sure what im doing is what your thinking of.

Could you provide me with an example? Just to make sure what im doing is what your thinking of.
change
Code: [Select]
if(%obj.getMountedImage(0) $= AK74MImage.getID() && %triggerNum == 4 && %val)
{
%newAmmo = %obj.toolAmmo[%obj.currTool];
%obj.mountImage(AK74MSCImage, 0);
%client.setControlCameraFov(80);
%obj.toolAmmo[%obj.currTool] = %newAmmo;
}
to
Code: [Select]
if(%obj.getMountedImage(0) $= AK74MImage.getID() && %triggerNum == 4 && %val)
{
%newAmmo = %obj.toolAmmo[%obj.currTool];
%obj.mountImage(AK74MSCImage, 0);
%client.zoom = %client.getControlCameraFov();
%client.setControlCameraFov(80);
%obj.toolAmmo[%obj.currTool] = %newAmmo;
}

change
Code: [Select]
function AK74MSCImage::onMount(%this, %obj, %slot, %client) 
{
%obj.client.setControlCameraFov(80);
commandToClient(%obj.client,'bottomPrint',"<just:right><font:impact:24><color:FF0000>|||  <font:impact:34>\c6" @ %obj.toolAmmo[%obj.currTool]+0 @ " / " @ %obj.client.quantity["AmmoMedium"]+0 @ "", 4, 2, 3, 4);
}
to
Code: [Select]
function AK74MSCImage::onMount(%this, %obj, %slot, %client) 
{
%client.zoom = %client.getControlCameraFov();
%obj.client.setControlCameraFov(80);
commandToClient(%obj.client,'bottomPrint',"<just:right><font:impact:24><color:FF0000>|||  <font:impact:34>\c6" @ %obj.toolAmmo[%obj.currTool]+0 @ " / " @ %obj.client.quantity["AmmoMedium"]+0 @ "", 4, 2, 3, 4);
}

and replace all instances of
Code: [Select]
client.setControlCameraFov(90);
with
Code: [Select]
client.setControlCameraFov(%client.zoom);

Ah thank you i see what he was talking about now.
Code: [Select]
function AEK971SCImage::onMount(%this, %obj, %slot, %client) 
{
%client.zoom = %client.getControlCameraFov();
%obj.client.setControlCameraFov(80);
commandToClient(%obj.client,'bottomPrint',"<just:right><font:impact:24><color:FF0000>|||  <font:impact:34>\c6" @ %obj.toolAmmo[%obj.currTool]+0 @ " / " @ %obj.client.quantity["AmmoMedium"]+0 @ "", 4, 2, 3, 4);
}

function AEK971SCImage::onUnMount(%this, %obj, %slot, %client) 
{
%client.setControlCameraFov(%client.zoom);
}

package AEK971Sights
{
function armor::onTrigger(%this,%obj,%triggerNum,%val)
{
%client = %obj.client;
if(%obj.getMountedImage(0) $= AEK971Image.getID() && %triggerNum == 4 && %val)
{
%newAmmo = %obj.toolAmmo[%obj.currTool];
%obj.mountImage(AEK971SCImage, 0);
%client.zoom = %client.getControlCameraFov();
%client.setControlCameraFov(80);
%obj.toolAmmo[%obj.currTool] = %newAmmo;
}
else if(%triggerNum == 4 && %obj.getMountedImage(0) $= AEK971SCImage.getID() && %val)
{
%newAmmo = %obj.toolAmmo[%obj.currTool];
%obj.mountImage(AEK971Image, 0);
%client.setControlCameraFov(%client.zoom);
%obj.toolAmmo[%obj.currTool] = %newAmmo;
}
Parent::onTrigger(%this,%obj,%triggerNum,%val);
}
function servercmdDropTool(%client,%slot)
{
if(%client.player.getMountedImage(0) $= AEK971SCImage.getID())
{
%client.player.unmountImage(0);
%client.setControlCameraFov(%client.zoom);
if($BKT::CH)
{
crossHair.setBitmap("base/client/ui/crosshair.png");
}
}
return Parent::servercmdDropTool(%client,%slot);
}
};
activatePackage(AEK971Sights);

That's what i got, unfortunately when i unmount the scoped image it keeps my FOV at 80 instead of reverting back to my default FOV. Am i missing something?

maybe try %obj.client instead of %client?
it should be the same thing, if %client is actually the client (could echo both and check)

maybe try %obj.client instead of %client?

Had the same idea, didn't work

put an echo in the unmount printing %obj.client and %client
this will let us know if they're the same, and if unmount is even being executed

Alright, this isn't exactly relevant to the main topic, but if there is a way to not have that weapon pack use a package for every single gun which slows loading times down quite a bit, that would be great.

Alright, this isn't exactly relevant to the main topic, but if there is a way to not have that weapon pack use a package for every single gun which slows loading times down quite a bit, that would be great.
have one package that checks for a value on the image datablock to be set, like image.isScopableGun, and trigger the scope to happen if true

example of what conan's saying:

Code: [Select]
datablock ShapeBaseImageData(yourgunname)
{
         isScopableGun = true;
         zoom = 40;
};

package scoping
{
     function Armor::onTrigger(%this,%params)
     {
           if(!%this.isScopableGun)
                    return parent::onTrigger(%this,%params);

           //put scopable-exclusive code here
     }
};
activatepackage(scoping);

you can shove this into a server.cs or package.cs as long as the package comes after the gun code. this way, any weaponimage with isScopingGun = true will execute the stuff you want
« Last Edit: April 30, 2017, 11:31:41 AM by PhantOS »

you can shove this into a server.cs or package.cs as long as the package comes after the gun code. this way, any weaponimage with isScopingGun = true will execute the stuff you want
package does not have to come after gun datablock definitions, but yes that is what i meam