I have a function in Control that randomly selects a unit to spawn. However, there is an option to remove enemies from the game, so they will no longer be valid entities in my table. How can I check to make sure they exist?
Here is my function with enemy possibilities that I need to check for. The "spawn" value.
Code: Select all
function get_unit_to_spawn()
local spawn_options = {
{spawn = "ne-biter-breeder-", weight = 20},
{spawn = "ne-biter-fire-", weight = 30},
{spawn = "ne-biter-fast-", weight = 60},
{spawn = "ne-biter-wallbreaker-", weight = 50},
{spawn = "ne-biter-tank-", weight = 20},
{spawn = "ne-spitter-breeder-", weight = 8},
{spawn = "ne-spitter-fire-", weight = 3},
{spawn = "ne-spitter-ulaunch-", weight = 2},
{spawn = "ne-spitter-webshooter-", weight = 10},
{spawn = "ne-spitter-mine-", weight = 10}
}
local calculate_odds = {}
for k, spawn in ipairs(spawn_options) do
for i = 1, spawn.weight do
calculate_odds[#calculate_odds + 1] = k
end
end
local random_num = #calculate_odds
return spawn_options[calculate_odds[math.random(random_num)]]
end
local unit_to_spawn = get_unit_to_spawn()
SpawnLaunchedUnits(entity, unit_to_spawn)
Thanks