System Custom Day and Night System

SanKakU

Member
Reaction score
21
I'm not prepared yet to post a test map, as I think the code can be improved, and i haven't yet worked on terrain or whatever for a test map...

i am using the system and it works great...but seeing as the code can probably be improved, i want to post that here, and get some input on that. then i can make a test map and submit it if things look good.

trigger called initial lighting day
JASS:
//this is according to how long the day is...
//because it starts at 13 and war3 automarically has dusk at 18
//and there's nothing you can do about that...
//instead of bothering with war3's imperfect midnight...
//this system uses only dusk and dawn...when it's dawn, it's dawn
//and to make matters simple, at game start it is dawn...that's what this trigger does
//it sets the game start time to dawn.
//you can change the sound if you like to whatever you want.
//go to sound editor, find a sound you want, use it, and give it
//a variable name, my variable names were thelightiswithus and thenightbeckons
//edit:
//actually now that i think about it this is the best way i can think of, to start it
//at 13...because 23 is 5 from 18 as is 13.  and at 24 the game goes to 0
//you can of course change your numbers to like 23.5 and 12.5 if you want...
//that's up to you.  or you can make the day shorter!  haha.
//of course you can also change the speed of the day too, so making the days
//ten hours long isn't so bad, you can choose to make the day longer.
//i believe you have to use the map's gameplay constants to do that.
function Trig_initialweatherday_Actions takes nothing returns nothing
set bj_dawnSound = gg_snd_thelightiswithus//this is my custom dawn sound
set bj_duskSound = gg_snd_thenightbeckons//this is my custom dusk/sunset sound
    call SetFloatGameState(GAME_STATE_TIME_OF_DAY, 13.00)
endfunction

//===========================================================================
function InitTrig_initiallightingday takes nothing returns nothing
    set gg_trg_initiallightingday = CreateTrigger(  )
    call TriggerAddAction( gg_trg_initiallightingday, function Trig_initialweatherday_Actions )
endfunction


trigger called night and day
JASS:
//I'm submitting this system in hopes that people will recommend how it can be improved, but also because
//nobody tried to make a system like this and i think it's very useful.

scope customdayandnightsystem initializer I
globals
private trigger t3 = CreateTrigger()//daydawnabilitychanges
private trigger t2 = CreateTrigger()//nightfallabilitychanges
private trigger t1 = CreateTrigger()//clockadjustment

//these auras are just set aside for when i need them, they have nothing to do with the
// custom day and night system
constant integer TerrorAura ='A047'
constant integer BrillianceAura ='A03D'
constant integer EnduranceAura ='A03E'
constant integer WarDrumsAura ='A03I'
constant integer UnholyAura='A03F'
constant integer VampiricAura ='A03G'
constant integer SlowAura='A03H'
constant integer GeneralAuraDummy ='AGnA'

//these are the ability and buff codes that the day and night system uses
//your abilities will probably be different, as may be your ability replacing actions...
constant integer DestroyEnergyDummy ='A00Q'
constant integer DestroyMagicDummy ='A00P'
constant integer DestroyEnergy ='A00S'
constant integer DestroyMagic ='A00N'
constant integer DispelMagicNormal='A00O'
constant integer HeightenedAgilityOFFDAY='A006'
constant integer HeightenedAgilityOFFNIGHT='A005'
constant integer HeightenedAgilityONDAY='A004'
constant integer HeightenedAgilityONNIGHT='A002'
constant integer HeightenedAgilityDUMMYDAY ='A00D'
constant integer HeightenedAgilityDUMMYNIGHT ='A00E'
constant integer TimeOfDayAgilityItem ='A00I'
constant integer DayStrikeDummy ='A00F'
constant integer NightStrikeDummy='A00B'
constant integer ColdStrikeNIGHT='A008'
constant integer HeatStrikeDAY ='A00A'
constant integer NightStrikeDAY='A007'
constant integer DayStrikeNIGHT ='A009'
constant integer NIGHTWALK='B000'
constant integer DAYWALK ='B001'
constant integer ColdStorm ='A00K'
constant integer AvengingFlames ='A00M'



//UNUSED?//i'm not sure what these are for but i guess i don't trigger them, but somewhere
//they have something to do with the abilities in the day and night system...
constant integer DAYAGILITY='B002'
constant integer NIGHTAGILITY ='B003'


endglobals
//textmacro time
//! textmacro RemoveUnitsFromGroup takes UNIT, GROUP
    loop
        set $UNIT$ = FirstOfGroup($GROUP$)
        exitwhen $UNIT$ == null
        call GroupRemoveUnit($GROUP$, PickedUnit)
    endloop
//! endtextmacro
//! textmacro groupup takes prefix
call GroupEnumUnitsInRect(g, bj_mapInitialPlayableArea,Condition(function $prefix$filter))
    call ForGroup(g, function $prefix$act )
//! endtextmacro
//! textmacro groupupd takes prefix
call GroupEnumUnitsInRect(g, bj_mapInitialPlayableArea,Condition(function $prefix$filter))
    call ForGroup(g, function $prefix$actd )
//! endtextmacro

//this section will probably look different for you
//feel free rename the functions and variables and whatever
//basically, these are the functions called when night time comes.
private function agilnfilter takes nothing returns boolean
    return ( GetUnitAbilityLevel( GetFilterUnit(), HeightenedAgilityDUMMYNIGHT) > 0 )
