// Get mean if characters wanna be bad
IfAttacked
  SetTargetToWhoeverAttacked
  CallForHelp
  tmpargument = TEAME       //Team EVIL
  TargetJoinTeam
IfKilled
  SetTargetToWhoeverAttacked
  CallForHelp
  tmpargument = TEAME       //Team EVIL
  TargetJoinTeam
  
//Talk
IfBumped
  SetTargetToWhoeverBumped
  IfStateIs0
    IfTargetIsOnSameTeam
      IfTargetIsAPlayer
        tmpx = selfcontent
        
        //Hey there!
        tmpy = 0
        IfXIsEqualToY
          tmpargument = 1
          SetContent
          tmpargument = 5
          PlayFullSound
          tmpargument = 1          
          SendMessage
          
        //I need mushrooms
        tmpy = 1
        IfXIsEqualToY
          tmpargument = 2
          SetContent
          tmpargument = 6
          PlayFullSound
          tmpargument = 2          
          SendMessage
          
        //I'll trade em for..
        tmpy = 2
        IfXIsEqualToY
          tmpargument = 3
          SetContent
          tmpargument = 7
          PlayFullSound
          tmpargument = 3          
          SendMessage
          
        //Try to trade
        tmpy = 3
        IfXIsEqualToY
          tmpargument = [MUSH]
          CostTargetItemID          //Traded 1 mushroom
            tmpargument = rand % 5 + 86         //Randomize the potion gain
            tmpx = targetx
            tmpy = targety
            tmpdistance = selfz + 50
            SpawnExactCharacterXYZ
            tmpargument = 8
            PlayFullSound
            tmpargument = 4          
            SendMessage
          Else                      //Failed, repeat the "quest"
            tmpargument = 2
            SetContent
            tmpargument = 6
            PlayFullSound
            tmpargument = 2          
            SendMessage
            
        //Wait before talking again
        tmpargument = 1
        SetState
        tmpargument = 140
        SetTime

//------------------------------------------------------------------------------
//Main AI loop
IfTimeOut
  tmpargument = 30
  SetTime
  IfStateIs0
    SetTargetToNearbyEnemy
      IfHoldingMeleeWeapon          //Attack enemies
        IfFacingTarget
          tmpx = targetdistance
          tmpy = 200
          IfXIsLessThanY
            PressLatchButton
      Else
        tmpargument = LATCHPACKRIGHT
        PressLatchButton
      tmpx = targetx
      tmpy = targety
    Else
      tmpx = selfspawnx             //Stand still
      tmpy = selfspawny
    ClearWaypoints
    AddWaypoint
  Else
    tmpargument = 0             //Reset talking
    SetState
//------------------------------------------------------------------------------
//Show where you are on the map
tmpx = selfx
tmpy = selfy
tmpargument = YELLOW
ShowBlipXY

//------------------------------------------------------------------------------
// ZZ> Handle death by sending a message and other stuff
IfKilled
  tmpargument = 2
  PlaySound
  tmpargument = 0
  SendMessage

  // Drop goodies
  tmpargument = selfmoney
  DropMoney

  // Make the character body
  tmpargument = 45
  SetBumpHeight

//------------------------------------------------------------------------------
// ZZ> Handle being attacked by blocking or countering or running away
IfAttacked
  tmpargument = rand & 1 + 3
  PlaySound

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