Need help to make diamond grid nested loop

Hi everyone,

Great day! I am trying to make a diamond grid nested loop but I have a problem with it. There are excessive events created that are more than the desired diamond grid. Kindly check the attached files for the picture. Here are my event commands and scripts:

Control Variables : #0003 map.start = Map ID
Control Variables : #0001 player.start.x = 1
Control Variables : #0002 player.start.y = 1
Control Variables : #0006 player.walk.min = Random 0..7
Control Variables : #0007 player.walk.max = $gameVariables.value(6)+Math.randomInt(7-$gameVariables.value(6)+1);

Transfer Player : {map.start}({player.start.x},{player.start.y})

Script : Galv.SPAWN.overlap = 'chars';
Control Variables : #0014 player.walk.tilex = 0
Control Variables : #0015 player.walk.tiley = 0
Control Variables : #0014 player.walk.tilex += player.walk.min
Control Variables : #0015 player.walk.tiley = 0
Loop
If : player.walk.tiley <= player.walk.max
Loop
If : Script : $gameVariables.value(14)<=$gameVariables.value(7);
Script : Galv.SPAWN.event(3,$gameVariables.value(1)+$gameVariables.value(14)-$gameVariables.value(15),
$gameVariables.value(2)+$gameVariables.value(15));
Script : Galv.SPAWN.event(3,$gameVariables.value(1)-$gameVariables.value(14)+$gameVariables.value(15),
$gameVariables.value(2)-$gameVariables.value(15));
Script : Galv.SPAWN.event(3,$gameVariables.value(1)+$gameVariables.value(14)-$gameVariables.value(15),
$gameVariables.value(2)-$gameVariables.value(15));
Script : Galv.SPAWN.event(3,$gameVariables.value(1)-$gameVariables.value(14)+$gameVariables.value(15),
$gameVariables.value(2)+$gameVariables.value(15));
: Else
Break Loop
Jump to Label : After Loop X
: End
Control Variables : #0014 player.walk.tilex += 1
: Repeat Above
Label : After Loop X
Control Variables : #0014 player.walk.tilex = player.walk.min
: Else
Break Loop
Jump to Label : After Loop Y
: End
Control Variables : #0015 player.walk.tiley += 1
: Repeat Above

The image I used for the diamond grid is the dog. Please help me remove the excessive dog events created.
I'm not familiar with the plugin you've shown, but in the above image, if you wanted only a diamond shape made out of dogs, try adding this to your code. (I'll have to describe)

There is a function called $gameMap.distance
It accepts the following arguments
x1, y1, x2, y2

In the above image, if all excess was removed (dogs), it would be only the dogs that had a distance of 3 from the Player.

So when generating the dogs, if you add this condition (we'll called the dog event position being examined 'dog')

if($gameMap.distance($gamePlayer.x, $gamePlayer.y, dog.x, dog.y) == 3)

The above condition requires that if the process is attempting to draw a dog, it must be a total (x and y) of 3 tiles from the player. If that rule
was followed in the image you've shown, it would leave a nice, even diamond shape.

I hope this helps.

*Also, There is a possibility that $gameMap.distance is a function added in by a Yanfly Core plugin, I'm not 100% sure. I just checked and it doesn't seem to be.
Hi standardplayer,

Thank you for your reply. As for your if($gameMap.distance($gamePlayer.x, $gamePlayer.y, dog.x, dog.y) == 3) formula, can you please provide me the full code to create the diamond grid dogs perfectly like this representation:

if($gameMap.distance($gamePlayer.x, $gamePlayer.y, dog.x, dog.y) == 3) {
//generate dogs in diamond grid pattern <- please finish the code
}

Original thread: https://forums.rpgmakerweb.com/threads/need-help-to-make-diamond-grid-nested-loop.106173/