endfunction

private function agilnact takes nothing returns nothing
    call UnitRemoveAbility(GetEnumUnit(), HeightenedAgilityOFFNIGHT)
    call UnitAddAbility(GetEnumUnit(), HeightenedAgilityONNIGHT)
    call SetUnitAbilityLevel(GetEnumUnit(), HeightenedAgilityONNIGHT, GetUnitAbilityLevel(GetEnumUnit(),HeightenedAgilityDUMMYNIGHT) )
    call UnitAddAbility(GetEnumUnit(), TimeOfDayAgilityItem)
    call SetUnitAbilityLevel(GetEnumUnit(), TimeOfDayAgilityItem, GetUnitAbilityLevel(GetEnumUnit(),HeightenedAgilityDUMMYNIGHT) )
endfunction

private function nsfilter takes nothing returns boolean
    return ( GetUnitAbilityLevel(GetFilterUnit(),NightStrikeDummy) > 0 )
endfunction

private function nsact takes nothing returns nothing
    call UnitRemoveAbility(GetEnumUnit(), NightStrikeDAY )
    call UnitAddAbility(GetEnumUnit(), ColdStrikeNIGHT )
    call SetUnitAbilityLevel(GetEnumUnit(), ColdStrikeNIGHT, GetUnitAbilityLevel(GetEnumUnit(),NightStrikeDummy) )
endfunction

private function agildfilter takes nothing returns boolean
    return ( GetUnitAbilityLevel(GetFilterUnit(),HeightenedAgilityDUMMYDAY) > 0 )
endfunction

private function agildact takes nothing returns nothing
    call UnitRemoveAbility(GetEnumUnit(), HeightenedAgilityONDAY )
    call UnitAddAbility(GetEnumUnit(), HeightenedAgilityOFFDAY )
    call SetUnitAbilityLevel(GetEnumUnit(), HeightenedAgilityOFFDAY, GetUnitAbilityLevel(GetEnumUnit(),HeightenedAgilityDUMMYDAY) )
    call UnitRemoveAbility(GetEnumUnit(), TimeOfDayAgilityItem )
endfunction

private function dsfilter takes nothing returns boolean
    return ( GetUnitAbilityLevel(GetFilterUnit(),DayStrikeDummy) > 0 )
endfunction

private function dsact takes nothing returns nothing
    call UnitRemoveAbility(GetEnumUnit(), HeatStrikeDAY )
    call UnitAddAbility(GetEnumUnit(), DayStrikeNIGHT )
    call SetUnitAbilityLevel(GetEnumUnit(), DayStrikeNIGHT, GetUnitAbilityLevel(GetEnumUnit(),DayStrikeDummy) )
endfunction

private function dmfilter takes nothing returns boolean
    return ( GetUnitAbilityLevel(GetFilterUnit(),DestroyMagicDummy) > 0 )
endfunction

private function dmact takes nothing returns nothing
    call UnitRemoveAbility(GetEnumUnit(), DestroyMagic )
    call UnitAddAbility(GetEnumUnit(), DispelMagicNormal )
    call SetUnitAbilityLevel(GetEnumUnit(), DispelMagicNormal, GetUnitAbilityLevel(GetEnumUnit(),DestroyMagicDummy) )
endfunction

private function defilter takes nothing returns boolean
    return ( GetUnitAbilityLevel(GetFilterUnit(),DestroyEnergyDummy) > 0 )
endfunction

private function deact takes nothing returns nothing
    call UnitRemoveAbility(GetEnumUnit(), DispelMagicNormal )
    call UnitAddAbility(GetEnumUnit(), DestroyEnergy )
    call SetUnitAbilityLevel(GetEnumUnit(), DestroyEnergy, GetUnitAbilityLevel(GetEnumUnit(),DestroyEnergyDummy) )
endfunction
//now we have the text macro, again, the names of the textmacro takes
//may probably look different for you...the only difference between
//these textmacro and the others is that they're calling the opposite functions
private function A takes nothing returns boolean
    local group g = CreateGroup()
    local unit PickedUnit = null
    
//Eithyr deserves credit for the textmacro RemoveUnitsFromGroup...
//i did not at that time understand textmacro
//i made the other textmacro after i found out how to make them
//Jesus4Lyf taught me textmacro, thanks.
//also this system is really retarded if you do not use
//preloading for your spells and abilities.
    
    //! runtextmacro groupup("agiln")
    //! runtextmacro RemoveUnitsFromGroup("PickedUnit", "g")
    //! runtextmacro groupup("agild")
    //! runtextmacro RemoveUnitsFromGroup("PickedUnit", "g")
    //! runtextmacro groupup("ns")
    //! runtextmacro RemoveUnitsFromGroup("PickedUnit", "g")
    //! runtextmacro groupup("ds")
    //! runtextmacro RemoveUnitsFromGroup("PickedUnit", "g")
    //! runtextmacro groupup("dm")
    //! runtextmacro RemoveUnitsFromGroup("PickedUnit", "g")
    //! runtextmacro groupup("de")
    //! runtextmacro RemoveUnitsFromGroup("PickedUnit", "g")
    set g = null
    return false
endfunction


//this section will probably look different for you
//feel free rename the functions and variables and whatever
//basically, these are the functions called when day time comes.

