AI


AI is a script system that calls commands at a certain time or after a certain event. AI can be added to any sprite or decal.
It's not possible to add new types of AI commands, but there's a long list of possible ones that can let you do some intricate effects. Check out the different AI types.

  • ai.AddNode runs a command at a certain time.
        Definition: ai.AddNode(ai type, start time(-1.0 for immediately), end time(-1.0 for infinite), number of parameters(different for each ai type), all parameters separated by commas).
  • ai.AddDeathNode runs a command when the owner is destroyed.
        Definition: ai.AddDeathNode(ai type, number of parameters(different for each ai type), all parameters separated by commas).
  • ai.AddHitNode runs a command when the owner takes damage.
        Definition: ai.AddHitNode(ai type, number of parameters(different for each ai type), all parameters separated by commas).
  • ai.AddActivateNode runs a command when the owner is activated.
        Definition: ai.AddActivateNode(ai type, start time(-1.0 for immediately), end time(-1.0 for infinite, 0.0 will execute and end the command immediately), number of parameters(different for each ai type), all parameters separated by commas).
  • ai.AddCollisionNode runs a command when the owner collides with something.
        Definition: ai.AddCollisionNode(ai type, number of parameters(different for each ai type), all parameters separated by commas).

    In multiplayer, AI nodes are generally not run on clients when the sprite is owned by the host. The host of a multiplayer session is the one telling clients what to do. Death nodes are always run on clients.

    These AI types are always run on clients too:
  • PLAY_SOUND
  • ADD_POTENTIAL_SECRET_ITEM
  • PLAYER_TIME_DILATION
  • SPAWN_PARTICLE
  • RANDOM_EVENT_COMPLETED

    These commands put into a script after an AI command will change their effects on clients:
  • ai.SetLastNodeToRunOnClients() : this will allow the AI command added in the previous line to run on clients.
  • ai.SetLastDeathNodeToNotRunOnClients() : this will prevent the death AI command added in the previous line to run on clients.

    Usage example

    Type 374 has this definition:

    SPAWN_SIMPLE_SPRITE, //13 ESpriteTypeEnum type, uint32 amount, float velocity, bool atImpact, float offsetX, float offsetY, float offsetZ, bool ownerRotation, float normalOffset, float rate(-1=once), float maxDistance(0=lightFlicker,1=viewDistance,2=infinite), bool headingVelocity, float scaleHack


    Using it to spawn 4 simple wood chips sprites on death would look like this:

    ai.AddDeathNode(374, 13, 47.0, 4.0, 500.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 2.0, 0.0, 1.0);

  • 374 is the AI type.
  • 13 is the amount of parameters for this AI type.
  • 47.0 is the sprite ID which is WOOD_CHIP. AI parameters are always float, so even if the real value is 47, we must put 47.0.
  • 4.0 means we spawn 4 wood chips.
  • 500.0 is the velocity at which they move on spawn. The velocity is in a random direction.
  • atImpact of 0.0 means that we don't spawn them at impact, but at the center of the sprite.
  • The offsets are all at 0.0, so we spawn in the center of the sprite.
  • OwnerRotation of 0.0 means that we don't set the wood chip sprite orientation to the one of the owner sprite.
  • NormalOffset of 0.0 means that there's no normal offset.
  • -1.0 for rate means that the sprite spawning only happens once.
  • 2.0 for max distance means we spawn the sprites at any range.
  • headingVelocity of 0.0 means that we don't affect the sprites' heading according to its velocity.
  • scaleHack is a special variable that exists on every sprite. It can affect how a sprite behaves. In this case it does nothing and we set it to 1.0, which is the default.

    Usage example 2

    Type 56 has this definition:

    AI_TYPE_PLAY_SOUND, //9 bool attached, bool UI, ESoundEnum sound, float volumeMin, float volumeMax, float pitchMin, float pitchMax, float rate(-1=once), bool replicated


    Using it to attach a looping sound to a sprite would look like this:

    ai.AddNode(56, -1.0, -1.0, 8, 1.0, 0.0, 389.0, 1.0, 1.0, 1.0, 1.0, -1.0);

  • 56 is the AI type.
  • -1.0 for start time means that we start the node right away.
  • -1.0 for end time means that the node never ends. In this case, the node will end itself after attaching the sound.
  • 8 is the amount of parameters for this AI type. The definition of the AI type says 9, but we don't have to define all of them.
  • 1.0 for attached means that the sound will be attached to the sprite and will move with it.
  • 0.0 for UI means that this isn't a UI sound.
  • 389.0 is the sound ID which is FLOATING_PLATFORM.
  • 1.0 for volumeMin is self explanatory.
  • 1.0 for volumeMax is self explanatory.
  • 1.0 for pitchMin is self explanatory.
  • 1.0 for pitchMax is self explanatory.
  • -1.0 for rate means that this node is executed only once.
  • The replicated parameter isn't set. This would play the sound on all peers if it was set to 1.0.