day and night detection not working

waaaks!

Zinctified
Reaction score
255
Hello

I'm creating a trigger that creates units on a given coordinates when it is night, the if else block does not work, looks like the condition is not right for detecting night or day.

Full Trigger (only nocturnalAct function not working)
JASS:
//! zinc
library Creeps requires GroupUtils, BoolexprUtils{
    string move = "Abilities\\Spells\\Human\\MassTeleport\\MassTeleportTarget.mdl";
    string burst = "Objects\\Spawnmodels\\Orc\\OrcSmallDeathExplode\\OrcSmallDeathExplode.mdl";
    string mark = "Abilities\\Spells\\Demon\\DarkPortal\\DarkPortalTarget.mdl";
    boolean rdy = true;
    integer creeper[];
    integer deadarmy[];
    integer demondays[];
    integer nocturnal[];
    unit tower[];
    function startCreeps(){
        creeper[0] = 'u001'; //Boogieman
        creeper[1] = 'u002'; //Arachnia
        creeper[2] = 'u003'; //Doom Beetle
        
        deadarmy[0] = 'u004'; //Skeleton Warrior
        deadarmy[1] = 'u005'; //Skeletal Mage
        deadarmy[2] = 'n004'; //Skeleton Archer
        
        demondays[0] = 'n005'; //Fel Grunt
        demondays[1] = 'n006'; //Fel Warlock
        demondays[2] = 'n007'; //Fel Beast
        
        nocturnal[0] = 'n008'; //Voidwalker
        nocturnal[1] = 'n009'; //Ghost
        nocturnal[2] = 'n00A'; //Giant Wolf
        
        //-----
        tower[0] = gg_unit_h000_0000;
        tower[1] = gg_unit_h000_0013;
        tower[2] = gg_unit_h000_0014;
        tower[3] = gg_unit_h000_0015;
        tower[4] = gg_unit_h000_0016;
        tower[5] = gg_unit_h000_0017;
        tower[6] = gg_unit_h000_0018;
        tower[7] = gg_unit_h000_0019;
        tower[8] = gg_unit_h000_0020;
    }
    
    function creeperAct(){
        unit u;
        integer r = GetRandomInt(0,8);
        real x = GetUnitX(tower[r]);
        real y = GetUnitY(tower[r]);
        PingMinimap(x,y,3.0);
        u = CreateUnit(Player(12),creeper[0],x,y,GetRandomReal(0,360));
        DestroyEffect(AddSpecialEffectTarget(move,u,"origin"));
        UnitApplyTimedLife(u,'BTLF',180.0);
        if(IsPlayerInForce(GetLocalPlayer(),bj_FORCE_ALL_PLAYERS))
            UnitShareVision(u,GetLocalPlayer(),true);
        u = CreateUnit(Player(12),creeper[1],x,y,GetRandomReal(0,360));
        DestroyEffect(AddSpecialEffectTarget(move,u,"origin"));
        UnitApplyTimedLife(u,'BTLF',180.0);
        if(IsPlayerInForce(GetLocalPlayer(),bj_FORCE_ALL_PLAYERS))
            UnitShareVision(u,GetLocalPlayer(),true);
        u = CreateUnit(Player(12),creeper[2],x,y,GetRandomReal(0,360));
        DestroyEffect(AddSpecialEffectTarget(move,u,"origin"));
        UnitApplyTimedLife(u,'BTLF',180.0);
        if(IsPlayerInForce(GetLocalPlayer(),bj_FORCE_ALL_PLAYERS))
            UnitShareVision(u,GetLocalPlayer(),true);
        u = null;
    }
    
    function deadarmyAct(){
        group g = NewGroup();
        unit gu;
        unit u;
        real x;
        real y;
        boolean b = false;
        GroupEnumUnitsInRange(g,0,0,999999,BOOLEXPR_TRUE);
        for(gu = FirstOfGroup(g) ; gu != null ; gu = FirstOfGroup(g)){
            if(GetWidgetLife(gu) <= 0.405 && !IsUnitType(gu,UNIT_TYPE_STRUCTURE) && !IsUnitType(gu,UNIT_TYPE_HERO)){
                x = GetUnitX(gu);
                y = GetUnitY(gu);
                b = true;
            }
            GroupRemoveUnit(g,gu);
        }
        ReleaseGroup(g);
        g = null;
        gu = null;
        if(b){
            b = false;
            PingMinimap(x,y,3.0);
            u = CreateUnit(Player(12),deadarmy[0],x,y,GetRandomReal(0,360));
            DestroyEffect(AddSpecialEffectTarget(burst,u,"origin"));
            UnitApplyTimedLife(u,'BTLF',180.0);
            if(IsPlayerInForce(GetLocalPlayer(),bj_FORCE_ALL_PLAYERS))
                UnitShareVision(u,GetLocalPlayer(),true);
            u = CreateUnit(Player(12),deadarmy[1],x,y,GetRandomReal(0,360));
            DestroyEffect(AddSpecialEffectTarget(burst,u,"origin"));
            UnitApplyTimedLife(u,'BTLF',180.0);
            if(IsPlayerInForce(GetLocalPlayer(),bj_FORCE_ALL_PLAYERS))
                UnitShareVision(u,GetLocalPlayer(),true);
            u = CreateUnit(Player(12),deadarmy[2],x,y,GetRandomReal(0,360));
            DestroyEffect(AddSpecialEffectTarget(burst,u,"origin"));
            UnitApplyTimedLife(u,'BTLF',180.0);
            if(IsPlayerInForce(GetLocalPlayer(),bj_FORCE_ALL_PLAYERS))
                UnitShareVision(u,GetLocalPlayer(),true);
        }
        u = null;
    }
    
    function demondaysAct(){
        group g = NewGroup();
        unit gu;
        unit u;
        real x;
        real y;
        boolean b = false;
        GroupEnumUnitsInRange(g,0,0,999999,BOOLEXPR_TRUE);
        for(gu = FirstOfGroup(g) ; gu != null ; gu = FirstOfGroup(g)){
            if(GetWidgetLife(gu) <= 0.405 && !IsUnitType(gu,UNIT_TYPE_STRUCTURE) && IsUnitType(gu,UNIT_TYPE_HERO)){
                x = GetUnitX(gu);
                y = GetUnitY(gu);
                b = true;
            }
            GroupRemoveUnit(g,gu);
        }
        ReleaseGroup(g);
        g = null;
        gu = null;
        if(b){
            b = false;
            PingMinimap(x,y,3.0);
            u = CreateUnit(Player(12),demondays[0],x,y,GetRandomReal(0,360));
            DestroyEffect(AddSpecialEffectTarget(mark,u,"origin"));
            UnitApplyTimedLife(u,'BTLF',180.0);
            if(IsPlayerInForce(GetLocalPlayer(),bj_FORCE_ALL_PLAYERS))
                UnitShareVision(u,GetLocalPlayer(),true);
            u = CreateUnit(Player(12),demondays[1],x,y,GetRandomReal(0,360));
            DestroyEffect(AddSpecialEffectTarget(mark,u,"origin"));
            UnitApplyTimedLife(u,'BTLF',180.0);
            if(IsPlayerInForce(GetLocalPlayer(),bj_FORCE_ALL_PLAYERS))
                UnitShareVision(u,GetLocalPlayer(),true);
            u = CreateUnit(Player(12),demondays[2],x,y,GetRandomReal(0,360));
            DestroyEffect(AddSpecialEffectTarget(mark,u,"origin"));
            UnitApplyTimedLife(u,'BTLF',180.0);
            if(IsPlayerInForce(GetLocalPlayer(),bj_FORCE_ALL_PLAYERS))
                UnitShareVision(u,GetLocalPlayer(),true);
        }
        u = null;
    }
    
    function nocturnalAct(){
        unit u;
        real x[];
        real y[];
        integer r = GetRandomInt(0,1);
        x[0] = GetRectCenterX(gg_rct_centerTop);
        y[0] = GetRectCenterY(gg_rct_centerTop);
        x[1] = GetRectCenterX(gg_rct_centerBottom);
        y[1] = GetRectCenterY(gg_rct_centerBottom);
        if(GetFloatGameState(GAME_STATE_TIME_OF_DAY) >= 18.0 && GetFloatGameState(GAME_STATE_TIME_OF_DAY) < 6.00 && rdy){
            BJDebugMsg("create nocturnal");
            rdy = false;
            PingMinimap(x[r],y[r],3.0);
            u = CreateUnit(Player(12),nocturnal[0],x[r],y[r],GetRandomReal(0,360));
            UnitApplyTimedLife(u,'BTLF',180.0);
            if(IsPlayerInForce(GetLocalPlayer(),bj_FORCE_ALL_PLAYERS))
                UnitShareVision(u,GetLocalPlayer(),true);
            u = CreateUnit(Player(12),nocturnal[1],x[r],y[r],GetRandomReal(0,360));
            UnitApplyTimedLife(u,'BTLF',180.0);
            if(IsPlayerInForce(GetLocalPlayer(),bj_FORCE_ALL_PLAYERS))
                UnitShareVision(u,GetLocalPlayer(),true);
            u = CreateUnit(Player(12),nocturnal[2],x[r],y[r],GetRandomReal(0,360));
            UnitApplyTimedLife(u,'BTLF',180.0);
            if(IsPlayerInForce(GetLocalPlayer(),bj_FORCE_ALL_PLAYERS))
                UnitShareVision(u,GetLocalPlayer(),true);
        }else if(GetFloatGameState(GAME_STATE_TIME_OF_DAY) < 18.0 && GetFloatGameState(GAME_STATE_TIME_OF_DAY) >= 6.00){
            rdy = true;
        }
        u = null;        
    }

    function onInit(){
        trigger t = CreateTrigger();
        TriggerRegisterTimerEventPeriodic(t,GetRandomReal(180,200));
        TriggerAddAction(t,function creeperAct);
        
        t = CreateTrigger();
        TriggerRegisterTimerEventPeriodic(t,GetRandomReal(200,220));
        TriggerAddAction(t,function deadarmyAct);
        
        t = CreateTrigger();
        TriggerRegisterTimerEventPeriodic(t,GetRandomReal(220,240));
        TriggerAddAction(t,function demondaysAct);
        
        t = CreateTrigger();
        TriggerRegisterTimerEventPeriodic(t,1.0);
        TriggerAddAction(t,function nocturnalAct);
        
        startCreeps();
    }
}
//! endzinc


