Author Topic: fix fov problem  (Read 3621 times)

So in my weapon i have a fire mode switching package that utilizes the brick cancel key to switch between image states. I have AK74MImage/AK74MImageADS and AK74MImageS/AK74MImageSADS. "S" stands for Semi, or Semi-Auto. So i am currently using gravity cat's method for fixing FOV. i have this package enabled in my effects.cs:

Code: [Select]
package ScopesPackage
{
  function GameConnection::onClientLeaveGame(%client)
  {
    if(isObject(%client.player.lasereffect)) %client.player.lasereffect.delete();
    parent::onClientLeaveGame(%client);
  }
  function serverCmdFixFov(%client,%fov)
  {
    if(isObject(%client))
    {
      %client.defaultZoom = mClampF(%fov,75,120);
      %client.noZoomCheck = true;
      if(%client.zoomnote $= "")
      {
        messageClient(%client,'',"Fixed default FOV to " @ %client.defaultZoom @ ".");
        %client.zoomnote = true;
      }
    }
  }
  function GameConnection::spawnPlayer(%client)
  {
    parent::spawnPlayer(%client);
    if(%client.noZoomCheck != true)
    {
      %client.defaultZoom = %client.getControlCameraFov();
      messageClient(%client,'',"\c3Type \c0/fixfov [your fov]\c3 to set the field of view to which weapons reset.");
    }
  }
  function GameConnection::onDeath(%this,%killerPlayer,%killer,%damageType,%damageLoc) { %player.client.setControlCameraFov(%player.client.defaultZoom); parent::onDeath(%this,%killerPlayer,%killer,%damageType,%damageLoc); }
  function Armor::onTrigger(%this,%player,%slot,%val)
  {
    if(isObject(%player)) {
    if(%player.getMountedImage(0).MeleeSecondary == 1 && %slot $= 4 && %val) {
    if(%player.getImageState(0) $= "Ready") %player.setImageAmmo(0,0); } }
      if(isObject(%player.getMountedImage(0)))
      {
        %image = %player.getMountedImage(0);
        if(isObject(%player.getObjectMount()))
        {
          %vehicle = %player.getObjectMount();
          for(%i=0;%i<8;%i++)
          {
            if(%vehicle.getMountedObject(%i) == %player) { %vehicleSlot = %i; break; }
          }
        }
        if(%image.item.zoom $= "") { parent::onTrigger(%this,%player,%slot,%val); return; }
        if((%image.item.image $= %image.getName()) && %slot $= 4 && %val)
        {
          %player.mountImage(%image.item.image @ "ADS",0);
          %player.client.setControlCameraFov(%image.item.zoom);
          if(%vehicle !$= "") Schedule(100,0,remount,%vehicle,%player,%vehicleSlot);
        }
        if(((%image.item.image @ "ADS") $= %image.getName()) && %slot $= 4 && %val)
        {
          %player.mountImage(%image.item.image,0);
          %player.client.setControlCameraFov(%player.client.defaultZoom);
//          messageClient(%player.client,toggleZoom());
          if(%vehicle !$= "") Schedule(100,0,remount,%vehicle,%player,%vehicleSlot);
        }
        parent::onTrigger(%this,%player,%slot,%val);
      }
      else
        parent::onTrigger(%this,%player,%slot,%val);
  }
};
activatePackage(ScopesPackage);

I then use
Code: [Select]
zoom = 90;in the Item data.

Whats happening is that on full auto, or the first set of image states "AK74MImage/AK74MImageADS this method works perfectly. However when i switch to single "AK74MImageS/AK74MImageSADS, i can no longer Aim Down Sights

There are no syntax errors, what should ido?

You didn't post the code for the AK74MImageS/ADS, but my best bet is that there was a typo in the AK74MImageS/ADS.item parameter.

If that's your entire code for scoping in and out, I don't see AK74MImageSADS anywhere on it.

Yeah, I figured out the problem with him on some server already. The code assumes his single fire AK74 has it's own item datablock, but it doesn't.

