Page 1 of 1

CustomInventory Overlays - How To?!

PostPosted: Tue Jan 10, 2017 8:35 am
by Nash
Arookas wrote:The wiki says A_Overlay can be called by CustomInventory classes, but goes on to say exactly nothing about how this is done. Would anyone happen to know exactly how I go about doing that? Placing the psprite states in the CustomInventory doesn't give me access to all the Weapon code pointers that make psprites actually useful, and defining the states in the weapon or player doesn't seem to work. Am I supposed to call A_Overlay in the Pickup state? Do I need to give it a Use state that always fails so it stays in the inventory?


This was never answered and I have no idea how to do this, too. Please help. Preferrably a minimal working example.

ALSO:

Can someone teach me how would you sync the animation between the actual weapon sprite, and the CustomInventory overlays. They must both play the exact same animation.

Re: CustomInventory Overlays - How To?!

PostPosted: Wed Jan 11, 2017 6:36 pm
by kodi
I'm very interested as well. Your post in the zscript thread made it sound like you had some success, but since this thread isn't marked as [SOLVED] I assume there's still issues. If you could provide a barebones zscript definition for an inventory item with an interactive overlay (if you've indeed succeded in doing that) I'd very much like to experiment a bit.

Nash wrote:Can someone teach me how would you sync the animation between the actual weapon sprite, and the CustomInventory overlays. They must both play the exact same animation.

I think you could give the playerpawn a "WeaponState" or whatever StateLabel variable which is set in every state of the actual weapon, then have a copy of each of these states as an overlay in each inventory item. At the end of each overlay state you'd jump to the next with Return Resolvstate () and a lookup for the owners WeaponState variable.

Re: CustomInventory Overlays - How To?!

PostPosted: Thu Jan 12, 2017 12:33 am
by Nash
Yeah I didn't mark this thread as [Solved] yet because

A) I don't really know WTF I was doing
B) I don't understand at all how to sync animations between all the overlays

Re: CustomInventory Overlays - How To?!

PostPosted: Thu Jan 12, 2017 6:52 am
by kodi
Well here's a plasma gun that runs on custom inventory overlays if that helps :P
Edit: I'll see if I can work out a synching system that works well. This is fun!
Code: Select allExpand view
class extraplasma : custominventory
{

   default
   {
      Inventory.Amount 1;
      inventory.maxamount 50;
      +INVENTORY.ALWAYSPICKUP;
      +INVENTORY.AUTOACTIVATE;
   }
   
   states
   {   
      use:
         TNT1 A 0
         {
            statelabel nextstate = "remove";
            let ownr = doomplayer(invoker.owner);
            if (ownr)                           
            {
               nextstate = "startoverlay";
            }
         return resolvestate(nextstate);
         }
         stop;
      
      remove:
         stop;
      
      startoverlay:
         TNT1 A 0
         {
            int layer = 5;
            A_OverLay(layer,"plasmaready");
            A_OverlayOffset(layer,0,32,WOF_KEEPX);
         }
         wait;
         
      plasmaready:
      PLSG A 1 A_jumpIf(getplayerinput(INPUT_BUTTONS)&BT_ATTACK,"shoot");
      loop;
      
      shoot:
      PLSF A 2 bright;
      TNT1 A 0 A_FireCustomMissile("plasmaball",frandom(-10.0,10.0));
      PLSF B 2 bright;
      PLSF A 2 bright;
      PLSG A 4;
      goto plasmaready;
      
      
      Spawn:
         TNT1 A -1;
         Stop;
   }

}

Edit:
Managed to get my overlays to synch with the real gun (the middle shotgun).
>>Video here<<

Re: CustomInventory Overlays - How To?!

PostPosted: Thu Jan 12, 2017 2:29 pm
by Caligari87
Oh lordy that's sexy.

8-)

Re: CustomInventory Overlays - How To?!

PostPosted: Fri Jan 13, 2017 12:32 am
by Nash
kodi wrote:Edit:
Managed to get my overlays to synch with the real gun (the middle shotgun).


Nice! Minimal sauce pl0x?

Re: CustomInventory Overlays - How To?!

PostPosted: Fri Jan 13, 2017 3:57 am
by kodi
Full sauce; minimal function ! :joker:

