#                                                                G+D  v.Final  |  11/06/2020
###############################################
start_tasks = '10:40'

# 1/0 | enable/disable
ignore_hunt = 0
hunt_spot = (32741, 32337, 8)

# 1/0 | enable/disable
get_adamantines = 1

# Write the same amount as in "HUNT UNTIL".
stamina_low = '14:00'
###############################################
###############################################
###############################################
###############################################
###############################################
###############################################
###############################################
###############################################
###############################################
###############################################
###############################################
###############################################
###############################################
###############################################
###############################################
# Waypoints sets
hunt = 0
to_d_base_one = 1
to_buya = 2
to_planima = 3
to_fal_kon = 4
to_kalamon = 5
to_elvira = 6
to_crimson = 7
to_gorgon = 8
gorgon = 9
to_crimson_done = 10
to_petraclops = 11
petraclops = 12
to_kalamon_done = 13
to_darktaur = 14
darktaur = 15
to_elvira_done = 16
to_observer = 17
observer = 18
to_fal_kon_done = 19
to_zealot = 20
zealot = 21
to_planima_done = 22
to_forgotten = 23
forgotten = 24
to_buya_done = 25
to_d_base_two = 26
to_hunt = 27
welcome = 28

# Npcs Gorgoros
kalamon = (32703, 31756, 8)
elvira = (32651, 31767, 7)
crimson = (32666, 31771, 14)
# Npcs Doratia
buya = (32417, 32035, 10)
planima = (32460, 31987, 8)
fal_kon = (32434, 31981, 8)

# Spots Gorgoros
gorgon_spot_base = (32658, 31777, 13)
gorgon_spot_back = (32658, 31770, 13)
gorgon_spot_continue = (32624, 31783, 13)
petraclops_spot_base = (32655, 31767, 12)
petraclops_spot_back = (32645, 31728, 12)      
petraclops_spot_continue = (32662, 31767, 12)
petraclops_spot_exit = (32652, 31714, 12)         
darktaur_spot_base = (32649, 31730, 8)
darktaur_spot_exit = (32648, 31756, 8)
darktaur_spot_back = (32652, 31756, 8)
darktaur_spot_continue = (32644, 31730, 8)
# Spots Doratia
doratia_base = (32433, 32028, 10)
observer_spot_base = (32436, 31978, 9)
observer_spot_back = (32436, 31977, 9)
observer_spot_continue = (32378, 31989, 9)
observer_spot_fast_exit = (32414, 31976, 8)
zealot_spot_base = (32458, 32008, 7)
zealot_spot_exit = (32455, 32000, 7)
zealot_spot_back = (32465, 32008, 7)
zealot_spot_continue = (32492, 31993, 11)
forgotten_spot_base = (32463, 31988, 10)

# Hours
import datetime
from System import DateTime
stamina_empty = '00:00'
stamina_full = '56:00'

# Drops
dropItemsList = ('Pink dragon egg')
drop_items_by_id_list = (2593, 5199, 2594)
queue = {}

def onScriptActivation():
	script.ShowMessage('-If you only want to perform the tasks and ignore the hunting area, in \n tab script in "ignore_hunt", you should write 1. \n If instead, you want to go to the hunting area after completing the \n tasks, you should write 0.\n\n-In the tab of the script, you only have to configure the start time of the\n  tasks in "start_tasks" and configure the "spot" of the hunting area.\n\n-You shouldn\'t activate or deactivate the stamina system, the script will \n do it automatically. You can only modify "No login hours" and \n "Hunt until" (If you modify "hunt until", write the same amount of \n stamina in "stamina_low" in the script tab).\n\n-The stamina system is automatically activated when all tasks are\n completed and deactivated when you start them.\n\n-In the hunting area, if the stamina is less than "' + str(stamina_low) + '", it will be\n disconnected to recharge it and then continue hunting.\n\n-If you are in the hunting area Online/Offline, 20 minutes before the\n time you set to start the tasks, You will leave the hunting area to\n prepare to do the tasks.\n\n-If your stamina is less than "' + str(stamina_low) + '" at the end of the tasks, you will\n disconnect to recharge it and then go to the hunting area. If on the\n contrary it is too low and the time is greater than the beginning of the\n tasks of the next day, you will connect 1 minute before the time that\n you configured to start the tasks.\n\n-You must leave 1 space in the backpack at all times, to take the items\n you receive from the NPCs (Aggregator, Ornate mirror and Charm ward)\n that the BOT drops them.\n\n-On the script tab, in "get_adamantines" you must put 1/0\n (enable/diasable) to perform or not, the task of getting the\n adamantines.\n\n-If you want to deliver the eggs to Kalamon, leave 5 empty spaces in the\n backpack, and disable "Item Storage" for item 5257 (Adamantine).\n\n-If you do not want BOT to deliver the eggs, you can enable "Item\n Storage" for item 5257 (Adamantine).\n\n\nScript created by DemonLord', 'Script G+D | v.Final')
	script.StatusMessage('Start script G+D v.Final')
	script.IgnoreMonsters(0)
	script.SetVar('day', 0)
	script.SetVar('monster_quest', 0)
	script.SetVar('exit_hunt', 0)
	script.SetVar('message_count', 0)
	script.SetVar('message_back', 0)
	script.SetVar('message_hunt', 0)
	script.SetVar('message_finish', 0)
	script.SetVar('stam_low', 0)
	script.PZChecksForDrop(0)
	script.EnableTickEvent(500)
	script.SetVar('gorgon_done', 0)
   	script.SetVar('gorgon_back', 0)
	script.SetVar('gorgon_continue', 0)
	script.SetVar('petraclops_done', 0)
   	script.SetVar('petraclops_back', 0)
	script.SetVar('petraclops_continue', 0)
	script.SetVar('darktaur_done', 0)
	script.SetVar('darktaur_back', 0)
	script.SetVar('darktaur_continue', 0)
	script.SetVar('observer_done', 0)
   	script.SetVar('observer_back', 0)
	script.SetVar('observer_continue', 0)
	script.SetVar('zealot_done', 0)
   	script.SetVar('zealot_back', 0)
	script.SetVar('zealot_continue', 0)
	script.SetVar('forgotten_done', 0)

