// .txt

beginzonescript;

variables;

short im_hostile = 0;
short max_crime = 5;
short last_abil;
short counter = 0;

body;

beginstate INIT_STATE;
	last_abil = get_current_tick();

	set_name(18036,"Kelner");
	
	set_name(18037,"X");
	if (gf(167,4) > 4)
		erase_char(18037);
	if (gf(167,4) == 5)
		spawn_creature(18110);
		
	set_name(18038,"Sage Ardella");
	set_name(18039,"Agass-Ess");
	set_name(18040,"Djokov");
	set_name(18041,"Captain Bahgdatis");

	set_name(18042,"Avernite Soldier");
	set_name(18043,"Avernite Soldier");
	set_name(18044,"Avernite Soldier");
	set_name(18045,"Avernite Soldier");
	set_name(18046,"Avernite Soldier");
	set_name(18047,"Avernite Soldier");
	set_name(18048,"Avernite Soldier");
	set_name(18049,"Avernite Soldier");
	set_name(18050,"Avernite Soldier");

	set_name(18057,"Sage Dressla");

	set_level(18061,14);
	set_level(18062,14);
	set_level(18063,14);
	set_level(18064,14);
	set_level(18065,14);

	set_level(18082,12);
	set_level(18083,12);
	set_level(18084,12);
	set_level(18085,12);
	
	add_range_to_group(18088,18093,43);
	set_name(30043,"Spiny Hellhound");
	set_new_abil(30043,8);
	set_aggression(30043,60);

	set_name(18090,"Ferocious Hellhound");
	set_boss_level(18090,1);
	set_coloradj(18090,72);
	
	add_range_to_group(18094,18101,44);
	set_name(30044,"Altered Arachnid");
	set_aggression(30044,60);
	set_name(18101,"Released Aranea");
	set_level(18101,16);
	
	set_name(18111,"Avernite Soldier");
	set_name(18112,"Avernite Soldier");
	set_name(18113,"Avernite Soldier");
	set_name(18114,"Avernite Soldier");

	// demon event
	sf(167,26,0);
	sf(167,19,0);
	
	// make worms 
	if ((gf(167,18) == 0) && (gf(167,4) < 6)) {
		activate_hidden_group(43);
		}
	if (gf(167,18) > 0)
		kill_object(30162,1);
		
	set_crime_tolerance(max_crime);

	break;

beginstate EXIT_STATE;

break;

beginstate START_STATE;
		if ((gf(167,18) > 0) && (party_has_item(304))) {
			take_item(304);
			reward_give(305);
			}

	// regen worms 
	if ((gf(167,18) == 0) && (gf(167,4) < 5) && (gf(167,26) > 0) && (on_which_layer() == 0)) {
		sf(167,26,0);
		activate_hidden_group(43);
		}
		
	if ((get_crime_level() >= max_crime) && (im_hostile == 0)) {
		make_zone_hostile(); 
		im_hostile = 1;
		//erase_char(30000);
		begin_talk_mode(299);
		}

	// if (gf(,) == 0) {
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(18036,"We need your help.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(18036,"Things are difficult.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(18036,"I am the leader here.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(18037,"Is time.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(18037,"Almost.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(18037,"Soon.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(18037,"I need.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(18037,"Yes.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(18038,"What a mess.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(18038,"Will work never resume?");
	if ((get_ran(1,0,100) < 10) && (gf(167,18) == 0))
		give_char_text_bubble(18038,"Beware the demon.");
	if ((get_ran(1,0,100) < 10) && (gf(167,18) == 0))
		give_char_text_bubble(18038,"Stay away from the center.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(18039,"Get back to work!");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(18039,"The school is open!");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(18039,"Ahssss!");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(18040,"Welcome.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(18040,"I can trade.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(18040,"I have potions.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(18040,"I do custom work.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(18041,"I just gave up.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(18041,"Why keep trying?");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(18041,"They do what they want.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(18041,"They always lie.");

	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(18111 + get_ran(1,0,3),"It's nasty upstairs.");
	if (get_ran(1,0,100) < 10)
		give_char_text_bubble(18111 + get_ran(1,0,3),"Be careful.");

	//	}

	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 == 4) {
			counter = 0;
			if (gf(167,15) == 0)
				sf(167,15,1);
				else sf(167,15,0);
			}
		}
break;

beginstate 10;
break;

beginstate 11;
break;

beginstate 12;
break;

beginstate 13;
break;

beginstate 15;
	set_terrain_string_range("The sign says - BARRACKS.",1);
break;

beginstate 16;
	set_terrain_string_range("The sign says - Experiment Management.",1);
break;

beginstate 17;
	set_terrain_string_range("The sign says - .",1);
break;

beginstate 30;
		if (revive_party()) {
			print_str_color("Entering or leaving the Tower Colony heals your wounds",2);
			print_str_color("  and restores your spell energy.",2);
			}
break;

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