Edit: Guess it was a silly way of doing it. If you find a better one please post that tutorial you mentioned at some point :)

Player:
Code: Select allExpand view
Class SpecMarine : DoomPlayer
{
    statelabel wepstate; //you need to set this to something by overriding postbeginplay if you want the overlay-weapons to work before you ready a weapon-weapon :P

}


weapon:
Code: Select allExpand view
class overlayshotgun : shotgun replaces shotgun
{
   default
   {
   weapon.ammouse 0;
   }

   states
   {   
   Ready:
      TNT1 A 0
        {
            let ownr = SpecMarine(invoker.owner); // Auto casts to the specified actor.
            if (ownr)                             // Make sure it exists.
            {
            ownr.wepstate = "wepready";                   
         }
         else
         {
            a_log("wepstate ready set fail");
         }
        }
      goto ready2;
      
   ready2:
      SHTG A 1 A_WeaponReady;
      Loop;
      
   Deselect:
      SHTG A 1 A_Lower;
      Loop;
      
   Select:
      SHTG A 1 A_Raise;
      Loop;
   
   Fire:
      SHTG A 0
      {
            let ownr = SpecMarine(invoker.owner);
            if (ownr)                           
            {
                ownr.wepstate = "wepfire";                   
         }
         else
         {
            a_log("wepstate fire set fail");
         }
        }
      SHTG A 3;
      SHTG A 7;
      SHTG A 0 A_FireBullets (5.6, 0, 7, 5, "BulletPuff");
      SHTG A 0 A_PlaySound ("weapons/shotgf", CHAN_WEAPON);
      SHTG BC 5;
      SHTG D 4;
      SHTG CB 5;
      SHTG A 3;
      SHTG A 7;
      Goto Ready;
   
   Spawn:
      SHOT A -1;
      Stop;

   }
}


overlay items:
Code: Select allExpand view
class extrashotgun : custominventory
{
   statelabel nextstate;
   default
   {
      Inventory.Amount 1;
      inventory.maxamount 50;
      +INVENTORY.ALWAYSPICKUP;
      +INVENTORY.AUTOACTIVATE;
   }

   states
   {
      use:
         TNT1 A 0
         {
            statelabel initstate = "remove";
            let ownr = specmarine(invoker.owner);
            if (ownr)                           
            {
               initstate = "startoverlay";
            }
            return resolvestate(initstate);
         }
         stop;
      
      remove:
         stop;
      
      startoverlay:
         TNT1 A 0
         {
            int layer = 5;
            A_OverLay(layer,"wepready");
            A_OverlayOffset(layer,64,32);
         }
         wait;
         
   wepready:

      SHTG A 1;
      SHTG A 0
        {
         let ownr = SpecMarine(invoker.owner);
            if (ownr)                             
            {
                invoker.nextstate = ownr.wepstate;                 
            }
      return resolvestate (invoker.nextstate);
        }
      SHTG A 1 A_log("Overlay Wepready state error");
      stop;
      
   wepfire: //this must has the exact same amount of frames as the corresponding state in the actual weapon.
      SHTG A 3;
      SHTG A 7;
      SHTG A 0 A_FireBullets (5.6, 0, 7, 5, "BulletPuff");
      SHTG A 0 A_PlaySound ("weapons/shotgf", CHAN_WEAPON);
      SHTG BC 5;
      SHTG D 4;
      SHTG CB 5;
      SHTG A 3;
      SHTG A 7;
      SHTG A 0
        {
            let ownr = SpecMarine(invoker.owner);
            if (ownr)                           
            {
                invoker.nextstate = ownr.wepstate;                   
            }
      return resolvestate (invoker.nextstate);
        }
      TNT1 A 0 A_log("wepfire resolvestate fail");
      stop;

   Spawn:
      SHOT A -1;
      Stop;

   }
}
 
class extrashotgun2 : extrashotgun
{
   states
   {
   startoverlay:
         TNT1 A 0
         {
            int layer = 6;
            //i tried putting random(5,500) here in the
            //above item, but several instances of the same
            //class of custom inventory item with overlays
            //do not work together :(
            A_OverLay(layer,"wepready");
            A_OverlayOffset(layer,-64,32);
         }
   }
}