• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[Trigger] Date & Time System

Status
Not open for further replies.
Level 7
Joined
Aug 19, 2007
Messages
21
[Solved] Date & Time System

I fixed the issue, some trigger was corrupt and broke every trigger made after it.


Well I have run into a little snag with my triggers not firing, only these three tho. They are enabled and Initially on. The chat message events were added after they wouldn't fire in an attempt to force a fire.

  • NewDay
    • Events
      • Player - Player 1 (Red) types a chat message containing -date as An exact match
      • Time - Elapsed game time is 5.00 seconds
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Day Equal to 8
        • Then - Actions
          • Set Day = 1
          • Set Week = (Week + 1)
        • Else - Actions
          • Set Day = (Day + 1)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Week Equal to 5
        • Then - Actions
          • Set Week = 1
          • Set Month = (Month + 1)
        • Else - Actions
          • Set Week = (Week + 1)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Month Equal to 13
        • Then - Actions
          • Set Month = 1
          • Set Year = (Year + 1)
        • Else - Actions
          • Set Month = 1
      • Wait 2.00 seconds
      • Game - Display to (All players) the text: ((|cff7777aaToday is + DayName[Day]) + (, + (MonthName[Month] + ( + ((String(Day)) + ( + ((String(Year)) + |r)))))))
  • Time
    • Events
      • Player - Player 1 (Red) types a chat message containing -time as An exact match
      • Time - Every 5.00 seconds of game time
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Hour Equal to 25
        • Then - Actions
          • Set Hour = 1
          • Trigger - Run NewDay <gen> (ignoring conditions)
        • Else - Actions
          • Set Hour = (Hour + 1)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Hour Greater than 12
        • Then - Actions
          • Game - Display to (All players) the text: (|cff7777aaIts + ((String((Hour - 12))) + (:00 + PM|r)))
        • Else - Actions
          • Game - Display to (All players) the text: (|cff7777aaIts + ((String(Hour)) + (:00 + AM|r)))
 
Last edited:
Level 18
Joined
Jan 21, 2006
Messages
2,552
There is a feature to convert in the regular World Editor. Go "Edit > Convert to Custom Script". Then paste what it gives you there. Do it with a copy of your trigger, not the actual trigger.
 
Level 7
Joined
Aug 19, 2007
Messages
21
JASS:
function Trig_Time_Copy_Func003C takes nothing returns boolean
    if ( not ( udg_Hour == 25 ) ) then
        return false
    endif
    return true
endfunction

function Trig_Time_Copy_Func004C takes nothing returns boolean
    if ( not ( udg_Hour > 12 ) ) then
        return false
    endif
    return true
endfunction

function Trig_Time_Copy_Actions takes nothing returns nothing
    call DisplayTextToForce( GetPlayersAll(), "TRIGSTR_115" )
    if ( Trig_Time_Copy_Func003C() ) then
        set udg_Hour = 1
        call TriggerExecute( gg_trg_NewDay )
    else
        set udg_Hour = ( udg_Hour + 1 )
    endif
    if ( Trig_Time_Copy_Func004C() ) then
        call DisplayTextToForce( GetPlayersAll(), ( "|cff7777aaIts " + ( I2S(( udg_Hour - 12 )) + ( ":00 " + "PM|r" ) ) ) )
    else
        call DisplayTextToForce( GetPlayersAll(), ( "|cff7777aaIts " + ( I2S(udg_Hour) + ( ":00 " + "AM|r" ) ) ) )
    endif
    call DisplayTextToForce( GetPlayersAll(), "TRIGSTR_116" )
endfunction

//===========================================================================
function InitTrig_Time_Copy takes nothing returns nothing
    set gg_trg_Time_Copy = CreateTrigger(  )
    call TriggerRegisterTimerExpireEventBJ( gg_trg_Time_Copy, udg_MinuteTimer )
    call TriggerAddAction( gg_trg_Time_Copy, function Trig_Time_Copy_Actions )
endfunction


JASS:
function Trig_NewDay_Copy_Func002C takes nothing returns boolean
    if ( not ( udg_Day == 8 ) ) then
        return false
    endif
    return true
endfunction

function Trig_NewDay_Copy_Func003C takes nothing returns boolean
    if ( not ( udg_Week == 5 ) ) then
        return false
    endif
    return true
endfunction

function Trig_NewDay_Copy_Func004C takes nothing returns boolean
    if ( not ( udg_Month == 13 ) ) then
        return false
    endif
    return true
endfunction

