First, you don't need to bother naming all the mobs — you can use the GetObjectNamesByType("MONSTER") function.
Second, it's obviously wrong to try to write a single value into 3 VARIABLES when that value is returned by RANDOM, which receives a TABLE. That's just something else)
Only x=creatures_position[k].x, y=..., z = ...
In short, I took the dev script for respawning bots from the 3rd campaign map for Freyda in Hammers of Fate, tweaked it to my needs also using the script for spawning red heroes near towns from the last Freyda map, and got this:
function SaveCoordinats( table )
local monster_list = {};
local k = 0;
for i=1,500 do
monster = "m"..i;
if IsObjectExists( monster ) then
k = k + 1;
monster_list[k] = monster;
creatures_positions[k] = GetObjectPosition(monster_list[k])
end;
end;
creatures_positions_list = length(creatures_positions)
end;
function RespawnUnitsByLuck()
-- if ( GetDate(WEEK) == 3 ) and ( GetDate(DAY_OF_WEEK) == random(6) + 1 ) then
local WR_luck = GetHeroStat(WR, STAT_LUCK)
local respawns_types = { CREATURE_AIR_ELEMENTAL, CREATURE_PHOENIX }
local respawns_quantities = { 100 * diff, 10 * diff }
local respawns_mood = {3, 0}
local respawns_courage = {1, 2}
local respawns_num = 20 + diff
local previous_pos = {}
local respawns_id = 0
local CanRespawnUnitsByLuck = random(100) + (10*(WR_luck+1)) * mod((WR_luck+1),diff)
if CanRespawnUnitsByLuck >= mod(70,(WR_luck+2)) + (60+diff) then --( 70 + (10+diff) ) then
print("<color=blue>Шанс ", CanRespawnUnitsByLuck ,". <color=orange>Респавним юнитов")
elseif CanRespawnUnitsByLuck < mod(70,(WR_luck+2)) + (60+diff) then --( 50 + (10+diff) ) then
print("<color=blue>Шанс ", CanRespawnUnitsByLuck ,". <color=orange>Никого не спавним")
return
end
if WR_luck >= 7 then
courage = {1, 0}
respawns_num = 20 * diff
respawns_quantities = { 200 * diff, 20 * diff }
end
for k=1, creatures_positions_list do
if ( IsTilePassable(creatures_positions[k][3]) ) then
local type = random( 1 ) + 1
if type == 2 and WR_luck < 3 then
type = 1
end
local creaturetype = respawns_types[ type ]
local quantity = respawns_quantities[ type ]
local mood = respawns_mood[ type ]
local courage = respawns_courage[ type ]
respawns_id = respawns_id + 1;
local respawnsname = 'respawns' .. respawns_id;
CreateMonster( respawnsname, creaturetype, quantity, creatures_positions[k][3], mood, courage, random( 360 ) );
end;
end;
-- end;
end;
The game complains about "attempt to index a number value". My head's already fried trying to finish this respawn so it works properly 🙃 The original dev version worked, but my map is big with lots of bushes, and covering every tile with a mask so no bot spawns there is not great( It's easier to just spawn them on existing monsters, so I already have those coordinates filled in on the map.