Edited full version to ease viewers
JASS:
//! zinc
library Creeps {
    boolean rdy = true;
    integer nocturnal[];
    function startCreeps(){
        nocturnal[0] = 'n008'; //Voidwalker
        nocturnal[1] = 'n009'; //Ghost
        nocturnal[2] = 'n00A'; //Giant Wolf
    }
    
    function nocturnalAct(){
        unit u;
        real x[];
        real y[];
        integer r = GetRandomInt(0,1);
        x[0] = GetRectCenterX(gg_rct_centerTop);
        y[0] = GetRectCenterY(gg_rct_centerTop);
        x[1] = GetRectCenterX(gg_rct_centerBottom);
        y[1] = GetRectCenterY(gg_rct_centerBottom);
        if(GetFloatGameState(GAME_STATE_TIME_OF_DAY) >= 18.0 && GetFloatGameState(GAME_STATE_TIME_OF_DAY) < 6.00 && rdy){
            BJDebugMsg("create nocturnal");
            rdy = false;
            PingMinimap(x[r],y[r],3.0);
            u = CreateUnit(Player(12),nocturnal[0],x[r],y[r],GetRandomReal(0,360));
            UnitApplyTimedLife(u,'BTLF',180.0);
            if(IsPlayerInForce(GetLocalPlayer(),bj_FORCE_ALL_PLAYERS))
                UnitShareVision(u,GetLocalPlayer(),true);
            u = CreateUnit(Player(12),nocturnal[1],x[r],y[r],GetRandomReal(0,360));
            UnitApplyTimedLife(u,'BTLF',180.0);
            if(IsPlayerInForce(GetLocalPlayer(),bj_FORCE_ALL_PLAYERS))
                UnitShareVision(u,GetLocalPlayer(),true);
            u = CreateUnit(Player(12),nocturnal[2],x[r],y[r],GetRandomReal(0,360));
            UnitApplyTimedLife(u,'BTLF',180.0);
            if(IsPlayerInForce(GetLocalPlayer(),bj_FORCE_ALL_PLAYERS))
                UnitShareVision(u,GetLocalPlayer(),true);
        }else if(GetFloatGameState(GAME_STATE_TIME_OF_DAY) < 18.0 && GetFloatGameState(GAME_STATE_TIME_OF_DAY) >= 6.00){
            rdy = true;
        }
        u = null;        
    }

    function onInit(){
        trigger t = CreateTrigger();
        TriggerRegisterTimerEventPeriodic(t,1.0);
        TriggerAddAction(t,function nocturnalAct);
        
        startCreeps();
    }
}
//! endzinc