def onScriptDeactivation():
	script.IgnoreMonsters(0)
	script.StatusMessage('Stop script G+D v.Final')

def onQuestFinish():
	script.SetVar('exit_hunt', 0)
	script.SetVar('message_count', 0)
	script.SetVar('message_back', 0)
	script.SetVar('message_hunt', 0)
	script.SetVar('message_finish', 0)
	script.SetVar('gorgon_done', 0)
   	script.SetVar('gorgon_back', 0)
	script.SetVar('gorgon_continue', 0)
	script.SetVar('petraclops_done', 0)
   	script.SetVar('petraclops_back', 0)
	script.SetVar('petraclops_continue', 0)
	script.SetVar('darktaur_done', 0)
	script.SetVar('darktaur_back', 0)
	script.SetVar('darktaur_continue', 0)
	script.SetVar('observer_done', 0)
   	script.SetVar('observer_back', 0)
	script.SetVar('observer_continue', 0)
	script.SetVar('zealot_done', 0)
   	script.SetVar('zealot_back', 0)
	script.SetVar('zealot_continue', 0)
	script.SetVar('forgotten_done', 0)

def onTick():
	now = datetime.datetime(DateTime.Now)
	time = now.strftime("%H:%M")
	stam = script.GetStaminaText()
	number = script.GetVar('day')
	way = script.GetWay()
	x = script.GetX()
	y = script.GetY()
	z = script.GetZ()
	if ignore_hunt == 0:
		if way == to_d_base_two and x == doratia_base[0] and y == doratia_base[1] and z == doratia_base[2]:
			script.ToggleStaminaSystem(1, 1)
			if stam >= stamina_low and script.GetVar('stam_low') == 0:
				script.SetWay(to_hunt, 2)
				script.ShowMessage('Your stamina is high enough to go hunting area, up to "' + str(start_tasks) + '" hours.\n-Current time: ' + str(time) + '\n-Current stamina: ' + str(stam), 'FULL STAMINA')				
			if stam <= stamina_low and script.GetVar('stam_low') == 1:
				script.SetVar('stam_low', 0)
				script.ShowMessage('Your stamina is too low to go to the hunting area, when it is full and it is not yet "' + str(start_tasks) + '" hours, it will go to the hunting area.\n-Current time: ' + str(time) + '\n-Current stamina: ' + str(stam), 'LOW STAMINA')
		if script.IsItTime(start_tasks, -60, 1):
			if way == to_d_base_two:
				script.ToggleStaminaSystem(1, 0)
				script.SetWay(welcome, 2)
				script.ShowMessage('In less than 1 minute, you will begin the tasks.', 'WAIT')
		if way == to_d_base_one and x == doratia_base[0] and y == doratia_base[1] and z == doratia_base[2]:
			if script.GetVar('message_back') == 0:
				script.SetVar('message_back', 1)
				script.LogoutUntilEx(start_tasks, -65)
				script.SetWay(welcome, 2)
				script.ShowMessage('You\'ve already hunted enough, 1 minute before "' + str(start_tasks) + '" hours you will connect automatically and start the tasks.\n-Current time: ' + str(time) + '\n-Current stamina: ' + str(stam), 'HUNTING FINISHED')
		if time == start_tasks and script.GetVar('message_count') == 0:
			script.SetVar('message_count', 1)	
			script.SetWay(to_buya, 2)
			script.SetVar('day', number + 1)
			script.ShowMessage('-Consecutive days doing tasks: ' + str(number) + '\n-Current time: ' + str(time) + '\n-Current stamina: ' + str(stam), 'START TASKS')
		if script.IsItTime(start_tasks, -1200, 1):
			if way == hunt and script.GetVar('message_hunt') == 0:
				script.SetVar('message_hunt', 1)
				script.IgnoreMonsters(1)
				script.ToggleStaminaSystem(1, 0)
				script.SetVar('exit_hunt', 1)
				script.ShowMessage('In 20 minutes you will start the tasks. I will go to the island and I disconnect until 1 minute before "' + str(start_tasks) + '" hours.\n-Current time: ' + str(time) + '\n-Current stamina: ' + str(stam), 'LEAVING THE HUNTING AREA')
		if way == hunt and x == hunt_spot[0] and y == hunt_spot[1] and z == hunt_spot[2]:
			if script.GetVar('exit_hunt') == 1:
				script.SetWay(to_d_base_one, 2)
				script.StatusMessage('Leaving the hunting area')
				script.SetVar('exit_hunt', 0)
	if ignore_hunt == 1:
		if way == to_d_base_two and x == doratia_base[0] and y == doratia_base[1] and z == doratia_base[2]:
			script.LogoutUntilEx(start_tasks, -65)
			script.SetWay(welcome, 2)
			script.ShowMessage('Tomorrow you will connect one minute before "' + str(start_tasks) + '" hours.\n-Current time: ' + str(time) + '\n-Current stamina: ' + str(stam), 'COMPLETED TASKS')
		if time == start_tasks and script.GetVar('message_count') == 0:
			script.SetVar('message_count', 1)	
			script.SetWay(to_buya, 2)
			script.SetVar('day', number + 1)
			script.ShowMessage('-Consecutive days doing tasks: ' + str(number) + '\n-Current time: ' + str(time) + '\n-Current stamina: ' + str(stam), 'START TASKS')

