@LabelIndex 420236
@StringIndex 0
class 1 on_day_night_spawn : default_maker {
parameter:
	int	IsNight = 0;

handler:
	EventHandler ON_START(i0,i1,def0) {
		i0 = gg::GetL2Time(2);
		if( i0 ) {
			if( IsNight == 1 ) {
				myself.i_ai0 = 1;
				super;
			} else {
				myself.i_ai0 = 0;
			}
		} else if( IsNight == 0 ) {
			myself.i_ai0 = 1;
			super;
		} else {
			myself.i_ai0 = 0;
		}
		myself::AddTimerEx(3000,1000);
	}

	EventHandler ON_NPC_CREATED(created_def,created_npc,maker0,i0) {
		i0 = gg::GetL2Time(2);
		if( i0 == 1 ) {
			if( myself.i_ai0 == 0 ) {
				if( IsNight == 0 ) {
					created_npc::Despawn();
				}
			}
		} else if( myself.i_ai0 == 0 ) {
			if( IsNight == 1 ) {
				created_npc::Despawn();
			}
		}
	}

	EventHandler ON_NPC_DELETED(deleted_def,i0,i1,maker0,reply) {
		i0 = gg::GetL2Time(2);
		if( i0 == 1 ) {
			if( IsNight == 1 ) {
				if( myself::AtomicIncreaseTotal(deleted_def,1,1) ) {
					deleted_def::Spawn2(1,deleted_def.respawn_time,deleted_def.respawn_rand);
				}
			}
		} else if( IsNight == 0 ) {
			if( myself::AtomicIncreaseTotal(deleted_def,1,1) ) {
				deleted_def::Spawn2(1,deleted_def.respawn_time,deleted_def.respawn_rand);
			}
		}
	}

	EventHandler ON_TIMER(timer_id,i0,i1,maker0) {
		if( timer_id == 3000 ) {
			i0 = gg::GetL2Time(2);
			if( i0 == 1 ) {
				if( myself.i_ai0 == 0 ) {
					if( IsNight == 1 ) {
						maker0 = gg::GetNpcMaker(myself.name);
						if( gg::IsNull(maker0) == 0 ) {
							gg::SendMakerScriptEvent(maker0,1001,0,0);
							myself.i_ai0 = 1;
						}
					}
				} else if( IsNight == 0 ) {
					maker0 = gg::GetNpcMaker(myself.name);
					if( gg::IsNull(maker0) == 0 ) {
						gg::SendMakerScriptEvent(maker0,1000,0,0);
					}
					myself.i_ai0 = 0;
				}
			} else if( myself.i_ai0 == 0 ) {
				if( IsNight == 0 ) {
					maker0 = gg::GetNpcMaker(myself.name);
					if( gg::IsNull(maker0) == 0 ) {
						gg::SendMakerScriptEvent(maker0,1001,0,0);
						myself.i_ai0 = 1;
					}
				}
			} else if( IsNight == 1 ) {
				maker0 = gg::GetNpcMaker(myself.name);
				if( gg::IsNull(maker0) == 0 ) {
					gg::SendMakerScriptEvent(maker0,1000,0,0);
				}
				myself.i_ai0 = 0;
			}
			myself::AddTimerEx(3000,1000);
		}
	}

}
