void gf_RandomUnitSpawnExample () {
// ------------------------- Interface -------------------------
const int lv_totalUnitTypes = 3;
const string lv_unitType1 = "Marine";
const string lv_unitType2 = "Zergling";
const string lv_unitType3 = "YourOtherUnitIDGoesHere";
// Go ahead and add more const strings for other unit types
// when modifying the code. Make sure to increase the total too.
// -------------------------------------------------------------
fixed lv_random = RandomFixed(0, 100);
fixed lv_chance = 100/lv_totalUnitTypes;
int lv_p = 1;
point lv_pt = Point(32, 32);
unit lv_u;
// When the game starts, there is 33% chance that the generator spawns a Zergling,
// 33% to spawn a marine, and 33% to spawn something else...
if (lv_random <= lv_chance) {
UnitCreate(1, lv_unitType1, c_unitCreateIgnorePlacement, lv_p, lv_pt, RandomInt(0, 360));
} else if (lv_random <= lv_chance*2) {
UnitCreate(1, lv_unitType2, c_unitCreateIgnorePlacement, lv_p, lv_pt, RandomInt(0, 360));
} else {
UnitCreate(1, lv_unitType3, c_unitCreateIgnorePlacement, lv_p, lv_pt, RandomInt(0, 360));
}
lv_u = UnitLastCreated();
}