def onDisconnect(info):
	way = script.GetWay()
	x = script.GetX()
	y = script.GetY()
	z = script.GetZ()
	if info == 'STAM' and way == to_d_base_two:
		script.SetVar('stam_low', 1)

def onReceiveItemDescription(itemId, name):
	if name in dropItemsList:
		return 1
	return 0

def checkDropQueue(x, y, z):
	if script.IsLocationFree(x, y, z) == 1:
		if len(queue) > 0:
			for slot, itemId in queue.items():
				if script.GetItemInSlot(slot) == itemId:
					if script.DropItem(slot, 0) == 'ok':
						queue.pop(slot)
						break
				else:
					queue.pop(slot)

def onChangeLocation(x, y, z):
	way = script.GetWay()
	checkDropQueue(x, y, z)
# Kalamon
	if way == to_kalamon and x == kalamon[0] and y == kalamon[1] and z == kalamon[2]:
		if script.GoToNpcEx('Kalamon'):
			script.StatusMessage('Hello Kalamon')
		else:
			script.StatusMessage('I can\'t find Kalamon')
			script.Alarm('I can\'t find Kalamon')
	elif way == to_kalamon_done and x == kalamon[0] and y == kalamon[1] and z == kalamon[2]:
		if script.GoToNpcEx('Kalamon'):
			script.StatusMessage('Hello Kalamon')
		else:
			script.StatusMessage('I can\'t find Kalamon')
			script.Alarm('I can\'t find Kalamon')
# Elvira
	elif way == to_elvira and x == elvira[0] and y == elvira[1] and z == elvira[2]:
		if script.GoToNpcEx('Elvira'):
			script.StatusMessage('Hello Elvira')
		else:
			script.StatusMessage('I can\'t find Elvira')
			script.Alarm('I can\'t find Elvira')
	elif way == to_elvira_done and x == elvira[0] and y == elvira[1] and z == elvira[2]:
		if script.GoToNpcEx('Elvira'):
			script.StatusMessage('Hello Elvira')
		else:
			script.StatusMessage('I can\'t find Elvira')
			script.Alarm('I can\'t find Elvira')
# Crimson
	elif way == to_crimson and x == crimson[0] and y == crimson[1] and z == crimson[2]:
		if script.GoToNpcEx('Crimson'):
			script.StatusMessage('Hello Crimson')
		else:
			script.StatusMessage('I can\'t find Crimson')
			script.Alarm('I can\'t find Crimson')
	elif way == to_crimson_done and x == crimson[0] and y == crimson[1] and z == crimson[2]:
		if script.GoToNpcEx('Crimson'):
			script.StatusMessage('Hello Crimson')
		else:
			script.StatusMessage('I can\'t find Crimson')
			script.Alarm('I can\'t find Crimson')
