Toggable object spawn
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!)
- nekostuffing
- Posts: 60
- Joined: Sat Aug 31, 2019 8:08 pm
- Graphics Processor: ATI/AMD with Vulkan/Metal Support
Toggable object spawn
Ive seen many mods that have options to toggle certain things to spawn or not, like smoke, bullet casings and other actors, but i haven't figured out how to do this, could someone help me understand how that's done, preferably using acs with decorate.
- R4L
- Global Moderator
- Posts: 426
- Joined: Fri Mar 03, 2017 9:53 am
- Preferred Pronouns: He/Him
- Operating System Version (Optional): Windows 11 Pro
- Graphics Processor: ATI/AMD with Vulkan/Metal Support
- Contact:
Re: Toggable object spawn
You can do this with CVars and CVARINFO: https://zdoom.org/wiki/CVARINFO
For an example, say I have a Pistol that spawns a smoke actor named BerettaSmokeSpawn in the fire state. You can define a CVar in a CVARINFO lump like so:
Then in the Fire state, say I had this for code:
Just add your CVar check before the first line:
A_JumpIf just evaluates if the CVar is true or false (in this case, false) and jumps/skips over A_FireProjectile to A_FireBullets. For more examples of A_Jump, see here: https://zdoom.org/wiki/A_Jump
For an example, say I have a Pistol that spawns a smoke actor named BerettaSmokeSpawn in the fire state. You can define a CVar in a CVARINFO lump like so:
Code: Select all
user bool mymod_disablesmoke = false; //Turn on smoke effects by defaultCode: Select all
Fire:
BRTT E 1 A_FireProjectile("BerettaSmokeSpawn",0,0,6,8) //Spawn smoke when firing
BRTT F 1 A_FireBullets(4,5,-1,6,"BulletPuff",1)
BRTT GHIJKLGO 1 A_WeaponReady
Goto Ready
Code: Select all
Fire:
TNT1 A 0 A_JumpIf(GetCVar("mymod_disablesmoke"), 2) //Don't spawn smoke
BRTT E 1 A_FireProjectile("BerettaSmokeSpawn",0,0,6,8)
BRTT F 1 A_FireBullets(4,5,-1,6,"BulletPuff",1)
BRTT GHIJKLGO 1 A_WeaponReady
Goto Ready
- nekostuffing
- Posts: 60
- Joined: Sat Aug 31, 2019 8:08 pm
- Graphics Processor: ATI/AMD with Vulkan/Metal Support
- Player701
-

- Posts: 1710
- Joined: Wed May 13, 2009 3:15 am
- Graphics Processor: nVidia with Vulkan support
- Contact:
Re: Toggable object spawn
NB: CVARs used for controlling object spawns should be marked server, otherwise they can and will break multiplayer games! Even if the object in question is just a decoration, its own behavior (such as calls to random(...) may cause a loss of network consistency due to the RNGs on each client going out of sync with each other. And even if this is avoided, by default any actor being spawned will trigger an RNG that is marked important to network sync, which will also eventually break the game if the actor is not spawned for some of the clients. There is actually a way to avoid triggering it, but I'd strongly advise against it because it looks somewhat like a hack and may eventually change at any time (and still doesn't guraantee stable behavior unless your actor is marked +NOINTERACTION, probably not even then).
- nekostuffing
- Posts: 60
- Joined: Sat Aug 31, 2019 8:08 pm
- Graphics Processor: ATI/AMD with Vulkan/Metal Support
Re: Toggable object spawn
I was using user bool but it wasn't even working in single player, changed it to server bool and now the option for turning the effect on and off works, will using server bool cause problems with multiplayer? im not sure if server int is what you meant.
- Player701
-

- Posts: 1710
- Joined: Wed May 13, 2009 3:15 am
- Graphics Processor: nVidia with Vulkan support
- Contact:
Re: Toggable object spawn
You can use any type (bool or int) depending on the application. For a simple toggle, bool is sufficient. It's the scope (server vs user) that matters. Server CVARs are always synchronized between players, and only the settings controller (i.e. the player who's hosting the game) can change them.
- nekostuffing
- Posts: 60
- Joined: Sat Aug 31, 2019 8:08 pm
- Graphics Processor: ATI/AMD with Vulkan/Metal Support
Re: Toggable object spawn
Alright thanks, appreciate it.
- R4L
- Global Moderator
- Posts: 426
- Joined: Fri Mar 03, 2017 9:53 am
- Preferred Pronouns: He/Him
- Operating System Version (Optional): Windows 11 Pro
- Graphics Processor: ATI/AMD with Vulkan/Metal Support
- Contact:
Re: Toggable object spawn
Heh, my bad for suggesting a user CVar. I didn't really think about multiplayer when I suggested it.