Skip to content

Boo Script Examples

Pychnight edited this page Feb 1, 2018 · 3 revisions

Proper way of doing Randomization

randomize_taunt = Taunts[System.Random().Next(Taunts.Count)]

Using Sub Functions for npc and projectiles

Npc.
Projectile.

Using ForEachNearbyPlayer and OnlyOnce Functionality

Uknown : Example needed

For example, suppose I want my NPC to spawn only while it's raining in the forest, and at daytime. I would do this:

OnCheckSpawn def(player, x, y):
    return (AtSurfaceLevel() and DuringDay() and DuringRain() and InForest(player)) and 1 or 0

Or if I wanted my NPC to spawn in underground hallow:

OnCheckSpawn def(player, x, y):
    return ((AtUndergroundLevel(player) or AtCavernLevel(player)) and InHallow(player)) and 1 or 0

Or if I wanted my NPC to spawn in a region, but only during an eclipse:

OnCheckSpawn = function(player, x, y):
    return (InAndAroundRegion(player, x, y, "region") and DuringEclipse()) and 1 or 0

Or if I wanted my NPC to only spawn on wood:

OnCheckSpawn def(player, x, y):
    type = GetTile(x, y).type
    return (type == 30) and 1 or 0

What if I wanted my NPC to be super common among the custom NPCs in hard mode, but rare otherwise?

OnCheckSpawn def(player, x, y):
    if not InRegion(x, y, "region"):
        return 0

    return DuringHardmode() and 10 or 1

Clone this wiki locally