# Gorgon
	elif x == gorgon_spot_base[0] and y == gorgon_spot_base[1] and z == gorgon_spot_base[2]:
		if script.GetVar('gorgon_done') == 1:
			script.SetWay(to_crimson_done, 2)
	elif x == gorgon_spot_back[0] and y == gorgon_spot_back[1] and z == gorgon_spot_back[2]:
		script.SetVar('gorgon_back', 1)
		script.SetVar('gorgon_continue', 0)
	elif way == gorgon and script.GetVar('gorgon_back') == 1 and script.GetVar('gorgon_continue') == 0 and script.GetVar('gorgon_done') == 1:
		script.SetWay(gorgon, 1)
		script.SetVar('gorgon_back', 0)
		script.SetVar('gorgon_continue', 0)
	elif x == gorgon_spot_continue[0] and y == gorgon_spot_continue[1] and z == gorgon_spot_continue[2]:
		script.SetVar('gorgon_back', 0)
		script.SetVar('gorgon_continue', 1)
	elif way == gorgon and script.GetVar('gorgon_back') == 0 and script.GetVar('gorgon_continue') == 1 and script.GetVar('gorgon_done') == 1:
		script.SetWay(gorgon, 2)
		script.SetVar('gorgon_back', 0)
		script.SetVar('gorgon_continue', 0)
# Petraclops
	elif x == petraclops_spot_exit[0] and y == petraclops_spot_exit[1] and z == petraclops_spot_exit[2]:
		if script.GetVar('petraclops_done') == 1:
			script.SetWay(to_kalamon_done, 2)
	elif x == petraclops_spot_back[0] and y == petraclops_spot_back[1] and z == petraclops_spot_back[2]:
		script.SetVar('petraclops_back', 1)
		script.SetVar('petraclops_continue', 0)
	elif way == petraclops and script.GetVar('petraclops_back') == 1 and script.GetVar('petraclops_continue') == 0 and script.GetVar('petraclops_done') == 1:
		script.SetWay(petraclops, 1)
		script.SetVar('petraclops_back', 0)
		script.SetVar('petraclops_continue', 0)
	elif x == petraclops_spot_continue[0] and y == petraclops_spot_continue[1] and z == petraclops_spot_continue[2]:
		script.SetVar('petraclops_back', 0)
		script.SetVar('petraclops_continue', 1)
	elif way == petraclops and script.GetVar('petraclops_back') == 0 and script.GetVar('petraclops_continue') == 1 and script.GetVar('petraclops_done') == 1:
		script.SetWay(petraclops, 2)
		script.SetVar('petraclops_back', 0)
		script.SetVar('petraclops_continue', 0)
# Darktaur
	elif x == darktaur_spot_exit[0] and y == darktaur_spot_exit[1] and z == darktaur_spot_exit[2]:
		if script.GetVar('darktaur_done') == 1:
			script.IgnoreMonsters(1)
			script.SetWay(to_elvira_done, 2)
	elif x == darktaur_spot_back[0] and y == darktaur_spot_back[1] and z == darktaur_spot_back[2]:
		script.SetVar('darktaur_back', 1)
		script.SetVar('darktaur_continue', 0)
	elif way == darktaur and script.GetVar('darktaur_back') == 1 and script.GetVar('darktaur_continue') == 0 and script.GetVar('darktaur_done') == 1:
		script.SetWay(darktaur, 1)
		script.SetVar('darktaur_back', 0)
		script.SetVar('darktaur_continue', 0)
	elif x == darktaur_spot_continue[0] and y == darktaur_spot_continue[1] and z == darktaur_spot_continue[2]:
		script.SetVar('darktaur_back', 0)
		script.SetVar('darktaur_continue', 1)
	elif way == darktaur and script.GetVar('darktaur_back') == 0 and script.GetVar('darktaur_continue') == 1 and script.GetVar('darktaur_done') == 1:
		script.SetWay(darktaur, 2)
		script.SetVar('darktaur_back', 0)
		script.SetVar('darktaur_continue', 0)
# Buya
	if way == to_buya and x == buya[0] and y == buya[1] and z == buya[2]:
		if script.GoToNpcEx('Buya'):
			script.StatusMessage('Hello Buya')
		else:
			script.StatusMessage('I can\'t find Buya')
			script.Alarm('I can\'t find Buya')
	elif way == to_buya_done and x == buya[0] and y == buya[1] and z == buya[2]:
		if script.GoToNpcEx('Buya'):
			script.StatusMessage('Hello Buya')
		else:
			script.StatusMessage('I can\'t find Buya')
			script.Alarm('I can\'t find Buya')
# Planima
	elif way == to_planima and x == planima[0] and y == planima[1] and z == planima[2]:
		if script.GoToNpcEx('Planima'):
			script.StatusMessage('Hello Planima')
		else:
			script.StatusMessage('I can\'t find Planima')
			script.Alarm('I can\'t find Planima')
	elif way == to_planima_done and x == planima[0] and y == planima[1] and z == planima[2]:
		if script.GoToNpcEx('Planima'):
			script.StatusMessage('Hello Planima')
		else:
			script.StatusMessage('I can\'t find Planima')
			script.Alarm('I can\'t find Planima')