private function agilnactd takes nothing returns nothing
    call UnitRemoveAbility(GetEnumUnit(), HeightenedAgilityONNIGHT )
    call UnitAddAbility(GetEnumUnit(), HeightenedAgilityOFFNIGHT )
    call SetUnitAbilityLevel(GetEnumUnit(), HeightenedAgilityOFFNIGHT, GetUnitAbilityLevel(GetEnumUnit(),HeightenedAgilityDUMMYNIGHT) )
    call UnitRemoveAbility(GetEnumUnit(), TimeOfDayAgilityItem )
endfunction

private function nsactd takes nothing returns nothing
    call UnitRemoveAbility(GetEnumUnit(), ColdStrikeNIGHT )
    call UnitAddAbility(GetEnumUnit(), NightStrikeDAY )
    call SetUnitAbilityLevel(GetEnumUnit(), NightStrikeDAY, GetUnitAbilityLevel(GetEnumUnit(),NightStrikeDummy) )
endfunction

private function dsactd takes nothing returns nothing
    call UnitRemoveAbility(GetEnumUnit(), DayStrikeNIGHT )
    call UnitAddAbility(GetEnumUnit(), HeatStrikeDAY )
    call SetUnitAbilityLevel(GetEnumUnit(), HeatStrikeDAY, GetUnitAbilityLevel(GetEnumUnit(),DayStrikeDummy) )
endfunction

private function agildactd takes nothing returns nothing
    call UnitRemoveAbility(GetEnumUnit(), HeightenedAgilityOFFDAY )
    call UnitAddAbility(GetEnumUnit(), HeightenedAgilityONDAY )
    call SetUnitAbilityLevel(GetEnumUnit(), HeightenedAgilityONDAY, GetUnitAbilityLevel(GetEnumUnit(),HeightenedAgilityDUMMYDAY) )
    call UnitAddAbility(GetEnumUnit(), TimeOfDayAgilityItem )
    call SetUnitAbilityLevel(GetEnumUnit(), TimeOfDayAgilityItem, GetUnitAbilityLevel(GetEnumUnit(),HeightenedAgilityDUMMYDAY) )
endfunction

private function dmactd takes nothing returns nothing
    call UnitRemoveAbility(GetEnumUnit(), DispelMagicNormal )
    call UnitAddAbility(GetEnumUnit(), DestroyMagic )
    call SetUnitAbilityLevel(GetEnumUnit(), DestroyMagic, GetUnitAbilityLevel(GetEnumUnit(),DestroyMagicDummy) )
endfunction

private function deactd takes nothing returns nothing
    call UnitRemoveAbility(GetEnumUnit(), DestroyEnergy )
    call UnitAddAbility(GetEnumUnit(), DispelMagicNormal )
    call SetUnitAbilityLevel(GetEnumUnit(), DispelMagicNormal, GetUnitAbilityLevel(GetEnumUnit(),DestroyEnergyDummy) )
endfunction
//now we have the text macro, again, the names of the textmacro takes
//may probably look different for you...the only difference between
//these textmacro and the others is that they're calling the opposite functions
private function a takes nothing returns boolean
    local group g = CreateGroup()
    local unit PickedUnit = null
    
//Eithyr deserves credit for the textmacro RemoveUnitsFromGroup...
//i did not at that time understand textmacro
//i made the other textmacro after i found out how to make them
//Jesus4Lyf taught me textmacro, thanks.
//also this system is really retarded if you do not use
//preloading for your spells and abilities.
    
    //! runtextmacro groupupd("agiln")
    //! runtextmacro RemoveUnitsFromGroup("PickedUnit", "g")
    //! runtextmacro groupupd("agild")
    //! runtextmacro RemoveUnitsFromGroup("PickedUnit", "g")
    //! runtextmacro groupupd("ns")
    //! runtextmacro RemoveUnitsFromGroup("PickedUnit", "g")
    //! runtextmacro groupupd("ds")
    //! runtextmacro RemoveUnitsFromGroup("PickedUnit", "g")
    //! runtextmacro groupupd("dm")
    //! runtextmacro RemoveUnitsFromGroup("PickedUnit", "g")
    //! runtextmacro groupupd("de")
    //! runtextmacro RemoveUnitsFromGroup("PickedUnit", "g")
    set g = null
    return false
endfunction
//see this one was called groupupd d meaning daytime version
//the other one is for nighttime.



//this function keeps it all together.  without it, custom day and night system is not possible
private function b takes nothing returns boolean
    call SetFloatGameState(GAME_STATE_TIME_OF_DAY, 13.00)//this 13.00 is dawn, the first minute of the day
    call StartSound(bj_dawnSound)//it's not really dawn without this sound...
    return false
endfunction

//===========================================================================
private function I takes nothing returns nothing

    call TriggerRegisterGameStateEventTimeOfDay( t1, GREATER_THAN_OR_EQUAL, 23.00 )//this is also dawn
    call TriggerAddCondition( t1, Condition( function b ) )//this calls the function that keeps it all together
    call TriggerRegisterGameStateEventTimeOfDay( t2, GREATER_THAN_OR_EQUAL, 18.00 )//this is dusk/sunset
    call TriggerAddCondition( t2, Condition( function A ) )//calling night time conditions because it's night
    call TriggerRegisterGameStateEventTimeOfDay( t3, LESS_THAN, 18.00 )//this is before dusk/sunset
    call TriggerAddCondition( t3, Condition( function a ) )//calling day time conditions because it's day
