ON INIT {
 SET §time 0
 SETEVENT CHAT OFF
 SET £friend "goblin_earth"
 SET £voice "_vb" 
 IF (§revived == 1) ACCEPT
 IF (#air_clan_dead == 2) {
   IF (#water_clan_dead == 2) {
     PHYSICAL ON
     SET §enemy 1
     SET §revived 1
     TELEPORT MARKER_0709
     ACCEPT
   }
  ACCEPT
 }
 ACCEPT
}

ON PLAYER_ENEMY {
 IF (§time == 1) ACCEPT
 SET §time 1
 SENDEVENT CUSTOM Trolley_0001 "COLLIDE"
 ACCEPT
}

ON ATTACK_PLAYER {
 IF (§time == 1) ACCEPT
 SET §time 1
 SENDEVENT CUSTOM Trolley_0001 "COLLIDE"
 ACCEPT
}

ON INITEND {
 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 WAIT "Goblin_misc_eatrat"
 LOADANIM ACTION3 "goblin_normal_sit_in"
 LOADANIM ACTION4 "goblin_normal_sit_cycle"
 SETWEAPON AXE
     INVENTORY DESTROY
     INVENTORY CREATE
    INVENTORY ADD "PROVISIONS\\RIBS_COOKED_MINI\\RIBS_COOKED_MINI"
      INVENTORY ADDMULTI "JEWELRY\\GOLD_COIN\\GOLD_COIN" 7
 RANDOM 50 {
    INVENTORY ADD "JEWELRY\\GOLD_COIN\\GOLD_COIN"
}
 RANDOM 30 {
    INVENTORY ADD "PROVISIONS\\BOTTLE_WINE\\BOTTLE_WINE"
}
 RANDOM 30 {
    INVENTORY ADD "PROVISIONS\\BREAD_HALF\\BREAD_HALF"
}
 INVENTORY ADDMULTI "JEWELRY\\GOLD_COIN\\GOLD_COIN" 23
 INVENTORY ADD "PROVISIONS\\TORCH\\TORCH"
// INVENTORY ADD "ARMOR\\CHEST_LEATHER\\CHEST_LEATHER"
// INVENTORY ADD "ARMOR\\LEGGING_LEATHER\\LEGGING_LEATHER"
// SENDEVENT -ir DURABILITY 100 "29"
// SENDEVENT -ir DURABILITY_ARMOR 100 "31"
 SET §fooled 0
 SET §zone_ok 0
 SET §frozen 1
 PHYSICAL OFF
 SET §chatpos 2
 SET §reflection_mode 0   
 ATTACH rat_base_dead2_0001 "action point" SELF "primary_attach"
 SET £attached_object "rat_base_dead2_0001"
 ACCEPT
} 

ON RELOAD {
  IF (§revived == 1) ACCEPT
  IF (#air_clan_dead == 2) {
    IF (#water_clan_dead == 2) {
      REVIVE
      SET §enemy 1 
      ACCEPT
    }
   ACCEPT
  }
 ACCEPT
}

ON CHAT {
  IF (§enemy == 1) ACCEPT
  IF (^speaking == 1) ACCEPT
  IF (§chatpos == 2) GOTO dialogue1_1
  IF (§chatpos == 4) {
   IF (§fooled == 0) {
    IF (#treasure_gob_found == 2) {
     CINEMASCOPE -s ON
     PLAYERINTERFACE -s HIDE
     SETPLAYERCONTROLS OFF
    }
   }
   SPEAK [Goblin_good_ally_misc_earth_vb] GOTO TREASURE_FOUND
   ACCEPT
  }
 ACCEPT
}

>>TREASURE_FOUND
 IF (§fooled == 1) ACCEPT
 IF (#treasure_gob_found == 2) {
  SENDEVENT CUSTOM Goblin_base_0029 "TREASURE" 
  SET §fooled 1
  ACCEPT
 }
 ACCEPT
   
