@LabelIndex 108709
@StringIndex 12823
class 0 ambassador_castle : citizen {
parameter:
	int	castle_id = 0;
	int	fortress_id = 0;
	string	fnHi1 = "";
	string	fnHi2 = "";
	string	fnContractSuccess = "";
	string	fnContractFail = "";
	string	fnIndepFail = "gludio_ambassador002.htm";
	string	fnIndepAlready = "gludio_ambassador002.htm";
	int	despawn_time = 60;
	int	msg_timeout = -1;

handler:
	EventHandler CREATED() {
		myself::AddTimerEx(7791,( ( despawn_time * 60 ) * 1000 ));
		super;
	}

	EventHandler TALKED(talker,i0) {
		if( myself::IsMyLord(talker) ) {
			myself::ShowPage(talker,fnHi);
			return;
		} else {
			myself::ShowPage(talker,fnHi2);
			return;
		}
	}

	EventHandler MENU_SELECTED(talker,ask,reply) {
		if( ask == -299 ) {
			if( reply == 0 ) {
				myself::Fortress_ContractCastle(myself.sm.id,talker.id,fortress_id,castle_id);
				return;
			} else if( reply == 1 ) {
				myself::Fortress_ContractCastle(myself.sm.id,talker.id,fortress_id,-1);
				return;
			}
		}
		super;
	}

	EventHandler SCRIPT_EVENT(script_event_arg1,script_event_arg2) {
		if( script_event_arg1 == 11039 ) {
			myself::Despawn();
		}
	}

	EventHandler TIMER_FIRED_EX(timer_id) {
		if( timer_id == 7790 ) {
			myself::Despawn();
		} else if( timer_id == 7791 ) {
			if( msg_timeout > 0 ) {
				myself::Say(gg::MakeFString(msg_timeout,"","","","",""));
			}
			myself::Fortress_ContractCastle(myself.sm.id,0,fortress_id,-1);
			myself::AddTimerEx(7790,( 3 * 1000 ));
		} else if( timer_id == 7792 ) {
			myself::BroadcastScriptEvent(11039,1,2000);
			myself::AddTimerEx(7790,( 3 * 1000 ));
		}
	}

	EventHandler FORTRESS_CONTRACT_CASTLE_RETURNED(talker,reply) {
		if( reply == -1 ) {
			myself::ShowPage(talker,fnContractSuccess);
			myself::AddTimerEx(7792,( 3 * 1000 ));
		} else if( reply == 0 ) {
			myself::ShowPage(talker,fnContractFail);
		} else if( reply == 1 ) {
			myself::ShowPage(talker,fnHi1);
			myself::AddTimerEx(7792,( 3 * 1000 ));
		} else if( reply == 2 ) {
			myself::ShowPage(talker,fnIndepFail);
		} else if( reply == 3 ) {
			myself::ShowPage(talker,fnIndepAlready);
		}
	}

}