endfunction

endscope


an example trigger:
JASS:
//this is just an example of something you can do to enhance an ability if you wish...
//it's not a super awesome spell or anything...it's just checking for time of day and acting accordingly...
//of course you'll notice it's doing it by checking the ability, because the ability is swapped
//according to the time of day...it's all kindof complicated...hopefully the constant integer names
//help things to make more sense...

function Trig_strike_Actions takes nothing returns nothing
    if GetUnitAbilityLevel(GetAttacker(), NIGHTWALK) >= 1 then
        call UnitDamageTarget( GetAttacker(), GetTriggerUnit(), ( ( GetUnitMoveSpeed(GetAttacker()) - GetUnitMoveSpeed(GetTriggerUnit()) ) * I2R(GetUnitAbilityLevel(GetAttacker(),NightStrikeDummy)) ), false, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_UNIVERSAL, WEAPON_TYPE_WHOKNOWS )       
    else
    if GetUnitAbilityLevel(GetAttacker(), DAYWALK) >= 1 then
        call UnitDamageTarget( GetAttacker(), GetTriggerUnit(), ( ( GetUnitMoveSpeed(GetAttacker()) - GetUnitMoveSpeed(GetTriggerUnit()) ) * I2R(GetUnitAbilityLevel(GetAttacker(),DayStrikeDummy)) ), false, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_UNIVERSAL, WEAPON_TYPE_WHOKNOWS )
    endif
    endif
endfunction

//===========================================================================
function InitTrig_strike takes nothing returns nothing
    set gg_trg_strike = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_strike, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddAction( gg_trg_strike, function Trig_strike_Actions )
endfunction
//i might have to rewrite these spells with a different event...
//event unit damaged might do damage after windwalk disappears instead of before...
//another idea is to rewrite how much damage is done to creeps or heroes in order to
//balance things...one shotting all the creeps seems kindof unfair...?
//another thing to look at is if they are doing damage properly when not in windwalk mode...
//another idea is to give creeps additional hp, towers too...

oh wow, almost forgot this one...
it has other unrelated stuff in it, but it's a very important trigger that helps prevent bugs in the system...
the textmacro in this trigger can probably be used elsewhere in the other triggers, but it's sortof more critical here...doesn't make much of a difference, but it is a lot more pleasing to the eye using this textmacro ifnight and ifday...
JASS:
scope spellsEPHS initializer I




//! textmacro ifnight
if GetFloatGameState(GAME_STATE_TIME_OF_DAY) >= 18.00 then
//! endtextmacro
//! textmacro ifday
if GetFloatGameState(GAME_STATE_TIME_OF_DAY) < 18.00 then
//! endtextmacro

private function A takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local integer i = GetLearnedSkill()
    local integer ii= 0
    if i == NightStrikeDummy then
    //! runtextmacro ifnight()
    call UnitRemoveAbility(u, NightStrikeDAY)
    call UnitAddAbility(u, ColdStrikeNIGHT)
    call SetUnitAbilityLevel(u, ColdStrikeNIGHT, GetUnitAbilityLevel(u,i) )
    else
    call UnitRemoveAbility(u, ColdStrikeNIGHT)
    call UnitAddAbility(u, NightStrikeDAY)
    call SetUnitAbilityLevel( u, NightStrikeDAY, GetUnitAbilityLevel(u,i) )
    call SetUnitAbilityLevel( u, NightStrikeDAY, GetUnitAbilityLevel(u,i) )
    endif
    elseif i == HeightenedAgilityDUMMYNIGHT then
    //! runtextmacro ifnight()
    call UnitRemoveAbility(u, HeightenedAgilityOFFNIGHT)
    call UnitAddAbility(u, HeightenedAgilityONNIGHT)
    call SetUnitAbilityLevel( u,HeightenedAgilityONNIGHT,  GetUnitAbilityLevel(u,i) )
    call UnitAddAbility(u, TimeOfDayAgilityItem)
    call SetUnitAbilityLevel( u,TimeOfDayAgilityItem,  GetUnitAbilityLevel(u,i) )
    else
    call UnitRemoveAbility(u, TimeOfDayAgilityItem)
    call UnitRemoveAbility(u, HeightenedAgilityONNIGHT)
    call UnitAddAbility(u, HeightenedAgilityOFFNIGHT)
    call SetUnitAbilityLevel(u, HeightenedAgilityOFFNIGHT, GetUnitAbilityLevel(u,i) )
    endif
    elseif i == DestroyEnergyDummy then
    //! runtextmacro ifnight()
    call UnitRemoveAbility(u, DispelMagicNormal)
    call UnitAddAbility(u, DestroyEnergy)
    call SetUnitAbilityLevel(u, DestroyEnergy, GetUnitAbilityLevel(u,i) )
    else
    call UnitRemoveAbility(u, DestroyEnergy)
    call UnitAddAbility(u, DispelMagicNormal)
    call SetUnitAbilityLevel(u, DispelMagicNormal, GetUnitAbilityLevel(u,i) )
    endif
    elseif i == DayStrikeDummy then
    //! runtextmacro ifday()
    call UnitRemoveAbility(u, DayStrikeNIGHT)
    call UnitAddAbility(u, HeatStrikeDAY)
    call SetUnitAbilityLevel(u, HeatStrikeDAY, GetUnitAbilityLevel(u,i) )
    else
    call UnitRemoveAbility(u, HeatStrikeDAY)
    call UnitAddAbility(u, DayStrikeNIGHT)
    call SetUnitAbilityLevel( u, DayStrikeNIGHT, GetUnitAbilityLevel(u,i) )
    endif
    elseif i == HeightenedAgilityDUMMYDAY then
    //! runtextmacro ifday()
    call UnitRemoveAbility(u, HeightenedAgilityOFFDAY)
    call UnitAddAbility(u, HeightenedAgilityONDAY)
    call SetUnitAbilityLevel( u,HeightenedAgilityONDAY,  GetUnitAbilityLevel(u,i) )
    call UnitAddAbility(u, TimeOfDayAgilityItem)
    call SetUnitAbilityLevel( u,TimeOfDayAgilityItem,  GetUnitAbilityLevel(u,i) )
    else
    call UnitRemoveAbility(u, TimeOfDayAgilityItem)
    call UnitRemoveAbility(u, HeightenedAgilityONDAY)
    call UnitAddAbility(u, HeightenedAgilityOFFDAY)
    call SetUnitAbilityLevel(u, HeightenedAgilityOFFDAY, GetUnitAbilityLevel(u,i) )
    endif
    elseif i == DestroyMagicDummy then
    //! runtextmacro ifday()
    call UnitRemoveAbility(u, DispelMagicNormal)
    call UnitAddAbility(u, DestroyMagic)
    call SetUnitAbilityLevel(u, DestroyMagic, GetUnitAbilityLevel(u,i) )
    else
    call UnitRemoveAbility(u, DestroyMagic)
    call UnitAddAbility(u, DispelMagicNormal)
    call SetUnitAbilityLevel(u, DispelMagicNormal, GetUnitAbilityLevel(u,i) )
    endif
    elseif i == 'A011' then//cntrlmgc
    call UnitAddAbility(u, 'A010')//spllstl
    call SetUnitAbilityLevel(u, 'A010', GetUnitAbilityLevel(u,i) )
    elseif i == 'A01H' then//unholyaura(sinister)
    call SetUnitAbilityLevel(u, 'A01I', (GetUnitAbilityLevel(u,i)+1) )//raisedead
    elseif i == 'A04R' then//fieryfury
    call AddPlayerTechResearched(GetOwningPlayer(u),'R00B',1)//lavalordatkspdbns
    endif
    set u = null
