• Please make sure you are familiar with the forum rules. You can find them here: https://forums.tripwireinteractive.com/index.php?threads/forum-rules.2334636/

Code Random Spawming Code

DevilDog (Teufelhund)

Grizzled Veteran
Feb 25, 2006
156
0
USA
We had promised earlier that we would share the code we created for the random spawning of the AT-Gun. Please keep in mind that the code was created to solve a very specific problem and to be as simple in it's implementation as possible.

It is rather straight forward and simply extends the SpawnVehicle function. If someone had previously created this, please let me know and they will be given proper credit. Also keep in mind that because we were creating a new vehicle it required it's own Factory like any other vehicle. But this could be used for any type of vehicle if desired. You would just replace or extend (preferred) the existing vehicle's factory.

How this works is simple. When the vehicle spawns for the first time, the code essentially flips a coin (x = Rand(2). When there is a '0' (tails), the bUseRandomizer is 'true' and it is the first time the vehicle is spawning (aka VehicleCount == 0) the vehicle will not spawn. I added the VehicleCount criteria specifically to allow a vehicle that has already spawned to respawn. Technically, without this you could eventually end up with no vehicles if on the next spawn you get a '0'. We didn't think that was a good idea.

Both of the variables bUseRandomizer and bDebugSpawn can be accessed through the vehicle's properties in the editor. This will allow a mapper to change the values without having to recompile the code.

The code I added into SpawnVehicle() is colored in red.


I will work on a better implementation guide if requested. If you see or make any improvements feel free to make them or improve what is here. All I ask is that you post the code back into the forums so the community at large can benefit.

Hopefully this will add some value where appropriate. I will let Slyk explain how he has used this in his maps with the spawns areas tied to objectives.

Sorry about the code alignment. It did not copy/paste well from WOTgreal. If you want the source *.uc please contact Slyk or myself.

//===================================================================
// M1937Factory
//
// Original content Copyright
 
Last edited: