So you're not going to check that there aren't any walls between the hero and the spawn point, you're just going to mark in the map editor those areas that are safe to spawn?
Basically I'm going the zone route because it lets me control from which list of enemies to spawn. Eg, if the script checks randomly to the east and determines that the enemy will be spawned in the "forest zone" , then it can generate the NPC based on that particular list.
I have updated the script, slightly, with a placeholder fix for when there isn't a suitable spot to spawn :
Code: Select all
global variable (1, pursuer)
---
plotscript, chasetimer, begin
set timer (0, 20, 18, @avoidedchase)
#a timer that lasts 20 seconds, at the end of which the chasing NPC is removed and the timer stops
end
---
plotscript, avoidedchase, begin
delete npc (pursuer)
stop timer (0)
set tag (tag: beingchased, 0)
set battle countdown (random (80, 160)
end
---
plotscript, enemy spawner, begin
variable (x_dir, y_dir, enemyzone, enemyspawn)
x_dir := 0, y_dir := 0
if (checktag ( tag: beingchased ) == 0) then (
for (attempt, 1, 20) do( # try 20 times
switch(random(1, 8)) do(
case(1) x_dir := 8
case(2) x_dir := -8
case(3) y_dir := 5
case(4) y_dir := -5
case(5) x_dir := 5, y_dir := -5
case(6) x_dir := 5, y_dir := 5
case(7) x_dir := -5, y_dir := -5
case(8) x_dir := -5, y_dir := 5
)
enemyzone := zone at spot (x_dir, y_dir, 0)
if (enemyzone == 1) then(
#grass list
set tag (tag: beingchased, 1)
enemyspawn := random (3, 6)
pursuer := create npc (enemyspawn, x_dir, y_dir)
chasetimer
break
)
else if (enemyzone == 2) then(
#forest list
set tag (tag: beingchased, 1)
enemyspawn := random (7, 9)
pursuer := create npc (enemyspawn, x_dir, y_dir)
chasetimer
break
)
else if (enemyzone == 3) then(
#beach list
set tag (tag: beingchased, 1)
enemyspawn := random (10, 11)
pursuer := create npc (enemyspawn, x_dir, y_dir)
chasetimer
break
)
else (
set battle countdown (random (40, 80))
continue
)
)
else (
set battle countdown (random (40, 80) )
break
)
end
---
plotscript, sampleenemytouch, npcref, begin
delete npc (npcref)
stop timer (0)
fight formation ( "z" )
set tag (tag: beingchased, 0)
end
Sorry, I know it's a bit all over the place and probably full of errors. My mind is more "arts" than "sciences", and I don't really have the mindset for coding. Doing my best though, appreciating all the help thrown my way.