- Joined
- Mar 15, 2017
- Messages
- 96
A simplified day or night detection with Register Event...
Demo:
Thanks to Banaar for telling me to use modules instead of initializer
vJASS:
library IsDayNight/* v1.1.0
****************************************************************************************************
* Is Day or Night
* By: BloodForBlood
*
* A simple day or night detector.
*
* How to Implement:
* Copy the dummy unit(TimeIdentifier) to your map
* then copy this library.Or use the ObjectMerger
* above "globals".
*
* API:
* function IsDay takes nothing returns boolean
* function IsNight takes nothing returns boolean
* function RegisterDayEvent takes code c returns nothing
* function RegisterNightEvent takes code c returns nothing
*
* Credits:
* Bannar - for giving me a dummy unit idea
* Original Creator - if there are an original creator of IsDayNight
* Wareditor - for the Dummy Unit ObjectMerger script
*
***************************************************************************************************/
// external ObjectMerger w3u hpea uNyt ufoo 0 uabi Aloc,Ambt umdl " " usca 0 ushu " " unam "TimeIdentifier" unsf "(IsDayNight)" util 0 uhpm 100 uhpr 100 uhrt "day" umpm 100 umpi 1 umpr 100
globals
private constant integer IDENTIFIER_ID = 'uNyt' // Change this to the proper id of the dummy
//==============Dont Modify Below==============
private boolean BOOL = false
private unit DUMMY
private trigger array TRIG
private boolean array EVENT
endglobals
function IsDay takes nothing returns boolean
return BOOL
endfunction
function IsNight takes nothing returns boolean
return not BOOL
endfunction
function RegisterDayEvent takes code c returns nothing
call TriggerAddCondition(TRIG[1], Filter(c))
endfunction
function RegisterNightEvent takes code c returns nothing
call TriggerAddCondition(TRIG[2], Filter(c))
endfunction
private function identifierNight takes nothing returns boolean
set BOOL = false
if (not EVENT[2]) then
set EVENT[1] = false
set EVENT[2] = true
call TriggerEvaluate(TRIG[2])
endif
call SetUnitState(DUMMY, UNIT_STATE_MANA, 1)
return false
endfunction
private function identifierDay takes nothing returns boolean
set BOOL = true
if (not EVENT[1]) then
set EVENT[1] = true
set EVENT[2] = false
call TriggerEvaluate(TRIG[1])
endif
call SetWidgetLife(DUMMY, 1)
return false
endfunction
private module m
private static method onInit takes nothing returns nothing
local rect r = GetWorldBounds()
local trigger t = CreateTrigger()
set TRIG[1] = CreateTrigger()
set TRIG[2] = CreateTrigger()
set DUMMY = CreateUnit(Player(15), IDENTIFIER_ID, GetRectMaxX(r), GetRectMaxY(r), 0)
call SetWidgetLife(DUMMY, 1)
call SetUnitState(DUMMY, UNIT_STATE_MANA, 1)
call PauseUnit(DUMMY, true)
call ShowUnit(DUMMY, false)
call TriggerRegisterUnitStateEvent(t, DUMMY, UNIT_STATE_LIFE, GREATER_THAN_OR_EQUAL, 2)
call TriggerAddCondition(t, Condition(function identifierDay))
set t = CreateTrigger()
call TriggerRegisterUnitStateEvent(t, DUMMY, UNIT_STATE_MANA, GREATER_THAN_OR_EQUAL, 2)
call TriggerAddCondition(t, Condition(function identifierNight))
call RemoveRect(r)
set r = null
set t = null
endmethod
endmodule
private struct s
implement m
endstruct
endlibrary
vJASS:
scope Demo initializer onInit
private function day takes nothing returns nothing
call BJDebugMsg("It's morning,wake up!")
endfunction
private function night takes nothing returns nothing
call BJDebugMsg("It's nighttime,time to sleep!")
endfunction
private function esc takes nothing returns nothing
if (IsDay()) then
call BJDebugMsg("Day")
endif
if (IsNight()) then
call BJDebugMsg("Night")
endif
endfunction
private function onInit takes nothing returns nothing
local trigger t = CreateTrigger()
if (IsNight()) then
call FogEnable(false)
call FogMaskEnable(false)
endif
call RegisterDayEvent(function day)
call RegisterNightEvent(function night)
call TriggerRegisterPlayerEvent(t, Player(0), EVENT_PLAYER_END_CINEMATIC)
call TriggerAddAction(t, function esc)
call BJDebugMsg("Press ESC to test IsDay/IsNight functions")
endfunction
endscope
Attachments
Last edited: