ON INIT {
  SETEVENT CHAT OFF
  SET §xpgiven 0
  SET £friend "goblin_earth"
  IF (§revived == 1) ACCEPT
  IF (#air_clan_dead == 2) {
    IF (#water_clan_dead == 2) {
      SET §enemy 1
      SET §revived 1
      TELEPORT MARKER_0710
      ACCEPT
    }
   ACCEPT
  }
 ACCEPT
}

ON INITEND {
 SET_SPEAK_PITCH 1.1
 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 WAIT2 "Goblin_misc_barbecue"
 PLAYANIM -l WAIT2
 ATTACH rat_base_dead3_0001 "primary_attach" SELF "primary_attach"
 SET £attached_object "rat_base_dead3_0001"
 SET §fooled 0
 SET §frozen 1
 SET §reflection_mode 0
      INVENTORY ADDMULTI "JEWELRY\\GOLD_COIN\\GOLD_COIN" 3
 RANDOM 50 {
    INVENTORY ADD "JEWELRY\\GOLD_COIN\\GOLD_COIN"
}
 RANDOM 30 {
    INVENTORY ADD "PROVISIONS\\BOTTLE_WINE\\BOTTLE_WINE"
}
 SENDEVENT -ir DURABILITY 100 "9"
 SET_CONTROLLED_ZONE GOB_AIR_EXIT1
 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 CUSTOM {
  IF (^$PARAM1 ==  "DONE") GOTO dialogue3_2
  IF (^$PARAM1 == "ALLY") {
    SPEAK [Goblin_good_ally_treasure] GOTO MAP
    ACCEPT
  }
 IF (^$PARAM1 == "TREASURE") GOTO dialogue4_1
 IF (^$PARAM1 == "FOOLED") SET §fooled 1
 IF (^$PARAM1 == "XPGIVEN") SET §xpgiven 1
 ACCEPT
}

>>MAP
    CINEMASCOPE -s OFF
    PLAYERINTERFACE -s SHOW
    SETPLAYERCONTROLS ON
    MAPMARKER 183 194 7 [addmarker_treasure_gob]
    HEROSAY [system_map_updated]
    SET #treasure_gob_found 1
    SET §chatpos 4
    SENDEVENT TADA PLAYER ""
    IF (§xpgiven == 0) {
     SET §xpgiven 1
     QUEST [system_Quest_earth_clan_done]
     HEROSAY [system_questbook_updated]
     ADD_XP 1000
     ACCEPT
    }
 ACCEPT

ON _ONTROLLEDZONE_ENTER {
  IF (^$param1 != PLAYER) ACCEPT
   IF (^$param2 == GOB_AIR_EXIT1) {
    UNSET_CONTROLLED_ZONE GOB_AIR_EXIT1
    GOTO dialogue1_1
    ACCEPT
   }
   IF (^$param2 == EARTHZONE) {
    UNSET_CONTROLLED_ZONE EARTHZONE
    GOTO dialogue2_1 
    ACCEPT
   } 
 ACCEPT
}

ON CHAT {
  IF (§enemy == 1) ACCEPT
  IF (^speaking == 1) ACCEPT
  IF (§chatpos == 3) {
   CINEMASCOPE -s ON
   SETPLAYERCONTROLS OFF
   PLAYERINTERFACE -s HIDE
   GOTO dialogue3_1
   ACCEPT
  }
  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] GOTO TREASURE_FOUND
   ACCEPT
  }
 ACCEPT
}

>>TREASURE_FOUND
 IF (§fooled == 1) ACCEPT
 IF (#treasure_gob_found == 2) {
  GOTO dialogue4_1
  ACCEPT
 }
 GOTO ENDC
 ACCEPT

>>dialogue1_1
 SPEAK [Goblin_go_tavern] SENDEVENT CUSTOM Goblin_base_0031 "TALK1" SET §chatpos 1
 SET_CONTROLLED_ZONE EARTHZONE 
 SET §chatpos 1
 ACCEPT

