// .txt

beginzonescript;

variables;

short im_hostile = 0;
short max_crime = 4;
short last_abil;
short counter = 0;
short spawn_once = 0;

body;

beginstate INIT_STATE;
	last_abil = get_current_tick();

	set_name(3132,"Barghan Farmer");
	set_courage(3132,0);
	set_name(3133,"Barghan Farmer");
	set_courage(3133,0);
	set_name(3134,"Barghan Farmer");
	set_courage(3134,0);
	
	set_name(3135,"Barghan Soldier");
	set_name(3136,"Barghan Soldier");
	set_name(3137,"Barghan Soldier");
	set_name(3138,"Barghan Soldier");
	set_name(3139,"Barghan Soldier");
	set_name(3140,"Barghan Soldier");
	
	set_name(3149,"Gret");
	set_name(3158,"Barghan Torturer");
	set_name(3159,"Barghan Torturer");
	set_name(3160,"Barghan Torturer");
	set_name(3161,"Barghan Torturer");
	set_name(3162,"Prisonmaster Gvessa");
	set_level(3162,20);
	set_boss_level(3162,1);
	
	set_level(3163,20);
	set_attack_bonus(3163,15);
	set_new_abil(3163,20);
	
	set_name(3164,"Breck-Drayssa");
	set_level(3164,20);
	set_boss_level(3164,1);
	if (gf(29,6) > 0)
		erase_char(3164);
	
//	add_range_to_group(,,groupn);

	set_crime_tolerance(max_crime);
	
	if (gf(29,4) > 0)
		set_terrain(0,111,136,0);

	break;

beginstate EXIT_STATE;

break;

beginstate START_STATE;
	if ((gf(29,0) > 0) && (gf(29,2) == 0) && (char_ok(3150) == FALSE) && (party_dist_to_spot(124,161) > 10)) {
		spawn_creature(3150);
		}
		
	if ((get_crime_level() >= max_crime) && (im_hostile == 0)) {
		make_zone_hostile();
		im_hostile = 1;
		}

	// worms
	if (get_ran(1,0,100) == 50)
		sf(29,8,0);
	if (get_ran(1,0,100) == 50)
		sf(29,9,0);
	if ((get_quest_status(190) == 2) && (on_which_layer() == 0)) {
		if ((gf(29,8) == 0) && (party_dist_to_spot(102,183) <= 4)) {
			sf(29,8,1);
			if (party_has_item(196)) {
				spawn_creature(3141);
				spawn_creature(3142);
				spawn_creature(3143);
				spawn_creature(3144);
				begin_talk_mode(61);
				}
				else if (gf(43,10) == 0) {
					sf(43,10,1);
					begin_talk_mode(60);
					}
					else {
						print_str_color("The worms come to the surface of the water and sniff.",3);
						print_str_color("  They don't smell anything they like, so they swim away.",3);
						}
			}

		if ((gf(29,9) == 0) && (party_dist_to_spot(109,155) <= 4)) {
			sf(29,9,1);
			if (party_has_item(196)) {
				spawn_creature(3145);
				spawn_creature(3146);
				spawn_creature(3147);
				spawn_creature(3148);
				begin_talk_mode(61);
				}
				else if (gf(43,10) == 0) {
					sf(43,10,1);
					begin_talk_mode(60);
					}
					else {
						print_str_color("The worms come to the surface of the water and sniff.",3);
						print_str_color("  They don't smell anything they like, so they swim away.",3);
						}
			}
		}

	// if (gf(,) == 0) {
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(3149,"Mrrrr.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(3149,"I welcome you, Avernite.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(3149,"Have some tea.");
	if ((get_ran(1,0,100) < 10) && (gf(29,6) == 0))
		give_char_text_bubble(3164,"Are you real?");
	if ((get_ran(1,0,100) < 10) && (gf(29,6) == 0))
		give_char_text_bubble(3164,"Truly an Avernite?");
	if ((get_ran(1,0,100) < 10) && (gf(29,6) == 0))
		give_char_text_bubble(3164,"Rescued at last?");
	//	}

	if (((is_combat()) && (tick_difference(last_abil,get_current_tick()) > 0)) || ((is_group()) && (tick_difference(last_abil,get_current_tick()) > 5))) {
		last_abil = get_current_tick();
		
		counter = counter + 1;
		if (counter == 5) {
			counter = 0;
			if (gf(29,5) == 0)
				sf(29,5,1);
				else sf(29,5,0);
			}
		
		}
break;

beginstate 10;
	if (spawn_once > 0)
		end();
	spawn_once = 1;
	
	if (gf(29,6) == 0) {
		activate_hidden_group(43);
		set_name(3151,"Prison Guard");
		set_level(3151,17);
		set_name(3152,"Prison Guard");
		set_level(3152,17);
		set_name(3153,"Prison Guard");
		set_level(3153,17);
		set_name(3154,"Prison Guard");
		set_level(3154,17);
		set_name(3155,"Prison Guard");
		set_level(3155,17);
		set_name(3156,"Prison Guard");
		set_level(3156,17);
		}
		
	if (gf(29,3) == 0)
		begin_talk_mode(4);
break;

beginstate 11;
break;

beginstate 12;
break;

beginstate 13;
break;

//	print_str("");
//	set_terrain_string_range(".",1);
//	set_terrain_string_range("The sign says - .",1);
