Pickup item use state

Archive of the old editing forum
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
Locked
User avatar
Wilcocliw
Posts: 30
Joined: Wed Sep 09, 2015 3:43 am

Pickup item use state

Post by Wilcocliw »

Is it possible to make a pickupItem lets say a HealthPickup https://zdoom.org/wiki/Classes:HealthPickup like this.

Its in your inventory bar and ready to be used, is it possible that when you use it you will see it be used in the hud like this for example?
Spoiler:
User avatar
ramon.dexter
Posts: 1562
Joined: Tue Oct 20, 2015 12:50 pm
Graphics Processor: nVidia with Vulkan support
Location: Kozolupy, Bohemia

Re: Pickup item use state

Post by ramon.dexter »

Sorry for OT :)

What mod for stalker is this? I have never seen animations like this :shock:

But, for your question: Here is an example of what I'm using - health item is a pickup. The pickup is not directly used, but it goes into inventory bar, where player has to activate it. The animation is the harder part - I would make it with ACS, but I think it could be made with Zscript also. But since I have zero knowledge of zscript, I cannot tell you more.

Code: Select all

ACTOR healBluePotion : Health
{
	Inventory.Amount 15
}

ACTOR blueHealingPotion : CustomInventory 13006
{
	//$Category "INVitems"
	//$Title Blue "Healing Potion"
	
	+InvBar //this is important for items, that has to be in inventory bar
	+Inventory.AlwaysPickup //this allows you to pickupup item, even you have one in your inventory
	-Solid
	+Shootable
	+NoDamage
	+NoBlood
	+CanPass
	+NoGravity
	
	Tag "Blue Healing Potion"
	height 24
	radius 8
	scale 0.5
	Inventory.Amount 1
	Inventory.MaxAmount 30
	Inventory.InterHubAmount 30 //this allows you to carry the healing potions between maps
	Inventory.PickupMessage "Found Blue Healing Potion!"
	Inventory.Icon "I_MHP1"
	Inventory.useSound "MWsounds/drink"

	States
		{
			Spawn:
			MHP1 ABC 4
			Loop
			
			Use:
			TNT1 A 0 A_GiveInventory("healBluePotion", 1)
			Stop
		
		}


}
User avatar
Wilcocliw
Posts: 30
Joined: Wed Sep 09, 2015 3:43 am

Re: Pickup item use state

Post by Wilcocliw »

Hey thx, I am a big fan of stalker and i am planning to make a mod inspired by it, however i am not really a ACS hero, i mostly look at already existing code and see how it works.
this kinda gives me an idea on how to use it ,at least with Decorate however ACS is really confusing.
User avatar
ramon.dexter
Posts: 1562
Joined: Tue Oct 20, 2015 12:50 pm
Graphics Processor: nVidia with Vulkan support
Location: Kozolupy, Bohemia

Re: Pickup item use state

Post by ramon.dexter »

Well, I was confused by ACS when I saw it for the first time. But believe me, it"s easier than you think.

If I want to make something that has an custom animation (I had the same idead as you have - have healing items with animation), I would use one of the simplest yet powerful functions, HudMessage https://zdoom.org/wiki/HudMessage. It allows you to write what you want, where you want. Gives you full control of text. ALSO, it allows you to draw custom image onscreen. So you can make an ACS animation. With arrays, it much easier.

Here is little example of ACS driven animation. It changes texture on linedef.

Code: Select all

//string array holding the texture names; array is better, because it allows to hold multiple options
str statsGenDispAnim[22] = {	"MNANM01",
								"MNANM02",
								"MNANM03",
								"MNANM04",
								"MNANM05",
								"MNANM06",
								"MNANM07",
								"MNANM08",
								"MNANM09",
								"MNANM10",
								"MNANM11",
								"MNANM12",
								"MNANM13",
								"MNANM14",
								"MNANM15",
								"MNANM16",
								"MNANM17",
								"MNANM18",
								"MNANM19",
								"MNANM20",
								"MNANM21",
								"MNANM22",	};

script "statsGeneratorAnimation" (void)
{
	for(int count; count < 22; count++) //'for' loop automatically counts up to defined value; it's useful for purposes, where you need to automatically reach some value
	{
		SetLineTexture(297, SIDE_FRONT, TEXTURE_BOTTOM, statsGenDispAnim[count]); //every loop assigns new texture name from the string, based on the 'count' variable; you can put here almost everything
		Delay(8); //delay is neccesary; without delay, you won't see any animation, because the script counts up to defined value and then stops. So you need to put some delay here, to see the animation. Delay is in ticks, so it's pretty simple to definig animation length in animdefs.
	}
}
And for the HudMessages, as I said, you can draw images with it.

Here is simple function to display an image. It's a custom, user-defined function. It could be used as normal, built-in function, but you have to declare it before you want to use it (I mean, put this function before any script using it). If you want to read more about functions, look to zdoom wiki.

Code: Select all