function Trig_NewDay_Copy_Actions takes nothing returns nothing
    call DisplayTextToForce( GetPlayersAll(), "TRIGSTR_117" )
    if ( Trig_NewDay_Copy_Func002C() ) then
        call DisplayTextToForce( GetPlayersAll(), "TRIGSTR_119" )
        set udg_Day = 1
        set udg_Week = ( udg_Week + 1 )
    else
        call DisplayTextToForce( GetPlayersAll(), "TRIGSTR_118" )
        set udg_Day = ( udg_Day + 1 )
    endif
    if ( Trig_NewDay_Copy_Func003C() ) then
        call DisplayTextToForce( GetPlayersAll(), "TRIGSTR_121" )
        set udg_Week = 1
        set udg_Month = ( udg_Month + 1 )
    else
        call DisplayTextToForce( GetPlayersAll(), "TRIGSTR_120" )
        set udg_Week = ( udg_Week + 1 )
    endif
    if ( Trig_NewDay_Copy_Func004C() ) then
        call DisplayTextToForce( GetPlayersAll(), "TRIGSTR_123" )
        set udg_Month = 1
        set udg_Year = ( udg_Year + 1 )
    else
        call DisplayTextToForce( GetPlayersAll(), "TRIGSTR_122" )
        set udg_Month = 1
    endif
    call DisplayTextToForce( GetPlayersAll(), ( ( "|cff7777aaToday is " + udg_DayName[udg_Day] ) + ( ", " + ( udg_MonthName[udg_Month] + ( " " + ( I2S(udg_Day) + ( " " + ( I2S(udg_Year) + "|r" ) ) ) ) ) ) ) )
    call DisplayTextToForce( GetPlayersAll(), "TRIGSTR_124" )
endfunction

//===========================================================================
function InitTrig_NewDay_Copy takes nothing returns nothing
    set gg_trg_NewDay_Copy = CreateTrigger(  )
    call TriggerAddAction( gg_trg_NewDay_Copy, function Trig_NewDay_Copy_Actions )
endfunction
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
I swear there were 3 functions before. The first one being some sort of variable initialization function.

Try replacing your initializer functions ("InitTrig_TrigName") with these ones:

JASS:
//===========================================================================
function InitTrig_NewDay_Copy takes nothing returns nothing
    call TimerStart(CreateTimer(), 0, false, function Trig_NewDay_Copy_Actions )

endfunction

JASS:
//===========================================================================
function InitTrig_Time_Copy takes nothing returns nothing
    call TimerStart(CreateTimer(), 5, true, function Trig_Time_Copy_Actions )

endfunction
 