endfunction

//===========================================================================
private function I takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    local integer index = 2
    loop
    call TriggerRegisterPlayerUnitEvent( t, Player(index),EVENT_PLAYER_HERO_SKILL, Filter(function FilterDebug) )
    set index = index + 1
    exitwhen index == 11
    endloop
    call TriggerAddAction( t, function A )
   // set bj_lastCreatedUnit = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), 'e008', 380, 380, 0)
    call XE_PreloadAbility( 'A01H')
    call XE_PreloadAbility( 'A011')
    call XE_PreloadAbility( DestroyMagicDummy)
    call XE_PreloadAbility( HeightenedAgilityDUMMYDAY)
    call XE_PreloadAbility( DayStrikeDummy)
    call XE_PreloadAbility( DestroyEnergyDummy)
    call XE_PreloadAbility( HeightenedAgilityDUMMYNIGHT)
    call XE_PreloadAbility( NightStrikeDummy)
    call XE_PreloadAbility( ColdStrikeNIGHT)
    call XE_PreloadAbility( NightStrikeDAY)
    call XE_PreloadAbility( HeightenedAgilityONNIGHT)
    call XE_PreloadAbility( TimeOfDayAgilityItem)
    call XE_PreloadAbility( HeightenedAgilityOFFNIGHT)
    call XE_PreloadAbility( DispelMagicNormal)
    call XE_PreloadAbility( DestroyEnergy)
    call XE_PreloadAbility( DayStrikeNIGHT)
    call XE_PreloadAbility( HeatStrikeDAY)
    call XE_PreloadAbility( HeightenedAgilityOFFDAY)
    call XE_PreloadAbility( HeightenedAgilityONDAY)
    call XE_PreloadAbility( DestroyMagic)
    call XE_PreloadAbility( 'A010')
    call XE_PreloadAbility( 'A01I')
    call XE_PreloadAbility( 'A04R')
    call XE_PreloadAbility( 'R00B')
    call XE_PreloadAbility( 'A06H')
    call XE_PreloadAbility( 'A066')
 //   call KillUnit(bj_lastCreatedUnit)
endfunction

endscope


as you can see right now my system is currently using libraries and such like xepreload or even taf which is my map's special library...

