RandomSpawner leaving empty space

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
PlutonianEmpire
Posts: 5
Joined: Tue Oct 09, 2018 4:07 pm
Location: MinneSNOWta

RandomSpawner leaving empty space

Post by PlutonianEmpire »

For example, lets say a RandomSpawner replaces ShotGun I have it set to DropItem 3 weapons, each from a different mod. When I load up Mod 1 and Mod 2 in ZDL but not Mod 3, The RandomSpawner at one point selects the weapon from Mod 3, resulting in empty space in-game where the ShotGun would normally be

How do I tell the RandomSpawner to try again if a weapon it selects does not exist?
Blue Shadow
Posts: 5043
Joined: Sun Nov 14, 2010 12:59 am

Re: RandomSpawner leaving empty space

Post by Blue Shadow »

By [wiki=ZScript_virtual_functions]overriding[/wiki] RandomSpawner's ChooseSpawn() function:

Code: Select all

class MyRandomSpawner : RandomSpawner
{
    override Name ChooseSpawn ()
    {
        // Copy the contents of the original function here, and modify as needed.
    }
} 
These two lines in that function should be of interest to you.
PlutonianEmpire
Posts: 5
Joined: Tue Oct 09, 2018 4:07 pm
Location: MinneSNOWta

Re: RandomSpawner leaving empty space

Post by PlutonianEmpire »

Would this go in DECORATE or somewhere else?
Gez
 
 
Posts: 17943
Joined: Fri Jul 06, 2007 3:22 pm

Re: RandomSpawner leaving empty space

Post by Gez »

ZScript only.
PlutonianEmpire
Posts: 5
Joined: Tue Oct 09, 2018 4:07 pm
Location: MinneSNOWta

Re: RandomSpawner leaving empty space

Post by PlutonianEmpire »

I was finally able to get around to making a zscript with the override, and using the new randomspawner class, however doing so resulted in Zandronum refusing to start up:

https://i.imgur.com/EdLNUvY.png
https://i.imgur.com/zlHr7Ns.png
https://i.imgur.com/7gbjPKm.png

What gives?
Gez
 
 
Posts: 17943
Joined: Fri Jul 06, 2007 3:22 pm

Re: RandomSpawner leaving empty space

Post by Gez »

Compatibility with Zandronum was not mentioned in the opening post. Zandy doesn't support ZScript last time I checked, so you're out of luck.
PlutonianEmpire
Posts: 5
Joined: Tue Oct 09, 2018 4:07 pm
Location: MinneSNOWta

Re: RandomSpawner leaving empty space

Post by PlutonianEmpire »

;_;

Alrighty thank you
User avatar
TDRR
Posts: 829
Joined: Sun Mar 11, 2018 4:15 pm
Location: Venezuela

Re: RandomSpawner leaving empty space

Post by TDRR »

This is doable with some hacky trickery.

You make actors that inherit from the vanilla Doom weapons and give them the same names as the weapons in the mods your spawner intends to support. So if one of the mods isn't loaded, it spawns a Vanilla Doom weapon instead of nothing. Of course this has the problem that the other mods have to be loaded last.


There's a cleaner way with ACS that involves making a check if the spawned actor has spawned correctly, but i haven't tested it. Theoretically it should be this:

DECORATE

Code: Select all

ACTOR BackupShotgun : Shotgun {}

ACTOR ShotgunRandomSpawn : Inventory replaces Shotgun
+INVENTORY.ALWAYSPICKUP
states
{
Spawn:
TNT1 A 0
TNT1 A 0 ACS_NamedExecuteAlways("SpawnShotgun", 0)
TNT1 A -1
Stop
}
}
ACS

Code: Select all

Script "SpawnShotgun" (void)
{
     int x = GetActorX(0);
     int y = GetActorY(0);
     int z = GetActorZ(0);
if(Spawn("SomeModShotgun",x, y, z == 0) {Spawn("BackupShotgun", x, y, z);}
}
This example is not random and it spawns the same weapon unless the mod isn't loaded (of course you need to change "SomeModShotgun" to the weapon you want to spawn) but making it random isn't hard at all.

Of course, if you can give me more information (which mods are meant to be supported by this, specifically) i could make a complete version for you.
User avatar
Arctangent
Posts: 1235
Joined: Thu Nov 06, 2014 1:53 pm
Contact:

Re: RandomSpawner leaving empty space

Post by Arctangent »

That also has the issue that the new weapon won't have the intended flags, TID, or special, meaning it won't be dropped with half ammo from monster ( and, subsequently, can't be picked up for ammo when dropped by monsters while Weapon Stay is on ), and you'll break compatability with any map that manipulates the weapon with scripting or causes something to happen when the weapon is picked up.

Also, speaking of Weapon Stay, not only would the weapon not disappear after being picked up, but because the thing that's spawning it is an item that would be picked up and then disappear, you'd be able to get all of the weapons from a spawner by combining Weapon Stay and Items Respawn, because the weapons will, well, stay, but the item that spawns them would keep respawning and thus spawning more weapons.
User avatar
TDRR
Posts: 829
Joined: Sun Mar 11, 2018 4:15 pm
Location: Venezuela

Re: RandomSpawner leaving empty space

Post by TDRR »

Arctangent wrote:That also has the issue that the new weapon won't have the intended flags, TID, or special, meaning it won't be dropped with half ammo from monster ( and, subsequently, can't be picked up for ammo when dropped by monsters while Weapon Stay is on ), and you'll break compatability with any map that manipulates the weapon with scripting or causes something to happen when the weapon is picked up.

Also, speaking of Weapon Stay, not only would the weapon not disappear after being picked up, but because the thing that's spawning it is an item that would be picked up and then disappear, you'd be able to get all of the weapons from a spawner by combining Weapon Stay and Items Respawn, because the weapons will, well, stay, but the item that spawns them would keep respawning and thus spawning more weapons.
You can transfer the TID as long as you pass it as an argument to the script (thing i forgot to do there) and yeah, the weapon DOES dissapear when you grab it and the Inventory item (spawner) would also dissapear, and when the inventory item respawns, the weapon does so too.
I have used this method many times and i know what it does, the only thing that can make the weapon properly stay is RandomSpawner and that isn't viable for Zandronum in this case.
Arctangent wrote:( and, subsequently, can't be picked up for ammo when dropped by monsters while Weapon Stay is on )
That's incorrect. The weapon will dissapear as if weapon stay wasn't active, but it will give full ammo.
This can be fixed by checking for the +DROPPED flag and spawning a different shotgun in that case. (or give it a CustomInventory item that sets the +DROPPED flag)
Post Reply

Return to “Scripting”