How can I make the amount of 10 monster spawne in each selected area?
Example:
10 fire golem at position 1500 (x) - 1000 (y)
10 ice golem in position 2000 (x) - 1600 (y)
10 Raptor in position 3000 (x) - 2000 (y)
I don't want each spawn to interfere with the other spawn.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
addhook("ms100", "MONSTERms100")
function MONSTERms100()
t = t + 1
if t % 100 == 0 then
while #MONSTERS < CONFIG.MAXMONSTERS do
local rand
repeat
rand = math.random(#CONFIG.MONSTERS)
until math.random(0, 100) < CONFIG.MONSTERS[rand].spawnchance
local m = deepcopy(CONFIG.MONSTERS[rand])
local x, y, tilex, tiley
repeat
if m.spawn1 then
tilex, tiley = math.random(m.spawn1[1], m.spawn2[1]), math.random(m.spawn1[2], m.spawn2[2])
else
tilex, tiley = math.random(map'xsize'), math.random(map'ysize')
end
until not gettile(tilex, tiley).SAFE and not gettile(tilex, tiley).PVP and tile(tilex, tiley, "walkable") and tile(tilex, tiley, "frame") ~= 34
m.x, m.y = math.floor(tilex*32+16), math.floor(tiley*32+16)
Monster:new(m)
end
end
for _, m in ipairs(MONSTERS) do
if t % m.atkspd == 0 then
m.target = nil
local closest
for _, p in ipairs(table.shuffle(player(0, 'table'))) do
if player(p, 'health') > 0 and not gettile(PLAYERS[p].x, PLAYERS[p].y).SAFE then
local dist = math.sqrt((player(p, 'x')-m.x)^2 + (player(p, 'y')-m.y)^2)
if dist < 400 then
if not closest or dist < closest[2] then
closest = {p, dist}
end
end
end
end
if closest then
local dist = closest[2]
if dist < 400 then
m.target = closest[1]
if m.spc and math.random(10000) <= m.spc[1] then
m.spc[2](m, m.target, dist)
elseif dist <= (m.range or 32) then
m:hit(m.target, 10)
end
end
end
end
m.imgang = math.sin(t/2.5*math.pi) * 15
if m.target and player(m.target, 'exists') and player(m.target, 'health') > 0 and not gettile(PLAYERS[m.target].x, PLAYERS[m.target].y).SAFE then
xdist, ydist = player(m.target, 'x') - m.x, player(m.target, 'y') - m.y
local dist = math.sqrt(xdist^2 + ydist^2)
if dist < 400 then
m.ang = math.atan2(ydist, xdist)-math.pi/2+math.random(-1, 1)/2
else
m.target = nil
end
end
if not m.target then
m:rot(math.random(-1, 1)/2)
end
if not m:move(m:rot(), m.health > m.runat and 1 or -1) then
repeat until m:move(math.rad(math.random(360)), 1)
end
end
if MONSTERESET == 0 or requestmonstereset == 1 then
MONSTERESET = 1
if MINUTES%30 == 0 or requestmonstereset == 1 then
for _, m in ipairs(MONSTERS) do
m:restart()
requestmonstereset = 0
end
msg('©100100255 MONSTER RESET @C')
end
end
end
function Monster:new(m)
if not (m.x or m.y) then return false end
m.image = image(m.image, m.x, m.y, 0)
imagescale(m.image, m.scalex, m.scaley)
setmetatable(m, self)
self.__index = self
table.insert(MONSTERS, m)
m.id = #MONSTERS
return m
end
TKS