Imitating original ammo pickup amount

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
Cyanide
Spotlight Team
Posts: 319
Joined: Fri Feb 15, 2013 9:39 pm
Location: 6 ft. under

Imitating original ammo pickup amount

Post by Cyanide »

I'm currently making a mod that generates a random set of weapons on every new game. For the randomizer I've done this in ACS:

Code: Select all

global int 4:shotgun_rand;
str arrayShotguns[2] = {"DoomShotgun", "DukeShotgun"};
script "WeaponPicker" OPEN
{
	if(first_gun_roll == true)
	{
		terminate;
	}
	first_gun_roll = true;
	shotgun_rand = Random(0, 1);
}

script "ShotgunRep" (void)
{
	Delay(1);
	SpawnSpotFacingForced(arrayShotguns[shotgun_rand], 0, 0);
}
The "ShotgunRep" script is called from a Decorate shotgun replacer:

Code: Select all

actor ShotgunReplaces replaces Shotgun
{
	States
	{
		Spawn:
			TNT1 A 1
			TNT1 A 10 ACS_NAmedExecuteAlways("ShotgunRep")
			Stop
	}
}
This works, but here's the problem. When I pick up a shotgun, that has been placed on the map I get 1 shotgun and 8 shells. This is fine, but when I pick up a shotgun that has been dropped from a Shotgunguy i also get 1 shotgun and 8 shells. I want to get the original 4 shells instead of 8. I also need to NOT tinker with the monster DECORATE to avoid incompatibility with other mods.

Any ideas? :)
User avatar
krokots
Posts: 266
Joined: Tue Jan 19, 2010 5:07 pm

Re: Imitating original ammo pickup amount

Post by krokots »

I was doing exact thing couple of years ago in my private mod ;). This halved amount is hard coded, but you could change that using ZScript in a couple of ways.
1) Using Events.
You would need to change the default amount of ammo per weapon to "halved" amount (eg. 4 for Shotty). Then, the event "WorldLoaded" you would iterate through actors, and for any weapon actor, you would just double the ammo amount given. That event is only at the start of a map, so any weapon that is spawned after this, will give halved amount.
2) Using BeginPlay() override on weapons.
This would need you to change all weapons to ZScript classes. Every weapon would have overriden PostBeginPlay() and in this function, it would check if it is "on floor" or "flying". That is kind of stupid check, but for your system that may suffice.

BTW I recommend strongly for you to start using ZScript instead of ACS and Decorate, it is way more flexible.
User avatar
Arctangent
Posts: 1235
Joined: Thu Nov 06, 2014 1:53 pm
Contact:

Re: Imitating original ammo pickup amount

Post by Arctangent »

The issue is that you're not retaining the +DROPPED actor flag that, well, dropped items have. You need to transfer that from the thing you're replacing to resulting item, which would be something ZScript can do extremely easily, while being something that requires a lot of indirect work arounds to do with ACS and DECORATE.
User avatar
Cyanide
Spotlight Team
Posts: 319
Joined: Fri Feb 15, 2013 9:39 pm
Location: 6 ft. under

Re: Imitating original ammo pickup amount

Post by Cyanide »

krokots wrote:I was doing exact thing couple of years ago in my private mod ;). This halved amount is hard coded, but you could change that using ZScript in a couple of ways.
1) Using Events.
You would need to change the default amount of ammo per weapon to "halved" amount (eg. 4 for Shotty). Then, the event "WorldLoaded" you would iterate through actors, and for any weapon actor, you would just double the ammo amount given. That event is only at the start of a map, so any weapon that is spawned after this, will give halved amount.
2) Using BeginPlay() override on weapons.
This would need you to change all weapons to ZScript classes. Every weapon would have overriden PostBeginPlay() and in this function, it would check if it is "on floor" or "flying". That is kind of stupid check, but for your system that may suffice.
Thanks! I think I've found a way to replicate your second answer without using ZScript.
krokots wrote:BTW I recommend strongly for you to start using ZScript instead of ACS and Decorate, it is way more flexible.
I would, but after looking at a lot of ZScript code I simply can't figure out what's going on, and the documentation on the wiki is still under construction. :( On top of that i have very limited experience with coding in general.
Post Reply

Return to “Scripting”