ON INIT {
 SET §status 0				// Used to check scenaric point
 SET £friend "kingdom"
 SET £type "human_guard_kingdom"
 SET £KEY_CARRIED "portcullis"
 SET §sleeping 0				// Check npc is sleeping and player cannot talk to him
 SET £voice "_vb"
 SET §up 0
 ACCEPT
}

ON INITEND {
 LOADANIM ACTION5 "human_normal_sit_cycle"
 LOADANIM ACTION6 "human_normal_drink_cycle"
 LOADANIM TALK_ANGRY "human_talk_angry_toponly"
 ATTACH MUG_0021 "BEER_ATTACH" SELF "left_attach"
 SET £attached_object "MUG_0021"
 SET §frozen 1
 PHYSICAL OFF
 COLLISION OFF
 PLAYANIM -l ACTION5
 SENDEVENT -ir DURABILITY 100 "90"
 TIMERdrink 0 18 GOTO DRINK
 ACCEPT
}

ON REACHEDTARGET {
  IF (^TARGET == MARKER_0065) {
    BEHAVIOR MOVE_TO
    SETTARGET MARKER_0064
    ACCEPT
  }
  IF (^TARGET == MARKER_0063) {
    BEHAVIOR NONE
    SETTARGET NONE
    TIMERpatrol 1 2 GOTO NEXT_STEP 
    ACCEPT
  }
  IF (^TARGET == MARKER_0064) {
    BEHAVIOR NONE
    SETTARGET NONE
    TIMERpatrol 1 2 GOTO NEXT_STEP01
    ACCEPT
  }
 ACCEPT
}

>>NEXT_STEP
  IF (§main_behavior_stacked != 0) {
    TIMERpatrol01 1 2 GOTO NEXT_STEP
  }
  ELSE {
    BEHAVIOR MOVE_TO
    SETTARGET MARKER_0064
  }
 ACCEPT

>>NEXT_STEP01
  IF (§main_behavior_stacked != 0) {
    TIMERpatrol02 1 2 GOTO NEXT_STEP01
  }
  ELSE {
    BEHAVIOR MOVE_TO
    SETTARGET MARKER_0063
  }
 ACCEPT

ON CINEMATIC {
  IF (§status == 3) {
    SET §status 4
    SENDEVENT CUSTOM HUMAN_BASE_0039 "STARTLAUGH"
    ACCEPT
  }
 ACCEPT
}

ON CHANGESTATUS {
  IF (^$PARAM1 == "3") {
    IF (§enemy == 1) ACCEPT
    SET §up 1
    TIMERdrink OFF
    PLAYANIM NONE
    PLAYANIM -2 NONE
    DETACH MUG_0021 SELF
    SET £attached_object "NONE"
    PHYSICAL ON
    TELEPORT MARKER_0074
    SET §sleeping 1
    SET §status 3
    SET §reflection_mode 0
    SETEVENT CHAT OFF
    FORCE_ANGLE 270
    SET §frozen 1
    PLAYANIM -l ACTION3
    ACCEPT
  }
  IF (^$PARAM1 == "5") {
    IF (§enemy == 1) ACCEPT
    SET §up 1
    TIMERdrink OFF
    PHYSICAL ON
    COLLISION ON
    PLAYANIM NONE
    PLAYANIM -2 NONE
    SET §sleeping 0
    SET §frozen 0
    TELEPORT MARKER_0850
    FORCE_ANGLE 0
    SET §status 5
    ACCEPT
  } 
 ACCEPT
}

ON CHAT {
  IF (^SPEAKING == 1) ACCEPT
  IF (§sleeping == 1) {
    SPEAK [human_guard_tryingto_sleep] NOP 
    REFUSE
  }
 ACCEPT
}

ON CUSTOM {
  IF (§enemy == 1) ACCEPT
  IF (^$PARAM1 == "GO") {
    TIMERdrink OFF
    DETACH MUG_0021 SELF
    SET £attached_object "NONE"
    PHYSICAL ON
    COLLISION ON
    SET §frozen 0
    PLAYANIM NONE
    PLAYANIM -2 NONE
    BEHAVIOR FRIENDLY
    SETTARGET PLAYER
    TELEPORT MARKER_0338
    BEHAVIOR MOVE_TO
    SETTARGET -a MARKER_0103
    ACCEPT
  }
  IF (^$PARAM1 == "TALK") {
    SPEAK [guard_sleep_2_goodnight] SENDEVENT CUSTOM HUMAN_BASE_0038 "TALK1"
    ACCEPT
  }
  IF (^$PARAM1 == "TALK1") {
    SPEAK [guard_2_ohno] SENDEVENT CUSTOM HUMAN_BASE_0038 "TALK2"
    ACCEPT
  }
  IF (^$PARAM1 == "TALK2") {
    SPEAK [guard_2_ohno2] SENDEVENT CUSTOM HUMAN_BASE_0038 "TALK3"
    ACCEPT
  }
  IF (^$PARAM1 == "TALK3") {
    SPEAK [guard_2_whistle] SENDEVENT CUSTOM HUMAN_BASE_0038 "TALK4"
    ACCEPT
  }
  IF (^$PARAM1 == "TALK4") {
    SPEAK [guard_2_happy] TIMERsleep 1 2 SENDEVENT CUSTOM HUMAN_BASE_0038 "TALK5"
    ACCEPT
  }
  IF (^$PARAM1 == "TALK5") {
    SPEAK [guard_2_ohno3] NOP
    ACCEPT
  }
  IF (^$PARAM1 == "WAKE_UP") {
    BEHAVIOR FRIENDLY
    SETTARGET HUMAN_BASE_0038
    SPEAK -a [guard_2_angry] SENDEVENT CUSTOM HUMAN_BASE_0038 "WAKE_UP2"
    ACCEPT
  }
  IF (^$PARAM1 == "WAKE_UP2") {
    BEHAVIOR FRIENDLY
    SETTARGET HUMAN_BASE_0038
    SPEAK [guard_2_angry_2] SENDEVENT CUSTOM HUMAN_BASE_0040 "WAKE_UP"
    ACCEPT
  }
  IF (^$PARAM1 == "WAKE_UP3") {
    BEHAVIOR FRIENDLY
    SETTARGET HUMAN_BASE_0038
    SPEAK [guard_2_angry_3] GOTO ENDPATROL
    BEHAVIOR MOVE_TO
    SETTARGET -a MARKER_0065
    SETEVENT CHAT ON
    ACCEPT
  }
 ACCEPT
}

>>ENDPATROL
 SENDEVENT CUSTOM HUMAN_BASE_0038 "PATROL"
 SENDEVENT CUSTOM HUMAN_BASE_0039 "PATROL"
 SENDEVENT CUSTOM HUMAN_BASE_0040 "PATROL"
 WORLDFADE OUT 1000 0 0 0
 TIMERpat 1 1 GOTO TELEPORT
 ACCEPT

>>TELEPORT
 TELEPORT MARKER_0064
 TIMERlook -m 1 10 PLAYERLOOKAT LIGHT_DOOR_0090
 TELEPORT -p MARKER_0938
 WORLDFADE IN 2500
 CINEMASCOPE -s OFF
 PLAYER_INTERFACE -s SHOW
 SET_PLAYER_CONTROLS ON
 ACCEPT

>>DRINK
 IF (§up == 1) ACCEPT
 PLAYANIM -2e ACTION6 GOTO DRINK2
 ACCEPT

>>DRINK2
 IF (§up == 1) ACCEPT
 PLAYANIM -2e NONE PLAYANIM -l ACTION5
 ACCEPT