# Fal Kon
	elif way == to_fal_kon and x == fal_kon[0] and y == fal_kon[1] and z == fal_kon[2]:
		if script.GoToNpcEx('Fal Kon'):
			script.StatusMessage('Hello Fal Kon')
		else:
			script.StatusMessage('I can\'t find Fal Kon')
			script.Alarm('I can\'t find Fal Kon')
	elif way == to_fal_kon_done and x == fal_kon[0] and y == fal_kon[1] and z == fal_kon[2]:
		if script.GoToNpcEx('Fal Kon'):
			script.StatusMessage('Hello Fal Kon')
		else:
			script.StatusMessage('I can\'t find Fal Kon')
			script.Alarm('I can\'t find Fal Kon')
# Forgotten
	elif way == forgotten:
		if script.GetVar('forgotten_done') == 1:
			script.IgnoreMonsters(1)
			script.SetWay(to_buya_done, 2)
# Zealot
	elif x == zealot_spot_exit[0] and y == zealot_spot_exit[1] and z == zealot_spot_exit[2]:
		if script.GetVar('zealot_done') == 1:
			script.SetWay(to_planima_done, 2)
	elif x == zealot_spot_back[0] and y == zealot_spot_back[1] and z == zealot_spot_back[2]:
		script.SetVar('zealot_back', 1)
		script.SetVar('zealot_continue', 0)
	elif way == zealot and script.GetVar('zealot_back') == 1 and script.GetVar('zealot_continue') == 0 and script.GetVar('zealot_done') == 1:
		script.SetWay(zealot, 1)
		script.SetVar('zealot_back', 0)
		script.SetVar('zealot_continue', 0)
	elif x == zealot_spot_base[0] and y == zealot_spot_base[1] and z == zealot_spot_base[2]:
		script.SetVar('zealot_back', 0)
		script.SetVar('zealot_continue', 1)
	elif way == zealot and script.GetVar('zealot_back') == 0 and script.GetVar('zealot_continue') == 1 and script.GetVar('zealot_done') == 1:
		script.SetWay(zealot, 2)
		script.SetVar('zealot_back', 0)
		script.SetVar('zealot_continue', 0)
# Observer
	elif x == observer_spot_base[0] and y == observer_spot_base[1] and z == observer_spot_base[2]:
		if script.GetVar('observer_done') == 1:
			script.SetWay(to_fal_kon_done, 2)
	elif x == observer_spot_fast_exit[0] and y == observer_spot_fast_exit[1] and z == observer_spot_fast_exit[2]:
		if script.GetVar('observer_done') == 1:
			if way == observer:
				script.SetWay(to_fal_kon_done, 2)
	elif x == observer_spot_back[0] and y == observer_spot_back[1] and z == observer_spot_back[2]:
		script.SetVar('observer_back', 1)
		script.SetVar('observer_continue', 0)
	elif way == observer and script.GetVar('observer_back') == 1 and script.GetVar('observer_continue') == 0 and script.GetVar('observer_done') == 1:
		script.SetWay(observer, 1)
		script.SetVar('observer_back', 0)
		script.SetVar('observer_continue', 0)
	elif x == observer_spot_continue[0] and y == observer_spot_continue[1] and z == observer_spot_continue[2]:
		script.SetVar('observer_back', 0)
		script.SetVar('observer_continue', 1)
	elif way == observer and script.GetVar('observer_back') == 0 and script.GetVar('observer_continue') == 1 and script.GetVar('observer_done') == 1:
		script.SetWay(observer, 2)
		script.SetVar('observer_back', 0)
		script.SetVar('observer_continue', 0)
# Ignore mobs
	elif way == to_d_base_one or way == to_buya or way == to_planima or way == to_fal_kon or way == to_buya_done or way == to_planima_done or way == to_fal_kon_done or way == to_d_base_two or way == to_kalamon or way == to_elvira or way == to_crimson or way == to_kalamon_done or way == to_elvira_done or way == to_crimson_done:
		script.IgnoreMonsters(1)

def onWaypointsEnded():
	way = script.GetWay()
	x = script.GetX()
	y = script.GetY()
	z = script.GetZ()
# Gorgon
	if way == to_gorgon and x == gorgon_spot_base[0] and y == gorgon_spot_base[1] and z == gorgon_spot_base[2]:
		script.SetWay(gorgon, 2)
		script.StatusMessage('Hunt Gorgons')
