• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Snippet] DayNightEvent

Level 8
Joined
Oct 3, 2008
Messages
367
A script that detects when it turns day or night.

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, 100000)
    call SetUnitX(NightU, 100000)
    call SetUnitY(DayU, 100000)
    call SetUnitY(NightU, 100000)
    //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.1 KB · Views: 220
Last edited:
Level 31
Joined
Jul 10, 2007
Messages
6,306
lol.... the one from TH eh? : P

When the ability lua scripts are done, you could stabilize your ability generation.

Now for some issues for certain maps
JASS:
call SetUnitX(DayU, 10000)
    call SetUnitX(NightU, 10000)
    call SetUnitY(DayU, 10000)
    call SetUnitY(NightU, 10000)

I'm pretty sure that that will crash a map instantly if the map's max coord doesn't go up to 10000. I'd use max x/max y for that from GetWorldBounds. Considering how often those coords are used from script to script, that might be something useful for Bribe's hopeful GlobalUtils.

I'm looking at your script and I'm really unsure as to how it works o-o. Maybe you could enlighten us as to how you use a unit's health event to detect day/night ; ).
call TriggerRegisterUnitStateEvent(t, DayU, UNIT_STATE_LIFE, GREATER_THAN_OR_EQUAL, 2)

I'm just quite curious about it o-o.

Also
JASS:
boolean IsDay = false
    boolean IsNight = false

You should put those into method operators in a struct so that they are readonly >.>.
 
Level 8
Joined
Oct 3, 2008
Messages
367
Now for some issues for certain maps

I don't believe any maps go that high. This is precisely the point. Units outside the map area don't crash as long as they aren't issued orders, which is impossible for these as they are paused and far out of the way. They aren't even selectable.

I'm just quite curious about it o-o.

I'm glad you asked. The two dummies are different in one or two other ways than name. One regenerates health during the day, the other during the night. Like humans and night elves. This is so it can work even with moonstones. It's an ingenious design on the part of Jesus4Lyf.

You should put those into method operators in a struct so that they are readonly >.>.

I would rather make them wrapper functions, but both solutions are rather ugly. The only way this would break is if users are doing it deliberately, in which case one can break damn near anything.
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
I'm glad you asked. The two dummies are different in one or two other ways than name. One regenerates health during the day, the other during the night. Like humans and night elves. This is so it can work even with moonstones. It's an ingenious design on the part of Jesus4Lyf.

That's what I figured, but I couldn't read the object merger code without looking in Object Editor ; D.

I don't believe any maps go that high. This is precisely the point. Units outside the map area don't crash as long as they aren't issued orders, which is impossible for these as they are paused and far out of the way. They aren't even selectable.

Ahh, I see. Actually, Fort Wars, a map I'm working on, goes to either 32k or 38k, so sadly I'd have to configure ur system for use in my own map if I wanted to use it :\. Fort Wars is 480x480.

Assumptions are always a bad idea ; P.
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
I can fix that. Just gotta add a zero to each.

haha, you're a brute force kinda guy aren't you : P

And is there a reason for these lines?
JASS:
    //call ShowUnit(DayU, false)
    //call ShowUnit(NightU, false)

Other than that, I'd register conditions or actions rather than triggers to improve the speed a little bit more and lower the memory. It'd also relinquish the need for the Event lib. That's kind of personal preference, but I don't see why you'd ever need to unregister a trigger from something like this, and if you do, could just as easily do it off of actions rather than triggers because I don't see the need to do groups of actions or w/e.

Those are just my opinions anyways = D.
 
Level 17
Joined
Jun 17, 2007
Messages
1,433
Somehow I feel like submitting this was a shot at deprecating my system. ;)

This is a nifty method and all, but it feels needlessly complicated when it could be simplified into something like this:
JASS:
library DayNightEvent

globals
    private real NIGHT = 18.
    private real DAY = 6.
endglobals

constant function TriggerRegisterDay takes trigger trig returns nothing
    call TriggerRegisterGameStateEvent(trig, GAME_STATE_TIME_OF_DAY, GREATER_THAN, DAY)
endfunction

constant function TriggerRegisterNight takes trigger trig returns nothing
    call TriggerRegisterGameStateEvent(trig, GAME_STATE_TIME_OF_DAY, GREATER_THAN, NIGHT)
