Script-spawned ammo won't respawn after pickup

Discuss all aspects related to modding Zandronum here.
Post Reply
User avatar
CallCenterHero
 
Posts: 24
Joined: Sun Jan 31, 2016 2:00 am

Script-spawned ammo won't respawn after pickup

#1

Post by CallCenterHero » Sun Apr 10, 2016 6:02 am

In the mod I'm working on right now, I spawn ammo based on which weapon is randomly selected at the beginning of the match. How I've devised to do this is:

1. Set up mapspots where ammo will spawn.
2. Wrote a script to spawn ammo at that mapspot based on a randomly-selected weapon.
3. Respawn every so often... deleting the previous ammo, which prevents a double-dose of ammo-getting.

What I want to do is eliminate step 3 if possible and make it to where the ammo respawns "naturally" without any scripts. Is there any way to do this if the ammo's been spawned by script instead of placed directly in the map?

Here is a snippet of the code I use to spawn/respawn the ammo.

Code: Select all


/* This array contains everything we need to know about each weapon. The weapon string, 
the string blasted out on the screen when the weapon is selected (callout), ammo type & quantity
and the mapSpot TID where we'll spawn that ammo*/

int weapons[WEAPARRSIZE][5] = {
	/*The data in these arrays is arranged in the following order:
	
	{(weapon string),(weapon callout), (ammo type), (ammo quantity), (mapSpot TID)}
	
	*/
	
	{"SuperShotgun","SUPER SHOTGUN", "Shell", 50, 200},
	{"RailGun","RAILGUN!!!", "Cell", 200, 100},
	{"PlasmaRifle","PLASMA RIFLE", "Cell", 100, 100},
};

/* ~~~SNIPPITY DOO-DAH~~~~ */
	
	/* This is the code to spawn ammo at a given mapspot. It works like this:
	1. Remove any previous ammo with the TID of 5100 (assigned to all ammo spawned by this script).
	2. Spawn new ammo.
	3. Wait 525 tics.
	4. Rinse, repeat
	
	Yeah, it's ok, I guess. 
	*/
	do {
		Thing_Remove(5100);
		SpawnSpot(weapons[indx][2], weapons[indx][4], 5100);
		
		delay (525);
		
		}
	while (countFinished == true);

User avatar
arkore
Forum Regular
Posts: 189
Joined: Mon Dec 17, 2012 8:01 pm

Re: Script-spawned ammo won't respawn after pickup

#2

Post by arkore » Thu Apr 14, 2016 5:21 am

Code: Select all

// Ammo death (respawn) script.
script 123 (int indx, int do_delay) {
  if (do_delay) { Delay(525); }
  int ammo_tid = 5100+indx;

  // Spawn ammo at the mapspot.
  SpawnSpotForced(weapons[indx][2], weapons[indx][4], ammo_tid, 0);
  SpawnSpot("ItemFog", ammo_tid);

  // Assign special for re-spawning(with delay) upon pick-up.
  SetThingSpecial(ammo_tid, ACS_ExecuteAlways, 123, 0, indx, 1);
}
// Test
script 5 OPEN {
  // Spawn cell without delay.
  ACS_Execute(123, 0, 2, 0, 0);
}

User avatar
SwordGrunt
Forum Regular
Posts: 377
Joined: Thu Jun 07, 2012 8:43 pm

Re: Script-spawned ammo won't respawn after pickup

#3

Post by SwordGrunt » Wed Apr 20, 2016 1:43 pm

Alternatively, you can create modified ammo actors and clear the DROPPED flag on their Spawn state. Unless you're already modifying weapons/ammo in your mod however, I'd recommend arkore's script instead.

Code: Select all

actor MyShell : Shell {
states {
   Spawn:
      TNT1 A 0
      TNT1 A 0 A_ChangeFlag("DROPPED",0)
      goto Super::Spawn
} }

Post Reply