and for those who can't read zinc codes
JASS:
scope nocturnals initializer onInit
    globals
        private boolean rdy = true
        private integer array nocturnal
    endglobals
    
    private function startCreeps takes nothing returns nothing
        set = nocturnal[0] = 'n008' //Voidwalker
        set = nocturnal[1] = 'n009' //Ghost
        set = nocturnal[2] = 'n00A' //Giant Wolf
    endfunction
    
    private function nocturnalAct takes nothing returns nothing
        local unit u
        local real array x
        local real array y
        local integer r = GetRandomInt(0,1)
        set x[0] = GetRectCenterX(gg_rct_centerTop)
        set y[0] = GetRectCenterY(gg_rct_centerTop)
        set x[1] = GetRectCenterX(gg_rct_centerBottom)
        set y[1] = GetRectCenterY(gg_rct_centerBottom)
        if(GetFloatGameState(GAME_STATE_TIME_OF_DAY) >= 18.0 and GetFloatGameState(GAME_STATE_TIME_OF_DAY) < 6.00 and rdy) then
            call BJDebugMsg("create nocturnal")
            set rdy = false
            call PingMinimap(x[r],y[r],3.0)
            set u = CreateUnit(Player(12),nocturnal[0],x[r],y[r],GetRandomReal(0,360))
            call UnitApplyTimedLife(u,'BTLF',180.0)
            if(IsPlayerInForce(GetLocalPlayer(),bj_FORCE_ALL_PLAYERS))then
                call UnitShareVision(u,GetLocalPlayer(),true)
            endif
            set u = CreateUnit(Player(12),nocturnal[1],x[r],y[r],GetRandomReal(0,360))
            call UnitApplyTimedLife(u,'BTLF',180.0)
            if(IsPlayerInForce(GetLocalPlayer(),bj_FORCE_ALL_PLAYERS))then
                call UnitShareVision(u,GetLocalPlayer(),true)
            endif
            set u = CreateUnit(Player(12),nocturnal[2],x[r],y[r],GetRandomReal(0,360))
            call UnitApplyTimedLife(u,'BTLF',180.0)
            if(IsPlayerInForce(GetLocalPlayer(),bj_FORCE_ALL_PLAYERS))then
                call UnitShareVision(u,GetLocalPlayer(),true)
            endif
        elseif(GetFloatGameState(GAME_STATE_TIME_OF_DAY) < 18.0 and GetFloatGameState(GAME_STATE_TIME_OF_DAY) >= 6.00)then
            set rdy = true
        endif
        set u = null
    endfunction

    private function onInit takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterTimerEventPeriodic(t,1.0)
        call TriggerAddAction(t,function nocturnalAct)
    
        call startCreeps()
    endfunction
endscope


I really thought that there's something wrong with my day and night condition.
thanks
 
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