i think i can definitely improve on my system but i don't really know where to start...
oh and here's a snippet from a crazy trigger i've been working on combining many spells into one event spell effect trigger...it might not be a good idea but whatever...as you can see it's a simple dummy cast thing if and only if the spell is being cast at a proper time of day...think like night stalker and using one of his spells that has a greater impact at night time...
well with my system you can do it for a day time dude too...not just night time...that's the entire point of this day and night system.
JASS:
    //flame storm speedup effect
    //made by SanKakU so please give credits if you use this spell in your map
    else
    if i == AvengingFlames then
    if GetFloatGameState(GAME_STATE_TIME_OF_DAY) < 18.00 then
    set u = CreateUnit(GetOwningPlayer(GetSpellAbilityUnit()), 'e000', ux, uy, 270.00)
    call UnitAddAbility(u, 'A00Z')
    call SetUnitAbilityLevel(u, 'A00Z', GetUnitAbilityLevel(GetSpellAbilityUnit(),AvengingFlames))
    call UnitApplyTimedLife(u, 'BTLF', 5.0)
    endif
    else
    //coldstorm slow effect
    //made by SanKakU so please give credits if you use this spell in your map
    if i == ColdStorm then
    if GetFloatGameState(GAME_STATE_TIME_OF_DAY) >= 18.00 then
    set u = CreateUnit(GetOwningPlayer(GetSpellAbilityUnit()), 'e000', ux, uy, 270.00)
    call UnitAddAbility(u, 'A00Y')
    call SetUnitAbilityLevel(u, 'A00Y', GetUnitAbilityLevel(GetSpellAbilityUnit(),ColdStorm))
    call UnitApplyTimedLife(u, 'BTLF', 5.0)
    endif
    else


i know things are a big mess right now...so please, some experts come along and clean it up for me, ok? you will of course be credited with helping if you do so...i know i'm not an expert programming and i know my place.

i mean...looking over my post...it seems to me like...i'm making a request for this bunch of code i wrote to be transformed into a system...or at least have someone explain to me how to do that, which would be preferable.
 

UndeadDragon

Super Moderator
Reaction score
447
Please indent your code. It makes it really difficult to read if it is one block of text.

Also, all of those functions can be put in one trigger, to simplify it a bit.
 

ElderKingpin

Post in the anime section, or die.
Reaction score
133
IM GUESSING. that instead of night turning into day in one quick move. it slowly changes into night and day. like real life (i guess?)
 

SanKakU

Member
Reaction score
21
UndeadDragon...don't whine about me not indenting...i don't like doing that.
as for making it all in one trigger...yeah i'm planning on it. i just haven't figured out how to yet.

Zwiebelchen, the system is to enable day time special abilities.

In warcraft 3, you can normally only enable night time abilities.

That's why there's a nightstalker in DOTA and there is the shadowmeld ability which you can only use at night.

With my system, you can go beyond just adding the night time abilities and also add some day time abilities. Just booleans can't pull this off.

That's why nobody has made any heroes or abilities dependant on if it's day time. I had to skip the 24 hour mark and change 23 to 13, which basically means that Warcraft 3 changes the clock from 24 to 0 at midnight. But things are complicated somewhere along the way, where exactly I forgot...to the point that it's necessary to make the 23 go to 13 and make that time be dawn, so that midnight is an unimportant hour. After all, midnight is not a critical hour, there is no dawn or dusk at that time.

ElderKingpin, that would be an interesting idea, but no, lol.

kingkingyyk3, how is it unreadable? i went to the trouble of adding a lot of comments to make it all more understandable... what's wrong with it? if it hits the graveyard i don't mind...i was kindof hoping someone would look at this and want to fix it up, but if that's not happening then that's the only place for it i reckon...
 

UndeadDragon

Super Moderator
Reaction score
447
kingkingyyk3, how is it unreadable? i went to the trouble of adding a lot of comments to make it all more understandable... what's wrong with it?

It is not indented. It is common practise to indent your code.
 

quraji

zap
Reaction score
144
I don't really get this. I'm not sure if you're trying to make custom day lengths or only allow abilities during the daytime/nighttime...

If you want to know if it's day, just use this.
JASS:
library DayOrNight

    globals
        real Dawn = 6.
        real Dusk = 18.
    endglobals
    
    function IsDaytime takes nothing returns boolean
        local real t = GetTimeOfDay()
        if (t>=Dawn or t<Dusk) then
            return true
        endif
        return false
    endfunction
    
endlibrary
 

tooltiperror

Super Moderator
Reaction score
231
The good seams like no one would use it, tbh.

And why not use the above function someone posted?
 

SanKakU

Member
Reaction score
21
I don't really get this. I'm not sure if you're trying to make custom day lengths or only allow abilities during the daytime/nighttime...

If you want to know if it's day, just use this.
JASS:
library DayOrNight

    globals
        real Dawn = 6.
        real Dusk = 18.
    endglobals
    
    function IsDaytime takes nothing returns boolean
        local real t = GetTimeOfDay()
        if (t>=Dawn or t<Dusk) then
            return true
        endif
        return false
    endfunction
    
endlibrary

what don't you understand about "Just booleans can't pull this off."? (rhetorical question, don't answer that)

I DID NOT MAKE THIS SYSTEM TO ARGUE ABOUT WHY IT'S NECESSARY...
I Honestly don't even remember where all the bugs are without me advancing it as far as I did.
But the bugs ARE there.

kingkingyyk3, you're probably right...

Everyone, just ignore the thread for now until I update the original post with something better. I don't want someone else thinking he's so smart coming in here telling me why the system isn't necessary...
 

Lyerae

I keep popping up on this site from time to time.
Reaction score
105
JASS:
library DayOrNight

    globals
        real Dawn = 6.
        real Dusk = 18.
    endglobals
    
    function IsDaytime takes nothing returns boolean
        local real t = GetTimeOfDay()
        if (t>=Dawn or t<Dusk) then
            return true
        endif
        return false
    endfunction
    
endlibrary


->

