How to make unit from item not spawn in a specific region

I have a unit that spawns from an item but i want them to not spawn in a specific region when the item is used

3 Likes

First, you want an ai player variable for the unit to be owned by.
image

Then, you’ll want to enter the entity scripts of the item. In the in-game editor, it looks like this:


In the legacy editor, go to Environment → Item Types → (the item that spawns the unit) → Extra → Entity-Scripts.

Next, you’ll want to create a script and use the trigger “when this entity (item) is used”. The trigger can be accessed at the bar below the script name.

After that, you’ll want an if statement, checking whether or not the position where you want the unit to spawn is in the region. In this case, I’ll just use the item position. To do this, use the Boolean comparing type, and select “region overlaps with region”

Make sure to set the second value to “false”

Then, you’ll want to create the unit using the “create unit at position” action. Set the player to the AI variable. Put it inside the “then:” section of the if statement. At the end, it should look something like this.

Hope this helps!

3 Likes

Can you make it so it also works with this limit script?

2 Likes

I can’t quite understand the context of this screenshot. Do you want it to only work if there’s no tree bosses already in the game?

Pro tip: entity scripts let you reduce the amount of lag in your game. Eg. if you have a bunch of items that do different things, don’t use a global script for when it’s used and run through 10 if statements – just use entity scripts in the specific items (only the items that need to trigger it, end up triggering it), AND you don’t need if statements to see which item type it is.

2 Likes

Yes, since then if someone saved up alot of boss spawn, it would be unplayable and also thank you telling me that tip, i didn’t know you could do that.

2 Likes

in this case, you’d just make all the code I mentioned, inside that if statement

2 Likes