ResetInventory [split]

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.
User avatar
hideousdestructor
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

ResetInventory [split]

Post by hideousdestructor »

In the meantime... Ed, how does that code work? I just see the player gets a bunch of dropitems but how does that translate to startitems?

EDIT: Still not sure why it's "drop"items, but I got this working:

Code: Select all

class InvReset:Inventory{
	override void attachtoowner(actor other){
		other.clearinventory();
		//stolen from Ed the Bat's eventhandler in Blade of Agony
		let drop=other.getdropitems();
		if(drop){
			for(dropitem di=drop;di;di=di.Next){
				if(di.Name=='None')continue;
				other.A_GiveInventory(di.Name,di.Amount);
			}
		}
		goawayanddie();
	}
}
Last edited by hideousdestructor on Sun Jul 23, 2017 7:00 pm, edited 1 time in total.
User avatar
Ed the Bat
Posts: 3060
Joined: Thu May 03, 2012 1:18 pm
Location: Maryland, US

Re: ResetInventory

Post by Ed the Bat »

User avatar
hideousdestructor
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: ResetInventory

Post by hideousdestructor »

One problem I've noticed with this method:

1. start as regular doomguy with pistol and 50 bullets
2. reset
3. end up as rich privileged doomguy with pistol and 70 bullets

since you're also getting the extra pickup bullets from the pistol.

Is there some way to bypass or cancel out any ammo given by a weapon?
User avatar
Major Cooke
Posts: 8221
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: GZBoomer Town

Re: ResetInventory

Post by Major Cooke »

A_SetInventory?
User avatar
Ed the Bat
Posts: 3060
Joined: Thu May 03, 2012 1:18 pm
Location: Maryland, US

Re: ResetInventory

Post by Ed the Bat »

Indeed. A_GiveInventory worked with known values in BoA, but A_SetInventory makes for a more flexible approach.
User avatar
Major Cooke
Posts: 8221
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: GZBoomer Town

Re: ResetInventory

Post by Major Cooke »

On top of that, A_SetInventory ignores all skill levels, so you don't need to worry about doing any sort of factoring. That's only for A_GiveInventory to be concerned about.
User avatar
hideousdestructor
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: ResetInventory

Post by hideousdestructor »

Already tried it, same problem.
Blue Shadow
Posts: 5046
Joined: Sun Nov 14, 2010 12:59 am

Re: ResetInventory [split]

Post by Blue Shadow »

Split from the feature request thread.
User avatar
hideousdestructor
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: ResetInventory [split]

Post by hideousdestructor »

So I finally got it working by brute force: do a second pass to set all items to their proper values.

Code: Select all

class InventoryResetter:Inventory{
	override void AttachToOwner(actor owner)
	{
		//can't just use ClearInventory since we want to get all the +undroppables too
		thinkeriterator it=thinkeriterator.create("Inventory");
		actor inv;
		while
		(
			inv=inventory(it.Next())
		){
			let invv=inventory(inv);
			if(invv && invv.owner==owner)
				invv.destroy();
		}
	
		//now get all the "dropitems" (i.e. player's startitems) and give them
		let drop=owner.getdropitems();
		if(drop)
		{
			for(dropitem di=drop;di;di=di.Next)
			{
				if(di.Name=='None') continue;
				owner.A_GiveInventory(di.Name,di.Amount);
			}
			//and again, to force all items to be set to their correct numbers
			for(dropitem di=drop;di;di=di.Next)
			{
				if(di.Name=='None')continue;
				owner.A_SetInventory(di.Name,di.Amount);
			}
		}
		goawayanddie();
	}
}
Blue Shadow
Posts: 5046
Joined: Sun Nov 14, 2010 12:59 am

Re: ResetInventory [split]

Post by Blue Shadow »

Is there any thing preventing you from doing one pass with A_SetInventory?
User avatar
hideousdestructor
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: ResetInventory

Post by hideousdestructor »

Vaecrius wrote:Already tried it, same problem.
Blue Shadow
Posts: 5046
Joined: Sun Nov 14, 2010 12:59 am

Re: ResetInventory [split]

Post by Blue Shadow »

Okay, what about using GiveInventoryType? It gives the item and returns it if the giving was successful. Then you can do the amount adjustments.
User avatar
hideousdestructor
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: ResetInventory

Post by hideousdestructor »

Code: Select all

			for(dropitem di=drop;di;di=di.Next)
			{
				if(di.Name=='None') continue;
				if(owner.GiveInventoryType(di.Name))
					owner.A_SetInventory(di.Name,di.Amount);
			}
Vaecrius wrote:
Vaecrius wrote:Already tried it, same problem.
EDIT: Now that's just bizarre:

Code: Select all

			for(dropitem di=drop;di;di=di.Next)
			{
				if(di.Name=='None') continue;
				owner.A_GiveInventory(di.Name);
				owner.A_SetInventory(di.Name,di.Amount);
			}
also leaves me with 70, even though logically it should be identical to doing them in 2 separate passes.

If I replace "di.Amount" with 0, I end up with no weapons at all... and 20 bullets.

I have no idea what the fuck is going on.


EDIT: I get it.

1. give clip 50
2. set clip 50
3. give pistol 1, get clip 20
4. set pistol 1, keep clip 20

That's why we need 2 separate passes - we have to revisit all the ammo only after we've finished giving weapons.
User avatar
hideousdestructor
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: ResetInventory [split]

Post by hideousdestructor »

After Ed the Bat's suggestion on the other thread I've managed to simplify it to this:

Code: Select all

class InventoryResetter:Inventory{
	override void AttachToOwner(actor owner)
	{
		//can't just use ClearInventory since we want to get all the +undroppables too
		for(let probe=owner.inv;probe;probe=probe.inv)
		{
			probe.bundroppable=false;
			probe.bkeepdepleted=false; //for some h/strife ammo types
			probe.buntossable=false;
		}
		owner.clearinventory();
	
		//now get all the "dropitems" (i.e. player's startitems) and give them
		let drop=owner.getdropitems();
		if(drop)
		{
			for(dropitem di=drop;di;di=di.Next)
			{
				if(di.Name=='None') continue;
				owner.A_GiveInventory(di.Name,di.Amount);
			}
			//and again, to force all items to be set to their correct numbers
			for(dropitem di=drop;di;di=di.Next)
			{
				if(di.Name=='None')continue;
				owner.A_SetInventory(di.Name,di.Amount);
			}
		}
		goawayanddie();
	}
}

Return to “Editing (Archive)”