JASS:
library DayOrNight
function IsDaytime takes nothing returns boolean
        local real t = GetTimeOfDay()
        if (t >= 6.0 or t<18.) then
            return true
        endif
        return false
    endfunction
    
endlibrary

?
 

NetherHawk

New Member
Reaction score
26
i have a map i made which there is a hero like night stalker. All i do is check if the time is > 17.99 and < 06.01 , no problems or bugs. What bugs do u get.

JASS:
function IsNight takes nothing returns boolean
    return GetTimeOfDay() &gt; 17.99 or GetTimeOfDay() &lt; 6.01
endfunction


i noticed that if u use exact values like 18.00 or 6.00 sometimes the trigger bugs.
 

Narks

Vastly intelligent whale-like being from the stars
Reaction score
90
two function calls instead of one?
 

Executor

I see you
Reaction score
57
Well, an important attribute of systems/librarys is, that the user can actually READ the code and understand it for himself. It is rubbish to tell the users to change function names, because this requires them to understand the code before the modification, which is hardly possible with "... function A ..." etc.

Furthermore would you explain more in detail these aspects:
  • WHAT does this system do?
  • HOW can I access these functions?*
*I hope the user doesn't have to write code inside your library, because this is nonprofessional, unhandy and not our standard. Keyword = Interface.

Maybe you should remember that this section is for finished systems only. If you want to improve your system post it in "JASS Help".

And for god's sake, learn to FORMAT your code...

Did you want to do sth. like this?

JASS:
library DayAndNight initializer Init
    globals
        private constant real DUSK = 18.
        private constant real DAWN =  6.
    endglobals    
       
    globals
        private Event   DayToNight      = 0
        private Event   NightToDay      = 0
        private trigger OnDayToNight    = CreateTrigger()
        private trigger OnNightToDay    = CreateTrigger()
    endglobals
    
    function IsDay takes nothing returns boolean
        local real time = GetFloatGameState(GAME_STATE_TIME_OF_DAY)
        return time &gt;= DAWN and time &lt;= DUSK
    endfunction
    
    function IsNight takes nothing returns boolean
        local real time = GetFloatGameState(GAME_STATE_TIME_OF_DAY)
        return time &lt; DAWN or time &gt; DUSK
    endfunction
    
    function TriggerRegisterDayBecomesNight takes trigger t returns EventReg
        return DayToNight.register(t)
    endfunction 
    
    function TriggerRegisterNightBecomesDay takes trigger t returns EventReg
        return NightToDay.register(t)
    endfunction 
    
    private function OnDayToNightEx takes nothing returns boolean
        call DayToNight.fire()
        return false
    endfunction
    
    private function OnNightToDayEx takes nothing returns boolean
        call NightToDay.fire()
        return false
    endfunction
    
    private function Init takes nothing returns nothing
        set DayToNight = Event.create()
        set NightToDay = Event.create()
        
        call TriggerRegisterGameStateEvent(OnDayToNight, GAME_STATE_TIME_OF_DAY, EQUAL, DUSK)
        call TriggerRegisterGameStateEvent(OnNightToDay, GAME_STATE_TIME_OF_DAY, EQUAL, DAWN)
        call TriggerAddCondition(OnDayToNight, Condition( function OnDayToNightEx))
        call TriggerAddCondition(OnNightToDay, Condition( function OnNightToDayEx))
    endfunction
endlibrary


JASS:
scope LifeLeechInNightSpell initializer Init
    globals
        private             group       GROUP           = CreateGroup()
    
        private constant    integer     ID_UNIT         = &#039;abcd&#039;
        private constant    integer     ID_SPELL        = &#039;efgh&#039;
        private             trigger     onTimeChange    = CreateTrigger()
        
        private             boolean     Day
        private             boolexpr    AddAndRemoveLifeLeech
    endglobals
    
    private function FAddAndRemoveLifeLeech takes nothing returns boolean
        local unit u = GetFilterUnit()
        if GetUnitTypeId(u) != ID_UNIT then
            return false
        endif
        
        if Day then
            call UnitRemoveAbility(u,ID_SPELL)
        else
            call UnitAddAbility(u,ID_SPELL)
        endif        
        return false
    endfunction

    private function onTimeChangeEx takes nothing returns boolean
        set Day = IsDay()
        call GroupEnumUnitsInRect(GROUP,bj_mapInitialPlayableArea,AddAndRemoveLifeLeech)
        return false
    endfunction
    
    private function Init takes nothing returns nothing
        call TriggerRegisterDayBecomesNight(onTimeChange)
        call TriggerRegisterNightBecomesDay(onTimeChange)
        call TriggerAddCondition(onTimeChange, Condition( function onTimeChangeEx))
        set AddAndRemoveLifeLeech = Condition( function FAddAndRemoveLifeLeech)
        call onTimeChangeEx()
    endfunction
endscope
 

quraji

zap
Reaction score
144
what don't you understand about "Just booleans can't pull this off."? (rhetorical question, don't answer that)

Apparently, the "booleans can't pull this off" part.
JASS:

scope MyDaytimeSpell
...
private function GetDamageOrWhatever takes nothing returns real
    if (IsDaytime()) then
        return 100.
    endif
    return 50.
endfunction
...
endscope


I DID NOT MAKE THIS SYSTEM TO ARGUE ABOUT WHY IT'S NECESSARY...

But you did post it, so you get our opinions/comments/criticisms.