endfunction

endlibrary
That would inline completely.
 
Level 17
Joined
Jun 17, 2007
Messages
1,433
You need to read the first post to see why he used units over the events ; P.
I did the read first, and quite frankly it would be far more sensible to detect the use of moonstones directly.

azlier had this system at th but it was sitting in submission limbo ; D.
And, he decided to submit this within a day of reviewing my submission. Hardly a coincidence.

--
Also, azlier, can't you follow your own section's submission guidelines? ;)
 
I don't believe any maps go that high. This is precisely the point. Units outside the map area don't crash as long as they aren't issued orders, which is impossible for these as they are paused and far out of the way. They aren't even selectable.
What about EnumUnitsOfPlayer() functions? People still use these, you know, for example to select locust units. Why not place the unit on MAP_MAX_X and MAP_MAX_Y, give it locust, pause it and hide it?
 
Level 13
Joined
May 11, 2008
Messages
1,198
>I don't believe any maps go that high.

ALL of my maps go that high! (a few old gui mods being exceptions)

btw you guys tried to outdo my pathetic idea for a system for this by making it. imo you should credit me for inspiring you.

> This is precisely the point. Units outside the map area don't crash as long as they aren't issued orders, which is impossible for these as they are paused and far out of the way. They aren't even selectable.

so when 10000,10000 exists is this still applicable?
so what? we just increase the number until we get something that goes off the map?

>I'm glad you asked. The two dummies are different in one or two other ways than name. One regenerates health during the day, the other during the night. Like humans and night elves. This is so it can work even with moonstones. It's an ingenious design on the part of Jesus4Lyf.

yeah, that's kindof interesting i guess...anyways analyzing this system has been put on hold for me for a long time because there are a lot of other concerns with the map i had it in mind for at the moment. anyway i'm currently working on a map where day and nnight won't really have any meaning...so...

anyway i think it was in submission limbo for one or two of two reasons:
1)j4l knew he was inspired by me but az wouldn't credit me...
2)nobody really said it was awesome and they're going to use it for sure

of course 1 is az's fault, 2 is my fault/others' fault.

really, i was not adept at figuringthings out back then...i don't think i could understand how the system works. now, though, i think i know how. i'll have to post a spellpack or two one of these days with this system in it, i guess. then he can be in my credits, lol.

edit: actually i guess i know now how it works just because now i sortof know how event works, the system that this one uses works. just because i've started using some other systems that use the event system. man, that system is good stuff.
 
Level 7
Joined
Oct 11, 2008
Messages
304
>> 1)j4l knew he was inspired by me but az wouldn't credit me...

let see what Jesus4Lyf says before do anything... just because you talk with him something and then this system become alive... so what? it don't mean nothing... something else can inspire J4L then u

>> 2)nobody really said it was awesome and they're going to use it for sure

it is awesome system and i use it :)

happy?

and yes.. i REALLY like this (i use this since it was in grave at thehelper)
 
Level 13
Joined
May 11, 2008
Messages
1,198
>> 1)j4l knew he was inspired by me but az wouldn't credit me...

let see what Jesus4Lyf says before do anything... just because you talk with him something and then this system become alive... so what? it don't mean nothing... something else can inspire J4L then u

>> 2)nobody really said it was awesome and they're going to use it for sure

it is awesome system and i use it :)

happy?

and yes.. i REALLY like this (i use this since it was in grave at thehelper)

haha, ok. yeah i use jBoard and i think it's awesome and as far as i know it's not accepted as a resource at wc3c.net or thehelper...it's like graveyard or stuck in submissions...yeah i don't think this shouldn't be approved then.

but i do wonder about those questions i asked about it in me last post.

about it was my idea... point was that i was trying to figure out how to make a system for changing abilities...i failed...but it was because of the day/night switching and these guys saw my attempt at make a system, laughed and said...yeah i think i can do this thing for you...to tell the truth, they only accomplished about half of what i wanted done...but i don't think it's possible to code the other half, anyway. so this is a system made based on my request.

obviously i didn't assist in coding anything, though. anyway, you seemed to misunderstand my post about that matter.
 
Top