ON CUSTOM {
 IF (^$PARAM1 == "ALLY") SET §chatpos 4
 IF (^$PARAM1 == "EATFISH") GOTO dialogue2_4 
 IF (^$PARAM1 == "FOOLED") SET §fooled 1
 IF (^$PARAM1 == "EARTHZONE2") SET_CONTROLLED_ZONE EARTHZONE2 
 ACCEPT
}

>>dialogue1_1
 IF (#water_clan_dead == 2) {
  CINEMASCOPE -s ON
  PLAYERINTERFACE -s HIDE
  SETPLAYERCONTROLS OFF
 }
 SPEAK [Goblin_misc_you_kill_water_vb] GOTO dialogue1_2
 ACCEPT 

>>dialogue1_2
 IF (#water_clan_dead == 2) {
   SPEAK -p [player_yes] GOTO dialogue1_3
   ACCEPT
 }
 SPEAK -p [player_not_yet] nop
 SET_CONTROLLED_ZONE EARTHZONE2
 ACCEPT

>>dialogue1_3
 SENDEVENT CUSTOM Goblin_base_0029 "ALLY"
 SET §chatpos 4
 ACCEPT

>>dialogue2_4
 SPEAK -ou [Goblin_eat_fish] GOTO dialogue2_5
 ACCEPT

>>dialogue2_5
 IF (#water_clan_dead == 2) GOTO dialogue2_6 
 SPEAK -pu [player_sounds_interesting] GOTO dialogue2_6
 ACCEPT

>>dialogue2_6
 SET #SHUT_UP 0
 CAMERA_ACTIVATE NONE
 SETEVENT CHAT ON
 QUEST [system_Quest_earth_clan] PLAY SYSTEM
 HEROSAY [system_questbook_updated]
 SET §reflection_mode 1
 IF (#water_clan_dead == 2) { 
  SENDEVENT CUSTOM GOBLIN_BASE_0029 "DONE"
  ACCEPT
 }
 IF (#water_clan_dead == 0) SET #water_clan_dead 1
 PLAYER_INTERFACE -s SHOW
 CINEMASCOPE -s OFF
 SET_PLAYER_CONTROLS ON
 SET §reflection_mode 1
 SENDEVENT REFLEXION goblin_base_0029 ""   
 ACCEPT

ON DIE {
 SENDEVENT CUSTOM barrel_0004 "EARTHDEAD"
 ACCEPT
}

ON TELEPORTE {
 LOADANIM WAIT "Goblin_normal_wait"
 TELEPORT marker_0436
 BEHAVIOR FRIENDLY
 SETTARGET marker_0438
 SET §zone_ok 1 
 SET_CONTROLLED_ZONE EARTHZONE
 ACCEPT
}

ON CONTROLLEDZONE_ENTER {
 IF (^$PARAM1 != PLAYER) ACCEPT
 IF (^$PARAM2 == EARTHZONE) {
  IF (§zone_ok == 0) ACCEPT
  UNSET_CONTROLLED_ZONE EARTHZONE
  SET §frozen 0
  BEHAVIOR MOVE_TO 
  SETTARGET MARKER_0437 
  LOADANIM WAIT "Goblin_misc_eatrat"
  ACCEPT
 }
 IF (^$PARAM2 == EARTHZONE2) {
  SENDEVENT TELEPORTE SELF ""
  UNSET_CONTROLLED_ZONE EARTHZONE2
  ACCEPT
 }
 ACCEPT
}

ON REACHEDTARGET {
  IF (^target == NONE) ACCEPT
  IF (^target == marker_0437) { 
    BEHAVIOR FRIENDLY
    SETTARGET MARKER_0435
    SET §frozen 1
    ACCEPT
  }
 ACCEPT
}

ON OUCH {
 DETACH rat_base_dead2_0001 SELF
 SET £attached_object "NONE"
 ACCEPT
}

ON ATTACK_PLAYER {
 DETACH rat_base_dead2_0001 SELF
 SET £attached_object "NONE"
 ACCEPT
}