ON INIT {
 SET_SPEAK_PITCH 0.85
 SET £friend "goblin_earth"
 IF (§revived == 1) ACCEPT
 IF (#air_clan_dead == 2) {
  IF (#water_clan_dead == 2) {
   INVENTORY ADD "PROVISIONS\\TORCH\\TORCH"
   SET §enemy 1
   SET §revived 1
   TELEPORT MARKER_0711
   ACCEPT
  }
  ACCEPT
 }
 ACCEPT
}
ON INITEND {
 SET_SPEAK_PITCH 0.9
 IF (§revived == 1) ACCEPT
 TWEAK SKIN "npc_Goblin_base_body" "npc_Goblin_grey_body"
 TWEAK SKIN "npc_Goblin_base_head" "npc_Goblin_grey_head"
 LOADANIM ACTION2 "Goblin_normal_lay_in"
 LOADANIM ACTION3 "Goblin_normal_lay_cycle"
 SET §fooled 0
 BEHAVIOR NONE
 SETTARGET NONE
 SENDEVENT -ir DURABILITY 100 "11"
 SET §reflection_mode 0
 ACCEPT
}
 
ON RELOAD {
  IF (§revived == 1) ACCEPT
  IF (#air_clan_dead == 2) {
   IF (#water_clan_dead == 2) {
    REVIVE 
    SET §enemy 1
    ACCEPT
   }
   ACCEPT
  }
 IF (§enemy == 1) ACCEPT
 IF (#treasure_gob_found == 2) {
  GOTO CHASE
  SET §sleeping 0
  ACCEPT
}

ON CUSTOM {
 IF (^$PARAM1 == "ALLY") SET §chatpos 4
 IF (^$PARAM1 == "FOOLED") SET §fooled 1
 IF (^$PARAM1 == "TALK1") {
  IF (#SHUT_UP == 0) SPEAK [Goblin_not_now] nop
  ACCEPT
 }
 IF (^$PARAM1 == "GOTOBED") {
  HEROSAY -d "goblin go to bed now"
  SET §chatpos 2
  BEHAVIOR MOVE_TO
	HERO_SAY -d "move_to"
  SETTARGET MARKER_0434
	HERO_SAY -d "settarget"
  ACCEPT
 }
 ACCEPT
}

ON REACHEDTARGET {
	HEROSAY -d "goblin au dodo"
 IF (^target == NONE) ACCEPT
 IF (^target == marker_0434) {
  SET §reflection_mode 0
  FORCE_ANGLE 320
  PLAYANIM -e ACTION2 PLAYANIM -l ACTION3
  SET §sleeping 1
  SET §frozen 1
  //COLLISION OFF
  ACCEPT
  }
ACCEPT
}

ON DIE {
 SENDEVENT CUSTOM barrel_0004 "EARTHDEAD"
 ACCEPT
}

ON CHAT {
  IF (§enemy == 1) ACCEPT
  IF (^speaking == 1) ACCEPT
  IF (§sleeping == 1) ACCEPT
  BEHAVIOR STACK
  BEHAVIOR FRIENDLY
  SETTARGET PLAYER
  IF (§chatpos == 4) {
   SPEAK [Goblin_good_ally_misc_earth_vb] BEHAVIOR UNSTACK
   ACCEPT
  }
 ACCEPT
}

ON CHASE {
 TELEPORT MARKER_0447
 SET §sleeping 0
 SET §frozen 0
 COLLISION ON
 SET §reflection_mode 0    
 PLAYANIM NONE
 BEHAVIOR -f MOVE_TO
 SETTARGET RAT_BASE_0086
 SETMOVEMODE RUN
 ACCEPT
}

ON TARGET_DEATH {
 BEHAVIOR MOVE_TO
 SETTARGET MARKER_0434
 SETMOVEMODE WALK
 REFUSE
}