Fandom

Crafting and Inventory System by Amphiprion Wiki

Spawning System

5pages on
this wiki
Add New Page
Comments0 Share

This system allow you to spawn every thing you need (ennemies, objects, etc...) using several rules.

Create a SpawnerEdit

To create a spawner, you can use any kind of object. Generally it will be an invisible object.

Now you must define all initialization variables of the spawner system in a "once" statement:

1) Define simple variables:

  • destroyWhenSpawnedCount (number) : if the remaining number (not destroyed) of spawend items less or equals to this value, this spawner object will be destroyed.
    • If you do not want your spawner object can be destroyed, set "-1" to <destroyWhenSpawnedCount>
  • ​refillWhenSpawnedCountLesserThan (number) : if the remaining number (not destroyed) of spawend items less to this value, the spawning system will respawn items to its maximum capacity.
    • ​This behavior is prioritary to destroyWhenSpawnedCount 
  • ​durationBeforeRefill (number) : the number of second to wait before refilling since the condition to refill occurs.
  • spawnCapacity (number) : the total number of items spawned after a refill or at initial spawning
  • spawnRadius (number) : for item that not need to be spawned at a given location. This number provide the radius used to compute a random location around this spawner object.
  • isAtRandom (boolean) : true, if you want to spawn an item randomly from the collection of spawnable items.
    • false, to cycle around all spawnable items (in this case, i recommand to use a MAX_CAPACITY who is a multiple of the spawnable items count.

2) Then you must define the list of spawnable items (only "template" are supported)

  • store the template in an object variable (i.e. <temp>)
  • define some variable on this object. Here all supported variable:
    • isSingleton (boolean) : true if only one single instance must exists at a time (as it is based on the "name" of the object, be sure to choose a unique name - for scope of this spawned)
    • spawnAtMyLoc (boolean) : true if this item will be spawned at a given location (specified via the <spawnLoc> variable), false if it will be spawned randomly around the spawner.
    • spawnLoc (vector) : world position to spawn this item.
    • spawnProbability (number) : percentage of chance to be spawned (the sum of all spawnable item proabilities must be equals to 100)
  • finally add it to the <spawnableItems> collection variable

3) Finally you must add the "Spawning System" brain template in a channel named "spawingSystemChannel"


This system is powerfull because a spawnable item can be spawner, and as you have many variables to configure the system, i hope you will be able to achieve all your needs.

Usefull spawner variableEdit

Here a list of inner variable that you can use (get/set) to enhance the spawner behavior:

  • countItemSpawned (number) : each time an item is spawned, this counter is incremented by 1
  • spawnedItems (collection) : contains all existing (not destroyed) spawned item.
  • spawnDepleted (boolean) : true is the spawn have been depleted (all spawned item have been destroyed). Works only if you does not tell the spawner to refill automatically (refillWhenSpawnedCountLesserThan = 0)
  • forceSpawnRefill (boolean) : true if you want to force the spawner to refill immediatly


Here some ideas to customize the spawner and create your own behavior:

  • have 3 waves, 1st: 5 mobs, 2nd: 3 mobs, 3rd: boss
    • Initialize the spawner for the 1st wave, and be sure to have:
      • refillWhenSpawnedCountLesserThan = 0
      • destroyWhenSpawnedCount = -1
      • switch to a new page (2)
    • (2) The page waiting the spawn have been depleted to create the second wave :
      • ​[WHEN]<spawnDepleted> [DO]
        • ​Clear the spawnable collection and add your template(s) for the second wave
        • set <spawnDepleted> = false
        • set <forceRefillSpawn> = true
        • switch to a new page (3)
    • (3) The page waiting the spawn have been depleted to create the 2nd wave :
      • ​[WHEN]<spawnDepleted> [DO]
        • ​Clear the spawnable collection and add your template(s) for the 3rd wave
        • set <spawnDepleted> = false
        • set <forceSpawnRefill> = true
        • set <destroyWhenSpawnedCount> = 0 if you want the spawner will be destroyed after spawning the last wave
        • switch to a new page (4 - empty page)

Advanced Spawning ExampleEdit

Here an example to illustrate the capabilities of the spawning system (Recursive spawn)

Swpan-overview

        















  • Spawning System brain is a template
  • (1) and (placeholder) are not templates.
  • (a), (b), (c), (d) and (2) are templates.


Spawn main

Main Spawner:

The goal is to create a spawner (1) following the following rules:   - Spawn 5 objects. Each object can be a goblin (a)/(b) or a treasure place (2)

- Object are spawned randomly with different kind of probabilities

  • (a) 47%, (b) 47%, (2) 6%
  • (2) is a singleton, so it is imposible to have several copy at a time.

- The position of the created element depend of this type

  • (a)/(b) in a random position around (1), in a maximum range of 11
  • (2) is spawned at the (placeholder) location

- (1) refill the crater (respawn 5 elements), 5 seconde after the previous 5 element have been destroyed

  • (a)/(b)/(c)/(d) are destroyed when killed by player
  • The Goblin treasure chest (2) is destroyed when openned.



This image contains "MAX_CAPACITY" instead of "spawnCapacity" ------->







Spawn chest

Secondary Spawner

When (2) is spawned by the main spawner, it will create 4 elements (not random)

  • (d) one time as it is a singleton
  • (c) 3 times

- The position of the created element is around (2), in a maximum range of 2.


This image contains "MAX_CAPACITY" instead of "spawnCapacity" ------->





Loot systemEdit

This system can be used as a loot system, this mean that spawned item are directly created inside the spawner object inventory. For exemple a chest or a dead body. 

  • If you want that all spawned items are stored inside the inventory of the spawner object, simply add set the boolean "spawnAsLoot" to "true".
  • If you want that only specific spawned items are stored inside the inventory of the spawner object, simply add set the boolean "spawnAsLoot" to "true" to the template initialization part of the spawner (where we define the "temp" variable)

If you want to loot a stackable item, you must initialize the template ("temp" section) to specify:

  • stacksize
  • STACK_SIZE_MAX
  • isStackable

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.