# Petraclops
	elif way == to_petraclops and x == petraclops_spot_base[0] and y == petraclops_spot_base[1] and z == petraclops_spot_base[2]:
		if get_adamantines == 1:
			script.SetWay(petraclops, 2)
			script.IgnoreMonsters(0)
			script.StatusMessage('Get adamantines')
		elif get_adamantines == 0:
			script.SetWay(petraclops, 1)
			script.IgnoreMonsters(1)
			script.SetVar('petraclops_done', 1)
			script.StatusMessage('Don\'t get adamantines')
# Darktaur
	elif way == to_darktaur and x == darktaur_spot_base[0] and y == darktaur_spot_base[1] and z == darktaur_spot_base[2]:
		script.SetWay(darktaur, 2)
		script.StatusMessage('Hunt Darktaurs')
# Observer
	elif way == to_observer and x == observer_spot_base[0] and y == observer_spot_base[1] and z == observer_spot_base[2]:
		script.SetWay(observer, 2)
		script.IgnoreMonsters(0)
		script.StatusMessage('Hunt Observers')
# Zealot
	elif way == to_zealot and x == zealot_spot_base[0] and y == zealot_spot_base[1] and z == zealot_spot_base[2]:
		script.SetWay(zealot, 2)
		script.IgnoreMonsters(0)
		script.StatusMessage('Hunt Zealots')
# Forgotten
	elif way == to_forgotten and x == forgotten_spot_base[0] and y == forgotten_spot_base[1] and z == forgotten_spot_base[2]:
		script.SetWay(forgotten, 2)
		script.IgnoreMonsters(0)
		script.StatusMessage('Hunt Forgottens')
# Finish tasks
	elif way == to_d_base_two and x == doratia_base[0] and y == doratia_base[1] and z == doratia_base[2]:
		if script.GetVar('message_finish') == 0:
			script.StatusMessage('All tasks have been completed')
			script.SetVar('message_finish', 1)
# Hunt
	elif way == to_hunt and x == hunt_spot[0] and y == hunt_spot[1] and z == hunt_spot[2]:
		script.SetWay(hunt, 2)
		script.IgnoreMonsters(0)
		script.StatusMessage('I will hunt until 20 minutes before ' + str(start_tasks))

def onReceiveNpcText(name, text, page):
	way = script.GetWay()
# Buya
	if name == 'Buya':
		if 'Hello' in text or 'Are you ready to kill' in text:
			if way == to_buya:
				script.StatusMessage('Buya task taken')
				script.ChooseNpcOption(1)
		elif 'Then go down there and do' in text or 'You didn\'t kill enough forgotten' in text:
			if way == to_buya:
				script.SetWay(to_planima, 2)
				script.ForgetNpc()
		elif 'Come back later' in text:
			if way == to_buya:
				script.SetWay(to_buya, 2)
				script.StatusMessage('You must wait a bit to do the task again')
				script.ForgetNpc()
				script.LogoutFor(20)
			elif way == to_buya_done:
				script.StatusMessage('Buya task completed')
				script.SetWay(to_d_base_two, 2)
				script.SetVar('monster_quest', 0)
				script.ForgetNpc()
				onQuestFinish()
		elif 'Here, take your reward' in text or 'You did an excellent job.' in text:
			if way == to_buya_done:
				script.StatusMessage('Buya task completed')
				script.SetWay(to_d_base_two, 2)
				script.SetVar('monster_quest', 0)
				script.ForgetNpc()
				onQuestFinish()
			elif way == to_buya:
				script.GoToNpcEx('Buya')
# Planima
	elif name == 'Planima':
		if 'Hello' in text or 'Are you ready to kill' in text:
			if way == to_planima:
				script.StatusMessage('Planima task taken')
				script.ChooseNpcOption(1)
		elif 'Then go out there and do' in text or 'You didn\'t kill enough zealots' in text:
			if way == to_planima:
				script.SetWay(to_fal_kon, 2)
				script.ForgetNpc()
		elif 'Come back later' in text:
			if way == to_planima:
				script.SetWay(to_planima, 2)
				script.StatusMessage('You must wait a bit to do the task again')
				script.ForgetNpc()
				script.LogoutFor(20)
			elif way == to_planima_done:
				script.StatusMessage('Planima task completed')
				script.SetWay(to_forgotten, 2)
				script.SetVar('monster_quest', 0)
				script.ForgetNpc()
		elif 'Here, take your reward' in text or 'You did an excellent job.' in text:
			if way == to_planima_done:
				script.StatusMessage('Planima task completed')
				script.SetWay(to_forgotten, 2)
				script.SetVar('monster_quest', 0)
				script.ForgetNpc()
			elif way == to_planima:
				script.GoToNpcEx('Planima')