JASS:
/*
    CustomDate 
        by Anachron
        
    local CustomDate cd = CustomDate.create()
    
    call cd.setTime(10, 0, 0) // Sets time to 10 am.
    call cd.setDate(2010, 2, 2) // Sets the date to 2nd of January 2010
    
    // Prints for example: 2nd of January 2010 - 10:00:00
    call BJDebugMsg(cd.getDate("D") + " of " + cd.getDate("M y") + " - " + cd.getTime("H:M:S"))
    
    call cd.addDays(2) // Will add 2 days to the current date
    call cd.subMonths(2) // Will remove 2 months from the current date
    
    // This will print: 4th of October 2009 - 10:00:00
    call BJDebugMsg(cd.getDate("D") + " of " + cd.getDate("M y") + " - " + cd.getTime("H:M:S"))
*/
library CustomDate initializer init
    
    globals
        private array   monthDays[12]
        private array   monthNames[12]
        private array   dayNames[12]
        private string  curFormat = null
    endglobals
    
    struct CustomDate
        private integer second  = 0
        private integer minute  = 0
        private integer hour    = 0
        private integer day     = 0
        private integer month   = 0
        private integer year    = 0
        
        method operator s takes nothing returns integer
            return .second
        endfunction
        
        method operator m takes nothing returns integer
            return .minute
        endfunction
        
        method operator h takes nothing returns integer
            return .hour
        endfunction
        
        method operator D takes nothing returns integer
            return .day
        endfunction
        
        method operator M takes nothing returns integer
            return .month
        endfunction
        
        method operator Y takes nothing returns integer
            return .year
        endfunction
        
        public function setDate takes integer y, integer m, integer d returns nothing
            set .year = y
            set .month = m
            set .day = d
        endfunction
        
        public function setTime takes integer h, integer m, integer s returns nothing
            set .hour = h
            set .minute = m
            set .second = s
        endfunction
    
        private function subDay takes nothing returns nothing
            set .day = .day -1
            if .day < 0 then
                set .month = .month -1
                if .month < 0 then
                    set .month = 12
                    set .year = .year -1
                endif
                set .day = monthDays[.month] -1
            endif
        endfunction
        
        private function addDay takes nothing returns nothing
            set .day = .day +1
            if .day >= monthDays[.month] then
                set .day = 0
                set .month = .month +1
                if .month => 12 then
                    set .month = 0
                    set .year = .year +1
                endif
            endif
        endfunction
        
        public function addDays takes integer i returns nothing
            loop
                exitwhen i == 0
                
                call .addDay()
                set i = i -1
            endloop
        endfunction
        
        public function subDays takes integer i returns nothing
            loop
                exitwhen i == 0
                
                call .subDay()
                set i = i -1
            endloop
        endfunction
        
        public function addWeeks takes integer i returns nothing
            loop
                exitwhen i == 0
                
                call .addDays(7)
                set i = i -1
            endloop
        endfunction
        
        public function subWeeks takes integer i returns nothing
            loop
                exitwhen i == 0
                
                call .subDays(7)
                set i = i -1
            endloop
        endfunction
        
        public function addMonths takes integer i returns nothing
            loop
                exitwhen i == 0
                
                call .addDays(monthDays[month])
                set i = i -1
            endloop
        endfunction
        
        public function subMonths takes integer i returns nothing
            loop
                exitwhen i == 0
                
                call .subDays(monthDays[.month])
                set i = i -1
            endloop
        endfunction
        
        public function addYears takes integer i returns nothing
            set year = year +i
        endfunction
        
        public function subYears takes integer i returns nothing
            set year = year -i
        endfunction
        
        public function getDate takes string format returns string
            local integer i = 0
            local integer stop = StringLength(format)
            local string s = null
            
            set curFormat = null
            
            loop
                exitwhen i >= stop
                set s = SubString(format, i, i +1)
                
                if s == "d" then
                    if .day < 9 then
                        set curFormat = curFormat + "0"
                    endif
                    set curFormat = curFormat + I2S(.day)
                elseif s == "D" then
                    set curFormat = curFormat + dayNames[.day] + I2S(.day)
                elseif s == "m" then
                    if .month < 9 then
                        set curFormat = curFormat + "0"
                    endif
                    set curFormat = curFormat + I2S(.month)
                elseif s == "M" then
                    set curFormat = curFormat + SubString(monthNames[.day], 0, 2)
                elseif s == "N" then
                    set curFormat = curFormat + monthNames[.day]
                elseif s == "y" then
                    set curFormat = curFormat + I2S(.year)
                else
                    set curFormat = curFormat + s
                endif
                
                set i = i +1
            endloop
            
            set s = null
            return curFormat
        endfunction
        
        public function getTime takes string format returns string
            local integer i = 0
            local integer stop = StringLength(format)
            local string s = null
            
            set curFormat = null
            
            loop
                exitwhen i >= stop
                set s = SubString(format, i, i +1)
                
                if s == "s" then
                    if .second < 9 then
                        set curFormat = curFormat + "0"
                    endif
                    set curFormat = curFormat + I2S(.second)
                elseif s == "m" then
                    if .minute < 9 then
                        set curFormat = curFormat + "0"
                    endif
                    set curFormat = curFormat + I2S(.minute)
                elseif s == "h" then
                    if .hour < 9 then
                        set curFormat = curFormat + "0"
                    endif
                    set curFormat = curFormat + I2S(.hour)
                else
                    set curFormat = curFormat + s
                endif
                
                set i = i +1
            endloop
            
            set s = null
            return curFormat
        endfunction
    endstruct
    
    private function init takes nothing returns nothing
        local integer i = 0
        
        set monthDays[0] = 31
        set monthDays[1] = 28
        set monthDays[2] = 31
        set monthDays[3] = 30
        set monthDays[4] = 31
        set monthDays[5] = 30
        set monthDays[6] = 31
        set monthDays[7] = 31
        set monthDays[8] = 30
        set monthDays[9] = 31
        set monthDays[10] = 30
        set monthDays[11] = 31
        
        set monthNames[0] = "January"
        set monthNames[1] = "February"
        set monthNames[2] = "March"
        set monthNames[3] = "April"
        set monthNames[4] = "May"
        set monthNames[5] = "June"
        set monthNames[6] = "July"
        set monthNames[7] = "August"
        set monthNames[8] = "September"
        set monthNames[9] = "October"
        set monthNames[10] = "November"
        set monthNames[11] = "December"
        
        loop
            exitwhen i >= 31
            
            if i == 0 then
                set dayNames[i] = "st"
            elseif i == 1 then
                set dayNames[i] = "nd"
            elseif i == 2 then
                set dayNames[i] = "rd"
            else
                set dayNames[i] = "th"
            endif
        endloop
    endfunction
endlibrary

its in vJass and I wrote it out of my head. Please report if it gives compile errors or doesn't work correctly.
 
Last edited:
Status
Not open for further replies.
Top