function void printSprite(str msgSprite, int msgID, int msgX, int msgY, int delayX)
{
    SetFont(msgSprite);
    HudMessage(s:"A"; HUDMSG_PLAIN, msgID, CR_UNTRANSLATED, msgX, msgY, delayX);
}
And one useful custom function:

Code: Select all

function void eraseHudmsg(int msgID)
{
	HudMessage(s:""; HUDMSG_PLAIN, msgID, CR_UNTRANSLATED, 0, 0, 0);
}

So, it simplifies the declaration. Instead of SetFont and HudMessage you write 'printSprite(str msgSprite, int msgID, int msgX, int msgY, int delayX)' and that's it.


So, for the animation you would need something like:
You have to keep in mind that arrays are counted from 0, so if you have four animation frames, their numbers will be 0 1 2 3.

Code: Select all

str animationSprites[] = {"<spriteName>", "<spriteName>", "<spriteName>", ...};


script "animtedItem" (void)
{
	for(int counter, counter < 5, counter++)
	{
		printSprite(animationSprites[counter], counter, <correct X offset>, <correct Y offset>, 4);
		Delay(4);
	}


}
This will play you an animation sequence. But you have to lower the weapon, so this is other thing.
User avatar
Wilcocliw
Posts: 30
Joined: Wed Sep 09, 2015 3:43 am

Re: Pickup item use state

Post by Wilcocliw »

cant you make it like a fake or hidden weapon that is called by using it from your Inv Bar?
User avatar
ramon.dexter
Posts: 1562
Joined: Tue Oct 20, 2015 12:50 pm
Graphics Processor: nVidia with Vulkan support
Location: Kozolupy, Bohemia

Re: Pickup item use state

Post by ramon.dexter »

Well, I don't know how to make it. You have DECORATE and ACS. You cannot simply affect actor state from ACS, so it's complicated.
You can lower the weapon in decorate actor's state, but I don't know how to call this from ACS.

Maybe, you could do it that way that using the item gives you some invisible inventory token, which will be then checked by weapon's fuction. But that means every weapon has to check for this token, and also, if you want to have multiple use animations, it would mean more tokens and more checks.

Basically, this functinality is not prepred in engine. Doom was simple shooter. Equipped weapons always stay onscreen, because there was no need to hide them. So hiding weapons is complicated.

You could make in work in decorate, if you have the option to affect other actor's state. From I know, this is not possible. So you cannot affect actor's state from different actor.

But as I said, this could may be done in zscript. But I don't know how.

But if you are a newbie to mapping and scripting, keep to the ground. The first example I posted is fully functional, it does what you want. The animation is the harder part - you have to actually draw the animation frames. So stick to the ground.
User avatar
juizzysquirt
Posts: 126
Joined: Sun Jan 04, 2009 3:29 pm
Location: Knee-Deep in L.A. Meltdown

Re: Pickup item use state

Post by juizzysquirt »

Wilcocliw wrote:cant you make it like a fake or hidden weapon that is called by using it from your Inv Bar?
Yes, I think A_GiveInventory("Heal") in Use-state of healing item should work. "Heal" being a weapon class with actual healing animation that starts in Ready-state and goes straight to Deselect. I think it should have A_TakeInventory in the last state, so the dummy weapon won't stay in player inventory. In case the user has disabled "Switch on pickup" option, you can use https://zdoom.org/wiki/A_SelectWeapon to make sure dummy weapon is selected. No need for ACS at all.
User avatar
ramon.dexter
Posts: 1562
Joined: Tue Oct 20, 2015 12:50 pm
Graphics Processor: nVidia with Vulkan support
Location: Kozolupy, Bohemia

Re: Pickup item use state

Post by ramon.dexter »

Yeah, that's it :)
User avatar
Wilcocliw
Posts: 30
Joined: Wed Sep 09, 2015 3:43 am

Re: Pickup item use state

Post by Wilcocliw »

now we are on the item discussion an idea that i have is to show your ammo in your inv bar.
now the idea is to have something like the minecraft inventory bar
Image
with some personal tweaks offcourse like i still want to keep the face "div" (sorry for using HTML sense)in in the hud.
and show my ammo for example i will make a box for specific ammo that will be first a fakeinventory item that you can pickup and that will add a specific amount of ammo (that can be stacked and dropped) to the inv bar like in stalker.
Image

also inventory items need to weigh stuff but that is for another topic i guess.

anyway thx for your guys input so far i really appreciate it. :D
User avatar
ramon.dexter
Posts: 1562
Joined: Tue Oct 20, 2015 12:50 pm
Graphics Processor: nVidia with Vulkan support
Location: Kozolupy, Bohemia

Re: Pickup item use state

Post by ramon.dexter »

Maybe you should understand that doom is little bit different from stalker. Zdoom doesn't calculate items weight in any ways (that means you will have to create a new weighting system from scratch. I knwo some about scripting, but I wouldn't try to make something like this, because, basically, I have no idea how to make this...).

You can use SBARINFO to display some things (mugshot, ammo boxes, armor, used weapon).
Locked

Return to “Editing (Archive)”