# Fal Kon
	elif name == 'Fal Kon':
		if 'Hello' in text or 'Are you ready to kill' in text:
			if way == to_fal_kon:
				script.StatusMessage('Fal Kon task taken')
				script.ChooseNpcOption(1)
		elif 'you to roam the surface and the tunnels' in text or 'You didn\'t kill enough observers' in text:
			if way == to_fal_kon:
				script.SetWay(to_kalamon, 2)
				script.ForgetNpc()
		elif 'Come back later' in text:
			if way == to_fal_kon:
				script.SetWay(to_fal_kon, 2)
				script.StatusMessage('You must wait a bit to do the task again')
				script.ForgetNpc()
				script.LogoutFor(20)
			elif way == to_fal_kon_done:
				script.StatusMessage('Fal Kon task completed')
				script.SetWay(to_zealot, 2)
				script.SetVar('monster_quest', 0)
				script.ForgetNpc()
		elif 'Here, take your reward' in text or 'You did an excellent job.' in text:
			if way == to_fal_kon_done:
				script.StatusMessage('Fal Kon task completed')
				script.SetWay(to_zealot, 2)
				script.SetVar('monster_quest', 0)
				script.ForgetNpc()
			elif way == to_fal_kon:
				script.GoToNpcEx('Fal Kon')
# Kalamon
	elif name == 'Kalamon':
		if 'Welcome back' in text:
			if way == to_kalamon:
				script.StatusMessage('Kalamon task taken')
				script.ChooseNpcOption(1)
		elif 'These can be found on this island' in text or 'You can get them from the Petraclops' in text:
			if way == to_kalamon:
				script.SetWay(to_elvira, 2)
				script.ForgetNpc()
			elif way == to_kalamon_done:
				script.StatusMessage('Adamantines are in your inventory')
				script.SetWay(to_darktaur, 2)
				script.IgnoreMonsters(0)
				script.ForgetNpc()
		elif 'Come back later' in text:
			if way == to_kalamon:
				script.SetWay(to_kalamon, 2)
				script.StatusMessage('You must wait a bit to do the task again')
				script.ForgetNpc()
				script.LogoutFor(20)
			elif way == to_kalamon_done:
				script.StatusMessage('Kalamon task completed')
				script.SetWay(to_darktaur, 2)
				script.IgnoreMonsters(0)
				script.ForgetNpc()
		elif 'You got everything' in text or 'Bring them to me to fulfil' in text:
			if way == to_kalamon_done:
				script.StatusMessage('Kalamon task completed')
				script.SetWay(to_darktaur, 2)
				script.IgnoreMonsters(0)
				script.ForgetNpc()
			elif way == to_kalamon:
				script.GoToNpcEx('Kalamon')
# Elvira
	elif name == 'Elvira':
		if 'Good to see you again' in text:
			if way == to_elvira:
				script.StatusMessage('Elvira task taken')
				script.ChooseNpcOption(1)
		elif 'Wonderful' in text or 'You are not done yet' in text:
			if way == to_elvira:
				script.SetWay(to_crimson, 2)
				script.ForgetNpc()
		elif 'Come back from time to time' in text:
			if way == to_elvira:
				script.SetWay(to_elvira, 2)
				script.StatusMessage('You must wait a bit to do the task again')
				script.ForgetNpc()
				script.LogoutFor(20)
			elif way == to_elvira_done:
				script.StatusMessage('Elvira task completed')
				script.SetWay(to_observer, 2)
				script.SetVar('monster_quest', 0)
				script.ForgetNpc()
		elif 'You have done it' in text:
			if way == to_elvira_done:
				script.StatusMessage('Elvira task completed')
				script.SetWay(to_observer, 2)
				script.SetVar('monster_quest', 0)
				script.ForgetNpc()
			elif way == to_elvira:
				script.GoToNpcEx('Elvira')
# Crimson
	elif name == 'Crimson':
		if 'Welcome back. So much of these' in text:
			if way == to_crimson:
				script.StatusMessage('Crimson task taken')
				script.ChooseNpcOption(1)
				script.IgnoreMonsters(0)
		elif 'Then comb the caves' in text or 'You are not finished yet' in text:
			if way == to_crimson:
				script.SetWay(to_gorgon, 2)
				script.ForgetNpc()
		elif 'Welcome back. I still have some stuff to prepare. Please come back later' in text:
			if way == to_crimson:
				script.SetWay(to_crimson, 2)
				script.StatusMessage('You must wait a bit to do the task again')
				script.ForgetNpc()
				script.LogoutFor(20)
			elif way == to_crimson_done:
				script.StatusMessage('Crimson task completed')
				script.SetWay(to_petraclops, 2)
				script.SetVar('monster_quest', 0)
				script.ForgetNpc()
		elif 'Great, you did it' in text:
			if way == to_crimson_done:
				script.StatusMessage('Crimson task completed')
				script.SetWay(to_petraclops, 2)
				script.SetVar('monster_quest', 0)
				script.ForgetNpc()
			elif way == to_crimson:
				script.GoToNpcEx('Crimson')

def onReachedNpc(uid, name):
	if not script.TalkToNpc(uid):
		script.StatusMessage('Can\'t talk to ' + name + '!')

