Another Coding Tip from Jands and Lude. Enjoy!

Creating a Random Spawn

The only issue in the editor with this script is to check the level extents from the Mission tab.

In the script you will need to call the routine for the first time:

def OnPostInit():
	regTimer('random_spawn', 30)

Then you will need to create the spawning routine:

def random_spawn(event):
	thugs = ('thug_001', 'thug_002', 'thug_003', 'thug_004', 'thug_005', 'thug_006')
	for thug in thugs:
		xvar = randint(extentX(box1)-100,extentX(box2)-100)
		yvar = randint(extentY(box1)-100,extentY(box2)-100)
		Object_SpawnAt('thug_with_gun', (xvar,yvar,0), thug)

The xvar and yvar variables should use numeric extents i.e. yvar = randint(-700,700)

I suggest reducing the extent by 100 to prevent placement too close to the edge.

This routine will create 6 thugs with guns (named thug_001, thug_002, etc) and randomly place them on a map.

And that’s the tip for today. Thanks again to the Herocity crew.