[SOLVED][zscript] get/set psprite?

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
User avatar
zrrion the insect
Posts: 2411
Joined: Thu Jun 25, 2009 1:58 pm
Location: Time Station 1: Moon of Glendale

[SOLVED][zscript] get/set psprite?

Post by zrrion the insect »

How can I get/set a psprite?
I am working on a quick melee for some weapons that I would like to add to the base weapon. This quick melee has 3 stages:
  1. lower weapon sprites off of screen
  2. melee happens
  3. raise melee sprites onto screen
I know that I can use "####" "#" 1 A_WeaponOffset(blah); for step one, and step 2 is pretty straight forward, but for step three I cannot use the same method as was used for step 1. If I could get the sprites used in step 1 I could then set the sprites in step 3 to do what I want.
Last edited by zrrion the insect on Sun Apr 08, 2018 12:58 am, edited 1 time in total.
User avatar
phantombeta
Posts: 2088
Joined: Thu May 02, 2013 1:27 am
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: Brazil

Re: [zscript] get/set psprite?

Post by phantombeta »

You can use [wiki=A_Overlay]A_Overlay[/wiki] and co., I believe.
User avatar
zrrion the insect
Posts: 2411
Joined: Thu Jun 25, 2009 1:58 pm
Location: Time Station 1: Moon of Glendale

Re: [zscript] get/set psprite?

Post by zrrion the insect »

I could absolutely use A_Overlay to handle the states while the main weapon was off of the screen, absolutely! I had not actually considered that approach. :oops:
I'd still be interested in a solution but I'm not in want of one.
User avatar
wildweasel
Posts: 21706
Joined: Tue Jul 15, 2003 7:33 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): A lot of them
Graphics Processor: Not Listed
Contact:

Re: [zscript] get/set psprite?

Post by wildweasel »

You might want to look at how I've done it in ww-cola3 - the frying pan logic is entirely handled within an overlay in a base weapon class that all other weapons inherit from, which makes it so that the only thing an inheriting weapon needs to be able to use melee is to inherit from the base class and have WRF_ALLOWZOOM present. Here's the code for that base class...

Code: Select all