If that's your entire code for scoping in and out, I don't see AK74MImageSADS anywhere on it.
Its because this snip
Code: [Select]
if(%image.item.zoom $= "") { parent::onTrigger(%this,%player,%slot,%val); return; }
        if((%image.item.image $= %image.getName()) && %slot $= 4 && %val)
        {
          %player.mountImage(%image.item.image @ "ADS",0);

Looks for whether or not the image name has "ADS" at the end of it. So basically what i posted along with
Code: [Select]
Zoom = 90;in the weapon code is the entirety of the system.


Yeah, I figured out the problem with him on some server already. The code assumes his single fire AK74 has it's own item datablock, but it doesn't.

Is there a way around this? Besides creating another itemdata, because that obviously is not going to work.

You don't have to make the itemdata usable. In fact, you should even be able to get away with using itself as an item.
AK74MImageS.item = AK74MImageS;
AK74MImageS.image = AK74MImageS;
AK74MImageSADS.item = AK74MImageS;

You don't need to use any /fixFov command. In fact, it would be rather stupid to do at this point, given that you can directly get a clients FOV.

Use %client.getControlCameraFOV() and %player.getCameraFOV().

Please disregard that as jiggy is committing Self Delete.

You don't need to use any /fixFov command. In fact, it would be rather stupid to do at this point, given that you can directly get a clients FOV.

Use %client.getControlCameraFOV() and %player.getCameraFOV().
Oh nice, though as im still steadily learning, im not too sure how to implement this. I did give it a few trys. I found a topic you had created in the past, but it didnt go into enough detail for me to understand
https://forum.blockland.us/index.php?topic=289786.0

Could you elaborate a bit more on how i would implement these? I use WeaponImage::OnMount() and WeaponImage::OnUnMount()

Oh nice, though as im still steadily learning, im not too sure how to implement this. I did give it a few trys. I found a topic you had created in the past, but it didnt go into enough detail for me to understand
https://forum.blockland.us/index.php?topic=289786.0

Could you elaborate a bit more on how i would implement these? I use WeaponImage::OnMount() and WeaponImage::OnUnMount()
No problem. What you should do is, when a player clicks to open up the zoom/ironsights, you first store their current fov in a client variable. something like %player.client.storedFOV = x;

Then you set their FOV to the zoom FOV. Then, when they click to exit zoom, you set their fov to the stored FOV, and then clear the stored FOV. Something like:
setplayerfov(%player.client.storedFOV);
%player.client.storedFOV = 0;

Code: [Select]
function AK74MSCImage::onMount(%this, %obj, %slot, %client) 
{
%client = %obj.client;
%client.storedFOV(75,120);
crossHair.setBitmap("Add-Ons/Weapon_Blockality/empty.png");
%client.player.setDataBlock("PlayerADS");
%client.setControlCameraFov(90);
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) 
{
%client = %obj.client;
%client.setplayerfov(%player.client.storedFOV);
%client.storedFOV = 0;
%client.player.setDataBlock("NormalPlayer");
//%obj.client.setControlCameraFov(90);
crossHair.setBitmap("base/client/ui/crosshair.png");
}

So something along the lines of this? Even though it doesnt work. Am i at least starting out ok?

Are you using two weapon images, one for scoped and one for not scoped? I'm assuming you are.

In AK74MSCImage::onMount:
Code: [Select]
%client isn't a variable of ::onMount.

%client.storedFov(); isn't a function. You're supposed to use a variable. Also, I don't know why you're defining the values for it instead of getting their current fov.
Instead do %client.storedFov = %client.getControlCameraFov();

You can't change a player's crosshair from the server. Crosshairs are client sided. If you do this, it'll change the host's crosshair whenever anyone scopes with the weapon.

You are you doing %client.player.setDatablock? %obj is already the player. It'd be like doing %player.client.player.setDatablock.

Why are you setting their fov to 90? I'm assuming AK74MSCImage is the zoomed in image. Shouldn't it be lower?

Why are you using %obj.client now when you've already defined %client?

clientCmdBottomPrint has three arguments, not five.

In AK74MSCImage::onUnMount:
Code: [Select]
%client isn't a variable of ::onUnMount.

Why are you using %player.client when you've already defined %client? Also, %player doesn't exist. It's %obj.

You don't really need to set their stored fov to 0. But it doesn't really matter if you do.

Again, you can't change the player's crosshair.
« Last Edit: August 28, 2016, 07:00:30 AM by jes00 »

clientCmdBottomPrint has three arguments, not five.
Oh, I thought so. And Ctrooper, in order to fix your bottomPrint not staying problem, change the BottomPrint command's time from whatever it is now to -1, then call the bottomPrint whenever you mount a new one or reload or fire, and do something like bottomPrint with no text for 1 second whenever you dismount the images.

You didn't post the code for the AK74MImageS/ADS, but my best bet is that there was a typo in the AK74MImageS/ADS.item parameter.
You don't have to make the itemdata usable. In fact, you should even be able to get away with using itself as an item.
AK74MImageS.item = AK74MImageS;
AK74MImageS.image = AK74MImageS;
AK74MImageSADS.item = AK74MImageS;
Oh, lol, so I was right to a certain extent.

EDIT: Sorry! Double-post!