Enemy only attacks under certain conditions

Based on a Project Spark Team club post.

Scenario: You only want enemies to attack when your player has a certain notoriety level or are attacked by the player.

Solution:
Use brain swapping kode. I have used enemy brain and idle villager for my example, but you can create or use any brains you like.

Create a number variable called notoriety and set it as a global variable. Add to it every time your player does something notorious, like killing. For example, in your enemy brains add this:

WHEN [started to][is dead] DO [global][notoriety][increment by][10]

You will then need to save this brain as Enemybrain2

Brain swapping kode

(To find the brain gallery: Go to objects in the kode wheel then gallery picker. To save a brain press Ξ and save brain.)

Empty an enemy brain and add:

  1. WHEN [once] DO [add brain][brain gallery:Idle villager] // If you want to use Wandering villager you will have to alter the brain to make sure they are team 2. Place a wandering villager in your world , change the line in his brain. You can now save the brain as WanderingVillageTeam2 and use that.
  2. WHEN [hit by attack]
  3. …WHEN [once] DO [push brain][braingallery:Enemy brain2]
  4. WHEN [global][numvar:notoriety][=>][60]
  5. …WHEN [once] DO [push brain][braingallery:Enemy brain2]

I am assuming you are making a one player game here and there is only one player, so the notoriety level can be set globally. If that is not the case then you will have to set the notoriety level within your player.

For Enemy brain2

WHEN [started to][is dead] DO [objvar: my enemy][notoriety][increment by][10]

For your enemy brain

  1. WHEN [once] DO [add brain][brain gallery:Idle villager]
  2. WHEN [hit by attack]
  3. …WHEN [once] DO [push brain][braingallery:Enemy brain2]
  4. WHEN [see][player] DO [objvar: my enemy][equals][it]
  5. …WHEN [my enemy][numvar:notoriety][=>][60]
  6. …/…WHEN [once] DO [push brain][braingallery:Enemy brain2]

Comments are closed.

Powered by WordPress.com.

Up ↑

%d bloggers like this: