// Check for a kill order
IfOrdered
  tmpx = selforder
  tmpy = [UNDO]
  IfXIsEqualToY
    UndoEnchant
    tmpargument = 0 - 500
    SetContent // Won't come back...


//------------------------------------------------------------------------------
// ZZ> Most undead have an enchantment sustaining them
IfSpawned
  EnchantTarget  // Enchant self...


//------------------------------------------------------------------------------
// ZZ> Rise from the dead...  Takes several times to wake...
IfCleanedUp
  GetContent
  tmpx = tmpargument
  tmpy = 0 - 1
  IfXIsMoreThanY
    tmpargument = tmpargument + 1
    SetContent
    tmpy = selfcounter & 7 + 7
    IfXIsMoreThanY
      tmpx = selfz
      tmpy = 0 - 20
      IfXIsMoreThanY
        tmpargument = 0
        SetContent


        tmpargument = 1
        SendMessageNear
        SetTargetToSelf
        RespawnTarget // Same location, RespawnCharacter returns to start...
        EnchantTarget  // Enchant self...
        tmpargument = 244  // Frame 61...
        SetFrame
        tmpargument = ACTIONMD
        DoActionOverride
        tmpargument = 50
        SetReloadTime
        tmpargument = 0
        ChangeArmor
      Else
        // No coming back from the pit...
        tmpargument = tmpy
        SetContent



//------------------------------------------------------------------------------
// ZZ> Handle death by sending a message and other stuff
IfKilled
  tmpargument = 1
  ChangeArmor


  IfTargetIsOnSameTeam
    tmpargument = MESSAGEFRAG
    IfTargetIsSelf
      tmpargument = 0 - 500
      SetContent // Won't come back...
      tmpargument = MESSAGEACCIDENT
  Else
    GetDamageType
    tmpx = tmpargument
    tmpy = DAMAGEHOLY
    IfXIsEqualToY
      tmpargument = 0 - 500
      SetContent // Won't come back...
      tmpargument = 2
    Else
      tmpargument = MESSAGEDEATH
  SendMessageNear


  // Drop goodies
  tmpargument = 65535
  DropMoney


  // Play the sound
  tmpargument = 1
  tmpdistance = rand & 2047 + 10000
  PlaySound


  // Make the character body
  tmpargument = 25
  SetBumpHeight



//------------------------------------------------------------------------------
// ZZ> Let the character walk around
IfTimeOut
  tmpx = rand & 255
  tmpy = 235
  IfXIsMoreThanY
    tmpargument = tmpx & 1 + 2
    tmpdistance = rand & 2047 + 10000
    PlaySound
    // Randomize the frames...
    tmpargument = tmpx & 1 + LATCHLEFT
    PressLatchButton
  SetTargetToNearbyEnemy
    tmpx = targetdistance
    tmpy = 110
    IfXIsLessThanY
      IfFacingTarget
        tmpargument = rand & 1 + LATCHLEFT
        PressLatchButton
    tmpargument = 20
    SetTime
    tmpx = targetx
    tmpy = targety
    tmpdistance = 200
    tmpturn = targetturnto
    Compass
  Else
    tmpargument = rand & 31 + 120
    SetTime
    tmpx = rand & 1023 - 512 + selfspawnx
    tmpy = rand & 1023 - 512 + selfspawny
  ClearWaypoints
  AddWaypoint
IfAtLastWaypoint
  tmpargument = 0
  SetTime


//------------------------------------------------------------------------------
// ZZ> Handle being attacked by blocking or countering or running away
IfAttacked
  // Image changes with damage
  tmpx = selflife
  tmpy = 2048
  IfXIsLessThanY
    tmpargument = 1
    ChangeArmor


  // Scream
  tmpargument = 0
  tmpdistance = rand & 2047 + 10000
  PlaySound
  // Chase the attacker
  SetTargetToWhoeverAttacked
  IfTargetIsOnHatedTeam
    tmpx = targetx
    tmpy = targety
    tmpdistance = 200
    tmpturn = targetturnto
    Compass
    ClearWaypoints
    AddWaypoint
    tmpargument = 30
    SetTime


//------------------------------------------------------------------------------
IfBumped
  SetTargetToWhoeverBumped
  IfTargetIsOnHatedTeam
    IfFacingTarget
      tmpargument = rand & 1 + LATCHLEFT
      PressLatchButton
    Else
      tmpx = targetx
      tmpy = targety
      tmpdistance = 200
      tmpturn = targetturnto
      Compass
      ClearWaypoints
      AddWaypoint
      tmpargument = 30
      SetTime
  Else
    tmpargument = 0
    SetTime
    SetTargetToOldTarget


//------------------------------------------------------------------------------
End
//------------------------------------------------------------------------------
