IfTimeOut
  tmpargument = rand & 15 + 25
  SetTime
  
  //Watch the player
  IfStateIs0
    SetTargetToNearestEnemy
      SetTurnModeToWatchTarget

  //This wins the module
  IfStateIs1
    Sneak
    SetTargetToNearestFriend
    tmpx = targetx
    tmpy = targety
    ClearWaypoints
    AddWaypoint

    //Allow rogues to kill him
    tmpargument = 0
    IfContentIs
      tmpargument = [ROGU]
      tmpdistance = 15
      SetTargetToNearestBlahID
        JoinEvilTeam
        tmpargument = 1
        SetContent
        ChangeArmor		//Allow to die

    IfBumped
      SetTargetToWhoeverBumped
      tmpargument = 1
      IfContentIs
        tmpargument = 3
        SendMessage
        tmpargument = 2
        SetContent
      Else
        EnableExport
        BeatModule
        tmpargument = [MAIN]
        tmpdistance = 8
        AddQuestAllPlayers

        //Say goodbye
        tmpargument = 0
        SendMessage
        tmpargument = 1
        SendMessage

        //Become invincible (just in case)
        tmpargument = 0
        ChangeArmor

        tmpargument = 3
        PlayFullSound

        tmpargument = 2
        SetState

        tmpargument = [BEAT]
        AddIDSZ

//Free!
IfOrdered
  tmpx = selforder
  tmpy = [FREE]
  IfXIsEqualToY
    tmpargument = 1
    SetState
    JoinGoodTeam
    BeatModule
    
    //Credits
    ClearEndMessage
    tmpargument = 5
    AddEndMessage
    tmpargument = 6
    AddEndMessage
    tmpargument = 7
    AddEndMessage
    tmpargument = 8
    AddEndMessage
    tmpargument = 9
    AddEndMessage
    tmpargument = 10
    AddEndMessage
    tmpargument = 11
    AddEndMessage
    tmpargument = 12
    AddEndMessage
    tmpargument = 13
    AddEndMessage
    tmpargument = 14
    AddEndMessage
    tmpargument = 15
    AddEndMessage
    tmpargument = 16
    AddEndMessage
    tmpargument = 17
    AddEndMessage
    tmpargument = 18
    AddEndMessage
    tmpargument = 19
    AddEndMessage
    tmpargument = 20
    AddEndMessage
    tmpargument = 21
    AddEndMessage
    tmpargument = 22
    AddEndMessage
    tmpargument = 23
    AddEndMessage
    tmpargument = 24
    AddEndMessage
    tmpargument = 25
    AddEndMessage
    tmpargument = 26
    AddEndMessage
    
//Rogue revenged himself
IfKilled
  tmpargument = 1000
  tmpdistance = EXPMURDER
  GiveExperienceToGoodTeam

  tmpargument = [ROGU]
  tmpdistance = 15
  SetTargetToNearestBlahID
    tmpargument = 2
  Else
    tmpargument = 4
  SendMessage
  tmpargument = 2
  PlayFullSound

  EnableExport
  BeatModule
  tmpargument = [MAIN]
  tmpdistance = 8
  AddQuestAllPlayers

  tmpargument = [BEAT]
  AddIDSZ

End
