// 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
  SetTargetToSelf
  EnchantTarget  // Enchant self...

//------------------------------------------------------------------------------
//Rise from the dead...  Takes several times to wake...
IfCleanedUp
  tmpx = selfcontent
  tmpy = 0
  IfXIsMoreThanY
    tmpargument = selfcontent - 1
    SetContent
    tmpx = selfcontent
    tmpy = 0
    IfXIsEqualToY
      tmpx = selfz
      tmpy = -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 = -500
      SetContent // Won't come back...
      tmpargument = MESSAGEACCIDENT
  Else
    GetDamageType
    tmpx = tmpargument
    tmpy = DAMAGEHOLY
    IfXIsEqualToY
      tmpargument = -500
      SetContent // Won't come back...
      SetTargetToWhoeverAttacked		//Give exp
      tmpargument = 20
      tmpdistance = EXPREVENGE
      GiveExperienceToTarget
      tmpargument = 2
    Else
      tmpargument = MESSAGEDEATH
  SendMessageNear

  // Drop goodies
  tmpargument = selfmoney
  DropMoney

  // Play the sound
  tmpargument = 1
  PlaySound

  // Make the character body
  tmpargument = 25
  SetBumpHeight
  
  //return from the dead?
  tmpx = selfcontent
  tmpy = -1
  IfXIsMoreThanY
    tmpargument = rand & 7 + 7    //How many CleanUp updates needed
    SetContent
    

//------------------------------------------------------------------------------
// ZZ> Let the character walk around
IfTimeOut
  tmpx = rand & 255
  tmpy = 235
  IfXIsMoreThanY
    tmpargument = tmpx & 1 + 2
    PlaySound
    // Randomize the frames...
    tmpargument = tmpx & 1 + LATCHLEFT
    PressLatchButton
  SetTargetToNearbyEnemy
    tmpx = targetdistance
    tmpy = 140
    IfXIsLessThanY
      IfFacingTarget
        tmpargument = rand & 1 + LATCHLEFT    //Random attack
        PressLatchButton
    tmpargument = 20
    SetTime
    tmpx = targetx
    tmpy = targety
    tmpdistance = 300
    tmpturn = targetturnto
    Compass
  Else
    tmpargument = rand & 31 + 60
    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
  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
//------------------------------------------------------------------------------