class ColaWeapon : Weapon replaces Fist
{
    default
    {
        Weapon.BobStyle "Alpha";
        Weapon.BobSpeed 2.5;
        Weapon.BobRangeX 0.2;
        Weapon.BobRangeY 0.5;
        Inventory.Icon "UNKNA0"; // if no icon defined, show <!> instead.
        +Weapon.NoAlert
        +Inventory.AlwaysPickup
        +Weapon.Ammo_Optional
    }
    int PanSwing; // Tracks how far across the screen the pan attack is.
	States
	{
	Select:
		TNT1 A 1 A_Raise;
		Wait;
	Deselect:
		TNT1 A 1 A_Lower;
		Wait;
	Ready:
		TNT1 A 1 A_WeaponReady;
		Loop;
	Fire:
		TNT1 A 1;
		Goto Ready;
	Flash:
		TNT1 A 1 A_Light2;
		TNT1 A 1 A_Light1;
		Goto LightDone;
	Zoom:
		"####" "#" 1 A_WeaponOffset(36.0, 54.0, WOF_INTERPOLATE);
		"####" "#" 1 A_WeaponOffset(80.0, 96.0, WOF_INTERPOLATE);
		"####" "#" 3 A_WeaponOffset(1.0, 999.0); // I need to retain the last used sprite so I offset it way off screen instead of TNT1'ing it. DO NOT INTERPOLATE THIS
		"####" "#" 1 A_Overlay(69, "FryingPan");
		"####" "#" 10 A_WeaponOffset(1.0, 999.0); // DON'T INTERPOLATE THIS EITHER
		"####" "#" 1 A_WeaponOffset(80.0, 96.0, WOF_INTERPOLATE);
		"####" "#" 1 A_WeaponOffset(60.0, 80.0, WOF_INTERPOLATE);
		"####" "#" 1 A_WeaponOffset(48.0, 66.0, WOF_INTERPOLATE);
		"####" "#" 1 A_WeaponOffset(36.0, 54.0, WOF_INTERPOLATE);
		"####" "#" 1 A_WeaponOffset(24.0, 46.0, WOF_INTERPOLATE);
		"####" "#" 1 A_WeaponOffset(12.0, 38.0, WOF_INTERPOLATE);
		"####" "#" 0 A_Jump(256, "Ready");
		Goto Ready;
	FryingPan:
		FPAN A 0 {
            A_OverlayFlags(69, PSPF_ADDWEAPON, 0);
        }
		FPAN A 0 {
			A_OverlayOffset(69, -128, 8);
			if ( CountInv("PowerWeaponLevel2") >= 1 )
			{
				A_PlaySound("pan/powerswing", CHAN_WEAPON);
			}
			else
			{
				A_PlaySound("pan/swing", CHAN_WEAPON);
			}
        }
    FryingPanContinue:
        FPAN A 1;
		FPAN A 0
		{
            int runPunch = 50 + ( Vel.XY.Length() * 3); // Adds player's run speed to melee damage. It's fun!
            //A_LogInt(runpunch);
            if ( invoker.PanSwing == 6 )
            {
                invoker.PanSwing = 0;
                A_TakeInventory("PanHitSomething", 999); // For safety
                return ResolveState("null"); // Pan's made it across the screen, erase it.
            }
            A_OverlayOffset(69, 96, 12, WOF_INTERPOLATE|WOF_ADD);
            if ( CountInv("PanHitSomething") == 1 )
            {
                invoker.PanSwing = 15;
                return ResolveState("FryingPanPreRecoil");
            }
			else if ( CountInv("PowerWeaponLevel2") >= 1 )
			{
				A_CustomPunch(runPunch * 3,1,0,"ColaWeaponStrongerHitPuff", 100);
			}
			else
			{
				A_CustomPunch(runPunch,1,0,"ColaWeaponHitPuff", 100);
			}
            invoker.PanSwing++;
            return ResolveState("FryingPanContinue");
        }
		Stop;
    FryingPanPreRecoil:
        FPAN AAAA 1 A_OverlayOffset(69, random(-2, 0), random(-2, 0), WOF_ADD);
    FryingPanRecoil:
        FPAN A 1 A_OverlayOffset(69, (-12 + random(-2, 2)), (24 + random(-2, 2)), WOF_INTERPOLATE|WOF_ADD);
        FPAN A 0
        {
            A_TakeInventory("PanHitSomething", 999);
            if ( invoker.PanSwing > 0 )
            {
                invoker.PanSwing--;
                return ResolveState("FryingPanRecoil");
            }
            else
            {
                return ResolveState("null");
            }
        }
        Stop;
	}
}
User avatar
Nash
 
 
Posts: 17439
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: [zscript] get/set psprite?

Post by Nash »

You can also spawn overlays from CustomInventory's... just another tool to consider for a specific situation (say you want to completely decouple your overlays from any weapon).
User avatar
zrrion the insect
Posts: 2411
Joined: Thu Jun 25, 2009 1:58 pm
Location: Time Station 1: Moon of Glendale

Re: [zscript] get/set psprite?

Post by zrrion the insect »

I actually managed to figure out how to do this the way I intended initially and I feel that it is a less complex solution so I've gone this route. I tried using overlays and it was a hassle keeping track of multiple states, especially since one state basically doesn't do anything besides wait for the other to finish.
This gets the current sprite:

Code: Select all

if(self.player)
		{
			PSprite psp = self.player.GetPSprite(layer);
			invoker.ReadySprite = psp.sprite;
		}
And this sets it back when you are done.

Code: Select all

if(self.player)
		{
			PSprite psp = self.player.GetPSprite(layer);
			psp.sprite = invoker.ReadySprite;
		}
A similar thing could pretty easily be done with the index of the sprite.
Post Reply

Return to “Scripting”