Jump to content
  • 0

Spawn powerup once instead of random item?


Dexiaz

Question

Hi there.

 

I'm working with a tweak mod for classic I/PWADs, and I want to make a feature to spawn "Allmap" on every map. I want it to spawn if it doesn't exist on map instead of any small item (armor bonus, health bonus, stimpack, medikit, shells, ammo box, clip, etc). And only once.

 

Engine: GZDoom. ACS, ZScript, Decorate.

Share this post


Link to post

5 answers to this question

Recommended Posts

  • 1

ZScript solution:

 

version "4.2"

class AllmapSpawnHandler : EventHandler
{
	override void WorldLoaded(WorldEvent e)
	{
		static const string ClassNames[] =
		{
			"Stimpack",
			"Medikit",
			"Clip",
			"HealthBonus",
			"ArmorBonus"
			// more here
		};
		
		// Supposedly LevelCreateActorIterator is faster, but I don't think
		// it works with tag 0
		ThinkerIterator it = ThinkerIterator.Create();
		Array<Actor> actors;
		
		Actor mo;
		
		while(mo = Actor(it.Next()))
		{
			// Don't touch actors with a tag
			if(mo.tid != 0)
				continue;

			string cn = mo.GetClassName();
			
			// Stop if there's already an allmap in the map
			if(cn == "Allmap")
				return;
			
			// Check if it's an actor we're ok with to replace
			for(int i; i < ClassNames.Size(); i++)
			{
				if(ClassNames[i] == cn)
				{
					actors.push(mo); // Store all valid actors in an array
					break;
				}
			}
		}
		
		for(int i=0; i < actors.size(); i++)
			console.printf(string.format("%d: %s", i, actors[i].GetClassName()));
		
		// Chose a random actor. Hack: skip the first one, since it's apparently
		// the ammo the player gets at start. There must be a better way
		mo = actors[Random(1, actors.Size()-1)]; 
		Actor.Spawn("Allmap", mo.pos); // Spawn Allmap at the actor's position
		mo.Destroy(); // Destroy the original actor
	}
}

Example attached.

allmapspawner.zip

Share this post


Link to post
  • 0

@tempdecal.wad two bugs here. first, second argument to `ACS_NamedExecuteAlways()` is map number, which should be 0 in your case (otherwise the script is simply scheduled, and never executed); and remove last "0". second, coordinates for `SpawnForce()`are in fixed-point, so you have to multiply them to 65536 in decorate code.

Edited by ketmar

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...