//------------------------------------------------------------------------------
IfSpawned
  Sneak				//Dont run around
  tmpargument = STATEGUARD
  SetState
  
//------------------------------------------------------------------------------
IfHealed
  tmpargument = 7
  SendMessageNear

//------------------------------------------------------------------------------
// Get mean if characters wanna be bad
IfAttacked
  Run
  SetTargetToWhoeverAttacked
  IfTargetIsAPlayer
    CallForHelp
    tmpargument = TEAME     //Team Evil
    TargetJoinTeam
    tmpargument = STATECOMBAT
    SetState
  tmpargument = rand & 1 + 3
  PlaySound
IfKilled
  CallForHelp			//Warn friends
  IfTargetIsAPlayer
    tmpargument = TEAME
    TargetJoinTeam
  tmpargument = 0
  SendMessageNear

//------------------------------------------------------------------------------
// ZZ> Handle normal state
IfTimeOut
  tmpargument = 50
  SetTime

  //WAIT AND TALK
  IfStateIsGuard
    SetTargetToNearbyEnemy		//Enemy near, go combat mode
      tmpargument = STATECOMBAT
      SetState
      CallForHelp
    Else
      tmpx = selfspawnx
      tmpy = selfspawny
      ClearWaypoints
      AddWaypoint

      //Reduce that counter
      tmpx = selfcontent
      tmpy = 0
      IfXIsMoreThanY
        tmpargument = selfcontent - 1
        SetContent
      
      //Cry out to attract buyers
      tmpdistance = BLAHFRIENDS
      tmpargument = [HUMA]
      SetTargetToNearestBlahID
        tmpx = targetdistance
        tmpy = 550
        IfXIsLessThanY
          SetTurnModeToWatchTarget
          tmpargument = 0
          IfContentIs
            tmpargument = 2
            SendMessageNear
            PlaySound
            tmpargument = 8   //Wait 8 seconds before doing again
            SetContent
            
            //Animate
            tmpargument = ACTIONMC
            DoAction
        Else
          SetTurnModeToVelocity
          
  //Run away in panic
  IfStateIsCombat
    Run
    SetTargetToNearbyEnemy
      CallForHelp

    tmpx = rand % 3000 + selfx - 1500
    tmpy = rand % 3000 + selfy - 1500
    ClearWaypoints
    AddWaypoint
    tmpargument = 75
    SetTime
    
    //Return to shopkeeping mode if everything seems normal again
    SetTargetToNearestEnemy
      tmpx = targetdistance
      tmpy = 128*16
      IfXIsMoreThanY
        tmpargument = STATEGUARD
        SetState        
    

//------------------------------------------------------------------------------
//What to do if bumped
IfBumped
  IfStateIsGuard
    SetTargetToWhoeverBumped
    tmpx = selfcontent
    tmpy = 6
    IfXIsLessThanY
      tmpargument = 2
      SendMessageNear
      PlaySound
      tmpargument = 12
      SetContent

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