Page 1 of 1

Day and Night spawns - notifier?

Posted: Thu Sep 12, 2013 11:06 pm
by Hyrelius
L2J Revision 9943:
L2JDP Revision 6199:

Hello,

is there a way to make the script react to day and night changes? I know I could use the DayNightSpawnManager to spawn a certain creature, but what I want is to be able to react to the day and night change, because I want to randomly decide the location and re-add the spawn myself.

In GameTimeController I found this:

Code: Select all

        _log.log(Level.CONFIG, getClass().getSimpleName() + ": Started.");                long nextTickTime, sleepTime;        boolean isNight = isNight();                if (isNight)        {            ThreadPoolManager.getInstance().executeAi(new Runnable()            {                @Override                public final void run()                {                    DayNightSpawnManager.getInstance().notifyChangeMode();                }            });        }
This means, that whenever isNight is true a new Runnable is created, which triggers the day and night switch.

I could easily add a listener, which (if registered to it) could notify all scripts about this change - not just DayNightSpawnManager. But I am not sure if this is something, that might be of interest by the L2J-Team. Perhaps there is even a different solution?

I greatly appreciate an answer and would do the job of adding the listener if there's a chance it might become part of L2J.

Hyrelius.

Re: Day and Night spawns - notifier?

Posted: Thu Sep 12, 2013 11:21 pm
by Zoey76
I believe the best solution should be a listener that replace the notifications.

That way more stuff can be unhardcoded from core, or at least unified with current scripts in Datapack.

Re: Day and Night spawns - notifier?

Posted: Thu Sep 12, 2013 11:23 pm
by Hyrelius
Okay I will attempt to write such a listener and will create a patchfile once done. I will also create an interface, that requires a method (e.g. "onDayNightChange") to be implemented before adding it to the listener.

Thanks for the answer!

Re: Day and Night spawns - notifier?

Posted: Fri Sep 13, 2013 5:33 am
by UnAfraid
Here's a patch we prepared to be committed https://gist.github.com/UnAfraid/ca4cfc5ac3f099df63c3
It includes such listener.

Re: Day and Night spawns - notifier?

Posted: Fri Sep 13, 2013 1:46 pm
by Hyrelius
Hey,

thank you guys!

I had done the changes myself and wanted to contribute them here... too bad you were faster, UnAfraid :D.

Anyway.. from what I see you've made a "DayNightChangeEvent" (what I had done too), but imo there's no particular reason for that, because you can always use GameTimeController.getInstance().isNight() to determine the current setting and there is no further information needed in that Event.

This is what I my diff-file looks like: http://pastebin.com/LJ4fHrWg

Perhaps I am wrong, but I think we do not need a DayNightChangeEvent, because there is no information that has to be transferred using that event.

Greetings,
Hyrelius.