Proper way to make random spawners based on CVARs
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!)
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!)
Proper way to make random spawners based on CVARs
I'm interested in making some random spawners that can be customized by CVARs. For example, an imp can spawn a GreenImp or a RedImp, but the player should be able to turn off RedImps if they so choose, with a boolean CVAR. Basic random spawners are easy enough, but how do I make customizable random spawners that also properly transfer thing tags, boss death properties, etc. ?
Re: Proper way to make random spawners based on CVARs
You'll have to use ZScript, which will let you override the ChooseSpawn() method.
That's all you have to do. Write a ChooseSpawn function that returns the name of the actor you want to spawn. (You can return 'None' to spawn nothing.)
That's all you have to do. Write a ChooseSpawn function that returns the name of the actor you want to spawn. (You can return 'None' to spawn nothing.)
Re: Proper way to make random spawners based on CVARs
Thanks so much Gez I managed to get myself something minimal working thanks to your suggestion. Is there a convenient way for me to combine the default randomization properties with DropItem + CVAR-based filtering? Say I have a random spawner that, by default, has an equal chance of spawning a GreenImp, RedImp, or BlueImp, and those drop chances are set via DropItem, as is documented on the wiki for RandomSpawner. However, I have a CVAR that is something like "tango_disable_green_imp" which, when true, should prevent the spawner from ever dropping the GreenImp, and instead go to something else. Is there a convenient way of doing this without essentially re-implementing the native ChooseSpawn() virtual function's logic every time?
In fact, it wouldn't even have to use DropItem necessarily, but I'm just trying to think of a clean, reusable system for CVAR-based RandomSpawners, without having to duplicate a lot of code in each RandomSpawner. For example, maybe something like the following psuedocode:
The local array of possible drops could be multidimensional, too, I guess, to include names and drop chances and weight, much like DropItem allows for. Is this even feasible or necessary though? Would it make more sense to just use DropItems and do the same process but using that list instead?
edit: Also just realized that it could make sense for the array to be part of the class itself (so a static property I think?) instead of locally declared inside the ChooseSpawn() method
In fact, it wouldn't even have to use DropItem necessarily, but I'm just trying to think of a clean, reusable system for CVAR-based RandomSpawners, without having to duplicate a lot of code in each RandomSpawner. For example, maybe something like the following psuedocode:
Code: Select all
ChooseSpawn()
{
if nomonsters is on, return 'None'
declare local array that maps all possible drops to their relevant CVARS, if any
iterate over the array and remove any items for which the corresponding CVAR is false
choose a drop from the remaining items at random
return that drop
}
edit: Also just realized that it could make sense for the array to be part of the class itself (so a static property I think?) instead of locally declared inside the ChooseSpawn() method
Re: Proper way to make random spawners based on CVARs
You could copy-paste the original ChooseSpawn function and graft your exclusion code there so that it skips over dropitems that have a disabled name.
Re: Proper way to make random spawners based on CVARs
Yeah I think I will end up doing just that. Thanks so much for the help Gez much appreciated