Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
  • 0
TheNerdTurtle2

Item Spawning Scripting Help

Question

Hi all!

 

It's been awhile since I've been on here but I've been working on a Doom mod and what I'm trying to do seems so simple, yet I cannot figure out how to accomplish it. My end goal is a little complicated so I'm going to dumb down my question and figure it out from there. 

 

I want to create a semirandom item spawning system. Basically let's say I created an actor in decorate called "WeakPowerupSpawner" and it's only goal is that upon loading the map it has a 50% chance to spawn green armor, 25% chance to spawn a Medkit and a 25% chance to spawn Blue armor. I know how to achieve this effect using map spots, however I also want to create a "StrongPowerupSpawner" and I feel that map editing would be much easier if I could use separate actors instead of giving identical map spots different tags.

 

Is this possible and if so could you please help me? THANKS!

 

Ask away if I'm not clear enough

Share this post


Link to post

5 answers to this question

Recommended Posts

  • 1

I don't have my stuff with me so I can't write the code, but you could define an actor class that contains multiple jump states to spawn different items that performs all of the jump states and then stops after a single tic. Depending on the structure of the jump states you could put a bunch of combinations of spawnable items, say you define two states it could jump to with a 50% chance of each and the states immediately below the jump state spawn your armor, you could put different items in each of the jump states and end up with a 25/25/50 chance with three different items. 

I wouldn't inherit from mapspot but I don't know if there is any real reason for that preference. It might not matter as long as the script "stop" after the item is spawned.

 

https://zdoom.org/wiki/A_SpawnItemEx

https://zdoom.org/wiki/A_Jump

 

There's also a "Random spawner" class I haven't played with. That might be the way to go.

Share this post


Link to post
  • 0
2 hours ago, Nihlith said:

I don't have my stuff with me so I can't write the code, but you could define an actor class that contains multiple jump states to spawn different items that performs all of the jump states and then stops after a single tic. Depending on the structure of the jump states you could put a bunch of combinations of spawnable items, say you define two states it could jump to with a 50% chance of each and the states immediately below the jump state spawn your armor, you could put different items in each of the jump states and end up with a 25/25/50 chance with three different items. 

I wouldn't inherit from mapspot but I don't know if there is any real reason for that preference. It might not matter as long as the script "stop" after the item is spawned.

 

https://zdoom.org/wiki/A_SpawnItemEx

https://zdoom.org/wiki/A_Jump

 

There's also a "Random spawner" class I haven't played with. That might be the way to go.

Hmmm.. I will look into that when I get home. I am pretty unfamiliar with jump states so it might take some trial and error

Share this post


Link to post
  • 0

It just occurred to me that you might need to randomize the duration of the state previous to the jump state in order to insure a random outcome. Might be a good idea if at first it doesn't succeed.

Share this post


Link to post
  • 0
8 hours ago, Nihlith said:

I don't have my stuff with me so I can't write the code, but you could define an actor class that contains multiple jump states to spawn different items that performs all of the jump states and then stops after a single tic. Depending on the structure of the jump states you could put a bunch of combinations of spawnable items, say you define two states it could jump to with a 50% chance of each and the states immediately below the jump state spawn your armor, you could put different items in each of the jump states and end up with a 25/25/50 chance with three different items. 

I wouldn't inherit from mapspot but I don't know if there is any real reason for that preference. It might not matter as long as the script "stop" after the item is spawned.

 

https://zdoom.org/wiki/A_SpawnItemEx

https://zdoom.org/wiki/A_Jump

 

There's also a "Random spawner" class I haven't played with. That might be the way to go.

I wrote the following DECORATE file and placed a bunch of the item on my map. It spawns nothing. Hmmmm

 

actor WeakPowerUp 6667
{
  Radius 20
  States
  {
  Spawn:
    TNT1 A 1 A_Jump(100, "Success") //256 = 100%
    Goto Death
  Success:
    TNT1 A 1 A_Jump(128, "HealthBonusSP", "ClipSP")
    TNT1 A 1 A_Jump(154, "ShellSP", "ArmorBonusSP", "StimPackSP")
    TNT1 A 1 A_Jump(256, "CellSP", "RocketAmmoSP", "MedikitSP")
    Goto Death
  HealthBonusSP:
    TNT1 A 1 A_SpawnItem("HealthBonus")
    Goto Death
  ClipSP:
    TNT1 A 1 A_SpawnItem("Clip")
    Goto Death
  ShellSP:
    TNT1 A 1 A_SpawnItem("Shell")
    Goto Death
  ArmorBonusSP:
    TNT1 A 1 A_SpawnItem("ArmorBonus")
    Goto Death
  StimPackSP:
    TNT1 A 1 A_SpawnItem("Stimpack")
    Goto Death
  CellSP:
    TNT1 A 1 A_SpawnItem("Cell")
    Goto Death
  RocketAmmoSP:
    TNT1 A 1 A_SpawnItem("RocketAmmo")
    Goto Death
  MedikitSP:
    TNT1 A 1 A_SpawnItem("Medikit")
    Goto Death
  Death:
    TNT1 A -1
    Stop
  }
}

Share this post


Link to post
  • 0

It doesn't work because your code has a couple of issues:

  • Without adding "NoDelay" right after the ticks value of a frame, the very first frame in the Spawn state of any actor won't run any function, so the first A_Jump() will never be called and it will directly go to the Death state.
  • Even if you have the "NoDelay" set up, you only roughly have the 39% chance of not going directly to the Death state.

Like Nihlith said, your best option is to go for a RandomSpawner actor, that it will do exactly what you want with a lot less efforts.

 

But if you still want to use "jumps" for unknown reasons, then:

 

Spawn:
    TNT1 A 0 NoDelay A_Jump(256, "GreenArmorSP", "GreenArmorSP", "MedkitSP", "BlueArmorSP") //256/4 = 25% --> 25% GreenArmor, 25% GreenArmor (50% total), 25% medkit and 25% BlueArmor.
    Goto Death
GreenArmorSP:
	TNT1 A 0 A_SpawnItemEx("GreenArmor")
	Goto Death
MedkitSP:
	TNT1 A 0 A_SpawnItemEx("Medkit")
	Goto Death
BlueArmorSP:
	TNT1 A 0 A_SpawnItemEx("BlueArmor")
	Goto Death
Death:
	TNT1 A 1 //no need to keep an invisible actor there forever
	Stop

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×