System DayNightEvent

Azlier

Old World Ghost
Reaction score
461
A script that detects when it turns day or night. DNR will be requiring this.

Detects moonstones and other nonsense.

Requires Event.
JASS:
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//  ~~    DayNightEvent   ~~    By Azlier    ~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//  What is DNE?
//         - DNE allows bugless detection of when day or night falls in WC3.
//
//  Functions:
//         TriggerRegisterDayEvent takes trigger whichTrigger
//           - Registers a trigger to fire whenever daytime begins.
//
//         TriggerRegisterNightEvent takes trigger whichTrigger
//           - Registers a trigger to fire whenenver nighttime begins.
//         
//  Note:
//    The booleans IsDay and IsNight can be used to determine whether it is day or night.
//
//  How to import:
//         - Create a trigger named DNR.
//         - Convert it to custom text and replace the whole trigger text with this.
//         - Save the map, and close it.
//         - Reopen the map and remove the exclamation marks from the start of the two lines below this one.
//!        external ObjectMerger w3u hpea dadt ufoo 0 uabi Avul,Aloc umdl " " usca 0 ushu " " unam "DayDetect" unsf "(DNE Dummy)" util 0 uhpm 5 uhpr 100 uhrt "day"
//!        external ObjectMerger w3u hpea nidt ufoo 0 uabi Avul,Aloc umdl " " usca 0 ushu " " unam "NightDetect" unsf "(DNE Dummy)" util 0 uhpm 5 uhpr 100 uhrt "night"
//         - Save again.
//
//
//      Thanks to Jesus4Lyf for the method on how to detect day/night.
//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
library DNE initializer Init requires Event

globals
    private constant integer DAY = 'dadt'
    private constant integer NIGHT = 'nidt'
    private Event DayEv
    private Event NightEv
    boolean IsDay = false
    boolean IsNight = false
    private unit DayU
    private unit NightU
    private trigger DayT = CreateTrigger()
    private trigger NightT = CreateTrigger()
endglobals

function TriggerRegisterDayEvent takes trigger t returns nothing
    call DayEv.register(t)
endfunction

function TriggerRegisterNightEvent takes trigger t returns nothing
    call NightEv.register(t)
endfunction

private function FlagDay takes nothing returns boolean
    set IsDay = true
    set IsNight = false
    call DayEv.fire()
    call SetWidgetLife(NightU, 1)
    return false
endfunction

private function FlagNight takes nothing returns boolean
    set IsNight = true
    set IsDay = false
    call NightEv.fire()
    call SetWidgetLife(DayU, 1)
    return false
endfunction

private function Init takes nothing returns nothing
    local trigger t
    
    set DayU = CreateUnit(Player(15), DAY, 0, 0, 270)
    set NightU = CreateUnit(Player(15), NIGHT, 0, 0, 270)
    call PauseUnit(DayU, true)
    call PauseUnit(NightU, true)
    call SetUnitX(DayU, 10000)
    call SetUnitX(NightU, 10000)
    call SetUnitY(DayU, 10000)
    call SetUnitY(NightU, 10000)
    //call ShowUnit(DayU, false)
    //call ShowUnit(NightU, false)
    call SetWidgetLife(DayU, 1)
    call SetWidgetLife(NightU, 1)
    
    set t = CreateTrigger()
    call TriggerRegisterUnitStateEvent(t, DayU, UNIT_STATE_LIFE, GREATER_THAN_OR_EQUAL, 2)
    call TriggerAddCondition(t, function FlagDay)
    
    set t = CreateTrigger()
    call TriggerRegisterUnitStateEvent(t, NightU, UNIT_STATE_LIFE, GREATER_THAN_OR_EQUAL, 2)
    call TriggerAddCondition(t, function FlagNight)
    
    set DayEv = Event.create()
    set NightEv = Event.create()
endfunction

endlibrary
 

Attachments

  • DNE Test Map.w3x
    15.7 KB · Views: 323

Jesus4Lyf

Good Idea™
Reaction score
397
I think I deserve credits in this one. :p

JASS:
//         - Reopen the map and delete the two lines below this one.
//!        external ObjectMerger w3u hpea dadt ufoo 0 uabi Avul,Aloc umdl " " usca 0 ushu " " unam "DayDetect" unsf "(DNE Dummy)" util 0 uhpm 5 uhpr 100 uhrt "day"
//!        external ObjectMerger w3u hpea nidt ufoo 0 uabi Avul,Aloc umdl " " usca 0 ushu " " unam "NightDetect" unsf "(DNE Dummy)" util 0 uhpm 5 uhpr 100 uhrt "night"

Would prefer the ol' "remove exclaimation mark" thing...

But this is pretty awesome, well done.
 

Azlier

Old World Ghost
Reaction score
461
I, for one, forgot that you can do that.
 

Azlier

Old World Ghost
Reaction score
461
They aren't even supposed to have those, this is the DNE test map, not the DNR test map :(.
 

SanKakU

Member
Reaction score
21
lol...i can't think of the last time a series of threads about war3 programming made me chuckle that much...well anyway i'll examine this stuff later on...

it sounds like from this thread's original post that you plan to update DNR...i guess i'll check back later
 

Azlier

Old World Ghost
Reaction score
461
DNR is already updated. It's just that I can't make it not require a holder player.
 

Azlier

Old World Ghost
Reaction score
461
Huh. Why was this graveyarded?
 

Azlier

Old World Ghost
Reaction score
461
Once again, I either find this tossed into the graveyard by an angry script or it never left at all.

Why?
 

Nestharus

o-o
Reaction score
84
tuts/resources submission section has an expiration on resources. If a resource has not received a reply in a set amount of time, it is auto moved to the graveyard.
 

Azlier

Old World Ghost
Reaction score
461
So it must have been an angry script.
 

tooltiperror

Super Moderator
Reaction score
231
1) What if someone sets game time to something past 12:00 or 6:00 or whatever? Then the event is skipped.
2) What if someone uses a moonstone? Game time won't change.
3) What if someone has paused the game time and uses a simulated night? Game time won't change.
 

Jedi

New Member
Reaction score
63
1)That can be countered easily with two booleans Day and Night.But you need to set events "time becomes less-more than or equal to xx, but because of that trigger will run everytime time change, only advantage this system I can see is that(which is not so important for me)

2)Moonstone sets time to 0:00?Game time event should be fired.

3)I don't understand what are you talking about.
 

tooltiperror

Super Moderator
Reaction score
231
>That can be countered easily with two booleans Day and Night.But you need to set events "time becomes less-more than or equal to xx, but because of that trigger will run everytime time change, only advantage this system I can see is that(which is not so important for me)
Okay, so you're now firing an event every game second. In addition to that, you're still not detecting moonstones.

>Moonstone sets time to 0:00?Game time event should be fired.
Moonstone won't change game time, so the event won't fire.

>I don't understand
Then nevermind it, it was random anyways.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top