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.

Imitating original ammo pickup amount

Postby Cyanide » Fri Jan 12, 2018 7:49 am

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 allExpand view
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 allExpand view
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
Cyanide
Spotlight Team
 
Joined: 15 Feb 2013
Location: 6 ft. under

Re: Imitating original ammo pickup amount

Postby krokots » Fri Jan 12, 2018 9:01 am

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
krokots
 
Joined: 19 Jan 2010

Re: Imitating original ammo pickup amount

Postby Arctangent » Fri Jan 12, 2018 9:04 am

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
Arctangent
squawky
 
Joined: 06 Nov 2014
Discord: SquawkyAtan#2371

Re: Imitating original ammo pickup amount

Postby Cyanide » Fri Jan 12, 2018 9:10 am

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.
User avatar
Cyanide
Spotlight Team
 
Joined: 15 Feb 2013
Location: 6 ft. under


Return to Scripting

Who is online

Users browsing this forum: No registered users and 3 guests