I Honestly don't even remember where all the bugs are without me advancing it as far as I did.
But the bugs ARE there.

I believe you..

I don't want someone else thinking he's so smart coming in here telling me why the system isn't necessary...

I'm still not clear what the heck it is or what it's supposed to do.
Clean it up, follow the advice of what people have been saying. If you need help ask for it.
 

SanKakU

Member
Reaction score
21
Well, an important attribute of systems/librarys is, that the user can actually READ the code and understand it for himself. It is rubbish to tell the users to change function names, because this requires them to understand the code before the modification, which is hardly possible with "... function A ..." etc.

Furthermore would you explain more in detail these aspects:
  • WHAT does this system do?
  • HOW can I access these functions?*
*I hope the user doesn't have to write code inside your library, because this is nonprofessional, unhandy and not our standard. Keyword = Interface.

Maybe you should remember that this section is for finished systems only. If you want to improve your system post it in "JASS Help".

And for god's sake, learn to FORMAT your code...

Did you want to do sth. like this?

JASS:
library DayAndNight initializer Init
    globals
        private constant real DUSK = 18.
        private constant real DAWN =  6.
    endglobals    
       
    globals
        private Event   DayToNight      = 0
        private Event   NightToDay      = 0
        private trigger OnDayToNight    = CreateTrigger()
        private trigger OnNightToDay    = CreateTrigger()
    endglobals
    
    function IsDay takes nothing returns boolean
        local real time = GetFloatGameState(GAME_STATE_TIME_OF_DAY)
        return time &gt;= DAWN and time &lt;= DUSK
    endfunction
    
    function IsNight takes nothing returns boolean
        local real time = GetFloatGameState(GAME_STATE_TIME_OF_DAY)
        return time &lt; DAWN or time &gt; DUSK
    endfunction
    
    function TriggerRegisterDayBecomesNight takes trigger t returns EventReg
        return DayToNight.register(t)
    endfunction 
    
    function TriggerRegisterNightBecomesDay takes trigger t returns EventReg
        return NightToDay.register(t)
    endfunction 
    
    private function OnDayToNightEx takes nothing returns boolean
        call DayToNight.fire()
        return false
    endfunction
    
    private function OnNightToDayEx takes nothing returns boolean
        call NightToDay.fire()
        return false
    endfunction
    
    private function Init takes nothing returns nothing
        set DayToNight = Event.create()
        set NightToDay = Event.create()
        
        call TriggerRegisterGameStateEvent(OnDayToNight, GAME_STATE_TIME_OF_DAY, EQUAL, DUSK)
        call TriggerRegisterGameStateEvent(OnNightToDay, GAME_STATE_TIME_OF_DAY, EQUAL, DAWN)
        call TriggerAddCondition(OnDayToNight, Condition( function OnDayToNightEx))
        call TriggerAddCondition(OnNightToDay, Condition( function OnNightToDayEx))
    endfunction
endlibrary


JASS:
scope LifeLeechInNightSpell initializer Init
    globals
        private             group       GROUP           = CreateGroup()
    
        private constant    integer     ID_UNIT         = &#039;abcd&#039;
        private constant    integer     ID_SPELL        = &#039;efgh&#039;
        private             trigger     onTimeChange    = CreateTrigger()
        
        private             boolean     Day
        private             boolexpr    AddAndRemoveLifeLeech
    endglobals
    
    private function FAddAndRemoveLifeLeech takes nothing returns boolean
        local unit u = GetFilterUnit()
        if GetUnitTypeId(u) != ID_UNIT then
            return false
        endif
        
        if Day then
            call UnitRemoveAbility(u,ID_SPELL)
        else
            call UnitAddAbility(u,ID_SPELL)
        endif        
        return false
    endfunction

    private function onTimeChangeEx takes nothing returns boolean
        set Day = IsDay()
        call GroupEnumUnitsInRect(GROUP,bj_mapInitialPlayableArea,AddAndRemoveLifeLeech)
        return false
    endfunction
    
    private function Init takes nothing returns nothing
        call TriggerRegisterDayBecomesNight(onTimeChange)
        call TriggerRegisterNightBecomesDay(onTimeChange)
        call TriggerAddCondition(onTimeChange, Condition( function onTimeChangeEx))
        set AddAndRemoveLifeLeech = Condition( function FAddAndRemoveLifeLeech)
        call onTimeChangeEx()
    endfunction
endscope

well i don't entirely understand your code but it might have something to it.

as for the others that still are wondering about where the errors come about...i don't remember the details but i think i just remembered that a big problem is with event registration.

if i remember right, i couldn't figure out how to get the event registering to fire properly without doing what i did. i'm not sure if what Executor proposed would fix it or not, but i'll definitely check it out...

as far as i can figure, if i'm remembering this right...
you can't get an event registered for time of day becomes greater than such and such and less than such and such. you can boolean it to figure out what time it is, but that's all you can do. you still need the proper event registration to begin with.

if you cast a spell, it's an easy matter to check the time right? but what if you need to replace the entire spell with another spell? the event isn't going to be when you cast the spell, it's going to be when the time goes from day to night or vice versa. that's the key, and that's why the system is important. it sounds like Executor might understand this, I'm not sure(it kinda looks like he just posted a lot of functions that call eachother, but what do i know...he didn't add any comments)...i copied his code into a trigger and i'll check it out later.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top