>>dialogue2_1
 SET #SHUT_UP 1
 SET_PLAYER_CONTROLS OFF
 PLAYER_LOOKAT MARKER_0435
 PLAYER_INTERFACE -s HIDE
 CINEMASCOPE -s ON
 SETEVENT CHAT ON
 SPEAK -pu [player_what_doing_here] GOTO dialogue2_2
 ACCEPT

>>dialogue2_2
 SPEAK -u [Goblin_we_earth_clan] GOTO dialogue2_3
 ACCEPT

>>dialogue2_3
 SPEAK -puo [player_why_hate] SENDEVENT CUSTOM Goblin_base_0030 "EATFISH"
 SENDEVENT CINEMATIC CAMERA_0081 ""
 SET §chatpos 3
 SENDEVENT CUSTOM Goblin_base_0031 "GOTOBED"
 ACCEPT

>>dialogue3_1
 SPEAK [Goblin_misc_you_kill_water] GOTO dialogue3_2
 ACCEPT 

>>dialogue3_2
 IF (#water_clan_dead == 2) {
   SPEAK -p [player_yes] GOTO dialogue3_3
   ACCEPT
 }
 SPEAK -p [player_not_yet] nop
 SETPLAYERCONTROLS ON
 CINEMASCOPE -s OFF
 PLAYERINTERFACE -s SHOW
 SENDEVENT CUSTOM Goblin_base_0030 "EARTHZONE2" 
 ACCEPT

>>dialogue3_3
 SPEAK [Goblin_good_ally_treasure] GOTO dialogue4_4
 ACCEPT

>>dialogue4_4
 IF (§xpgiven == 0) {
   SET §xpgiven 1
   QUEST [system_Quest_earth_clan_done]
   HEROSAY [system_questbook_updated]
   ADD_XP 1000
 }
 SENDEVENT TADA PLAYER ""
 SENDEVENT CUSTOM Goblin_base_0030 "ALLY"
 MAPMARKER 183 194 7 [addmarker_treasure_gob]
 HEROSAY [system_map_updated]
 SET #treasure_gob_found 1
 SET §chatpos 4
 SET §reflection_mode 1
 SETPLAYERCONTROLS ON
 CINEMASCOPE -s OFF
 PLAYERINTERFACE -s SHOW
 ACCEPT 

>>dialogue4_1
 SET §fooled 1
 SENDEVENT CUSTOM Goblin_base_0030 "FOOLED"
 SENDEVENT CUSTOM Goblin_base_0031 "FOOLED"
 SPEAK -p [player_fooled_treasure] GOTO dialogue4_2
 ACCEPT 

>>dialogue4_2
 SPEAK [Goblin_you_silly] GOTO ENDC
 ACCEPT

>>ENDC
 CINEMASCOPE -s OFF
 PLAYERINTERFACE -s SHOW
 SETPLAYERCONTROLS ON
 ACCEPT

ON DIE {
 SENDEVENT CUSTOM barrel_0004 "EARTHDEAD"
 ACCEPT
}

ON REFLEXION {
 SET §reflection_mode 1
ACCEPT
}

ON OUCH {
 DETACH rat_base_dead3_0001 SELF 
 SET £attached_object "NONE"
 SENDEVENT HIDE rat_base_dead3_0001 ""
 ACCEPT
}

ON ATTACK_PLAYER {
 DETACH rat_base_dead3_0001 SELF 
 SET £attached_object "NONE"
 SENDEVENT HIDE rat_base_dead3_0001 ""
 ACCEPT
}

ON DOUSED { 
 IF (§enemy == 1) ACCEPT
 IF (§revived == 1) ACCEPT
 TIMERignit -i 1 2 SPELLCAST -msf 10 IGNIT FIRE_CAMP_0005 
 ACCEPT
}

ON CONTROLLEDZONE_ENTER {
 IF (§enemy == 1) ACCEPT
  IF (^$param1 != PLAYER) ACCEPT
   IF (^$param2 == GOB_AIR_EXIT1) {
    UNSET_CONTROLLED_ZONE GOB_AIR_EXIT1
    GOTO dialogue1_1
    ACCEPT
   }
   IF (^$param2 == EARTHZONE) {
    UNSET_CONTROLLED_ZONE EARTHZONE
    GOTO dialogue2_1 
    ACCEPT
   } 
 ACCEPT
}