Lua Behaviours

In order to allow modders a little bit more control over enemy movements There is a small experimental lua scripting environment hidden within the LuaBehaviour

Lua scripts stored in ModFolder/Behaviours/ can be passed as "luaScript" into Lua behaviours.

for example the following entity:

{
  "name": "luaSaucer",
  "sprite": "Sprites/Enemies/saucer",
  "behaviour": "Lua",
  "explosionEntity": "explosionSmall",
  "explosionX": 0,
  "explosionY": 0,
  "sortOrder": 10000,
  "maxHitPoints": 1,
  "speed": 4,
  "isEnemy": true,
  "deathBulletEntity": "deathBullet",
  "highlightPoints": false,
  "points": 10,
  "secondaryTargetValue": 1,
  "customBehaviourData": {
    "luaScript": "saucer",
    "firePattern": {
      "veryEasy": [ 80 ],
      "easy": [ 80 ],
      "normal": [ 60 ],
      "hard": [ 40 ],
      "nasty": [ 50 ]
    }
  }
}

In "Platypus Reclayed" will load "Platypus Reclayed/Behaviours/saucer.lua"

This entity can be spawned like regular entities: spawnEntity("entity": "luaSaucer", "x": 800, "y": 240);

Hooks

Certain functions within lua functions are called by the game automatically. These are:

  • void OnDeinitialise()
  • void OnHitByBullet(BaseEntity bulletEntity)
  • void OnHitByPlayer(Player player)
  • void OnInitialise()
  • void OnKill()
  • void OnRender()
  • void OnTick()
  • bool CanFire()
  • bool HasCollision()
  • bool IsKilledManually()
  • bool IsPlayerBullet()
  • float BulletConsume(BaseEntity consumer)
  • int BulletGetKillCreditIndex()
  • bool ShouldIgnorePlayerInvincibility()
  • bool ShouldKillPlayerOnTouch()

Lua language definition file

For code completion and documentation purposes, the types.lua file contains luals definitions that can be used with various IDEs.

Performance

As this lua implementation sits on top of existing systems and isn't being used by the main game, there are hardly any measures to improve performance. As such it is recommended to not rely on too many small objects and avoid calling back into the game unnecessarily

Logic Layer

The logic layer is mostly used for collision in Platypus this is a matrix graph to show which layers interact with eachother

Image of the 2D Collision Matrix

Setting the logic layer can be done with the following functions

  • SetLogicLayerDefault()
  • SetLogicLayerTransparentFX()
  • SetLogicLayerIgnoreRaycast()
  • SetLogicLayerWater()
  • SetLogicLayerUI()
  • SetLogicLayerPlayer()
  • SetLogicLayerPlayerShot()
  • SetLogicLayerEnemy()
  • SetLogicLayerEnemyShot()
  • SetLogicLayerLoadScreen()
  • SetLogicLayerPlayerPickupCollider()
  • SetLogicLayerPickup()
  • SetLogicLayerPlayerShotNoFruit()