Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(1 edit) (+1)

Hello! I would probably do something like this:


let player = $gamePlayer;

let x = player.x;

let y = player.y;

let d = player.direction();

let frontX = x + (d === 6 ? 1 : d === 4 ? -1 : 0);

let frontY = y + (d === 2 ? 1 : d === 8 ? -1 : 0);



front X takes player x location and adds 1 if direction is 6 (facing right) or adds -1 (subtracts 1, if player is facing left) or it adds 0 if neither (player is facing up or down)

frontY takes player y location and adds 1 if the direction is 2 (facing down) or adds -1 (subtracts 1, if the player is facing up) or it adds 0 if neither (player is facing left or right)

This code should give you the x,y coordinates for the tile in front of the player. There are countless other conditions you can set as well, as this doesn't factor in if the tile in front of the player is passable or not. So once you have the frontX and frontY you can then handle whatever other conditions, if any are necessary, before spawning an event.

(1 edit)

Thanks much!

I also noticed issues when I try to spawn an event ontop of an existing event. For example, if I spawn an event above me, and nothing is currently there, it works fine. If I try to spawn an event on top of myself or on top of an existing event, the event i'm trying to spawn doesn't spawn. Any ideas, or is this intended?

Anyway to fix this? Not sure why this is occuring.

(+2)

If you know a little bit of javascript you should be able to adjust the code within the Ritter.canSpawnOn function in the plugin code.

it's a pretty straightforward function and easy to add to or remove things from.

Ritter.canSpawnOn = function(x, y, regions) {

    var region = $gameMap.regionId(x,y);

    //if ($gameMap.eventsXy(x, y).length > 0) return false;

    //if ($gamePlayer.x == x && $gamePlayer.y == y) return false;

    if (regions && !regions.contains(region)) return false;

    if (!$gameMap.isPassable(x,y)) return false;

    return true;

};

So if you wanted to spawn on top of the player and on top of other events you can simply comment out the two lines as shown above, but if you wanted more control you can expand on the if statements and set more conditions as well.

This is indeed expected behavior as a basic canSpawnOn function, but I left it very easy to edit, just return true if the spawner can spawn on the tile or false if not. The function is structured so it will first attempt to return false but if it passes all the conditions it'll return true at the bottom.

I hope this helps, and if you need further help be sure to ask!

(+1)

I accomplished this using your advise. Thanks much Ritter!