def onTalkedWithNpc(uid, result):
	if not result:
		if not script.TalkToNpc(uid):
			script.StatusMessage('Can\'t talk to ' + name + '!')

def onKilledEnemy(name, templateId):
	varname = 'killed_' + name
	mobs = script.GetVar(varname) + 1
	script.SetVar(varname, mobs)
	txt = str(mobs)
# Gorgoros
	if name == 'Gorgon' and mobs == 25:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)
	elif name == 'Gorgon' and mobs == 50:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)
	elif name == 'Gorgon' and mobs == 75:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)
	elif name == 'Darktaur' and mobs == 25:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)
	elif name == 'Darktaur' and mobs == 50:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)
	elif name == 'Darktaur' and mobs == 75:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)
# Doratia
	elif name == 'Forgotten' and mobs == 25:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)
	elif name == 'Forgotten' and mobs == 45:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)
	elif name == 'Zealot' and mobs == 25:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)
	elif name == 'Zealot' and mobs == 45:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)
	elif name == 'Observer' and mobs == 25:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)
	elif name == 'Observer' and mobs == 45:
		script.StatusMessage('Killed: ' + name + ' \nTotal: ±' + txt)

def onReceiveQuestLogUpdate(text):
# Gorgoros
	if 'Gorgon population at bay. I agreed to kill 100 of these' in text:
		script.SetVar('gorgon_done', 0)
	elif 'Kalamon offered me a deal.' in text:
		script.SetVar('petraclops_done', 0)
	elif 'Elvira still wants revenge for her fallen friends.' in text:
		script.SetVar('darktaur_done', 0)
	elif 'I killed the 100 Gorogns for Crimson' in text:
		script.SetVar('gorgon_done', 1)
		script.IgnoreMonsters(1)
		if script.GetVar('monster_quest') == 0:
			script.SetVar('monster_quest', 1)
			script.StatusMessage('I killed 100 gorgons. I\'ll go take the reward')
	elif 'I killed the 100 Dartaurs for Elvira.' in text:
		script.SetVar('darktaur_done', 1)
		script.IgnoreMonsters(1)
		if script.GetVar('monster_quest') == 0:
			script.SetVar('monster_quest', 1)
			script.StatusMessage('I killed 100 Darktaurs. I\'ll go take the reward')
# Doratia
	elif 'I met a guy named buya who wants to explore the ruins but is afraid to do so with all these forgotten spirirts around.' in text:
		script.SetVar('forgotten_done', 0)
	elif 'Planima the Agramage wants to tend to her experiments again but is afraid to do so with all these zealots around.' in text:
		script.SetVar('zealot_done', 0)
	elif 'The gamekeeper Fal Kon needs some help with keeping the Observers in check.' in text:
		script.SetVar('observer_done', 0)
	elif 'I killed 50 forgotten spirits.' in text:
		script.SetVar('forgotten_done', 1)
		script.IgnoreMonsters(1)
		if script.GetVar('monster_quest') == 0:
			script.SetVar('monster_quest', 1)
			script.StatusMessage('I killed 50 Forgottens. I\'ll go take the reward')
	elif 'I disposed of 50 zealots.' in text:
		script.SetVar('zealot_done', 1)
		script.IgnoreMonsters(1)
		if script.GetVar('monster_quest') == 0:
			script.SetVar('monster_quest', 1)
			script.StatusMessage('I killed 50 Zealots. I\'ll go take the reward')
	elif 'I killed the promised 50 Observers.' in text:
		script.SetVar('observer_done', 1)
		script.IgnoreMonsters(1)
		if script.GetVar('monster_quest') == 0:
			script.SetVar('monster_quest', 1)
			script.StatusMessage('I killed 50 Observers. I\'ll go take the reward')

def onReceiveAddItemToBackpack(slot, itemId):
	if itemId in drop_items_by_id_list:
		if script.DropItem(slot, 1) == 'no_room':
			queue[slot] = itemId
	elif get_adamantines == 1:	
		if itemId == 5257 and script.GetItemsCount(5257, 1) == 1:
			script.StatusMessage('I have 1/5 adamantine') 
		elif itemId == 5257 and script.GetItemsCount(5257, 1) == 2:
			script.StatusMessage('I have 2/5 adamantines') 
		elif itemId == 5257 and script.GetItemsCount(5257, 1) == 3:
			script.StatusMessage('I have 3/5 adamantines') 
		elif itemId == 5257 and script.GetItemsCount(5257, 1) == 4:
			script.StatusMessage('I have 4/5 adamantines') 
		elif itemId == 5257 and script.GetItemsCount(5257, 1) >= 5:
			script.SetVar('petraclops_done', 1)
			script.IgnoreMonsters(1)
			script.StatusMessage('I already have 5 adamantines')