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.
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 = 039;dadt039;
private constant integer NIGHT = 039;nidt039;
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