System Multiboard Timers

Reaction score
456
_ __ ___ ____ _____ ______ _____ ____ ___ __ _
Multiboard Timers System v2.0
¯ ¯¯ ¯¯¯ ¯¯¯¯ ¯¯¯¯¯ ¯¯¯¯¯¯ ¯¯¯¯¯ ¯¯¯¯ ¯¯¯ ¯¯ ¯

by Überplayer


Just a 'simple' system, which adds different kind of timers to a multiboard.

Instruction Trigger:
JASS:
v.2.0

Made by: Überplayer

Requirements:
¯¯¯¯¯¯¯¯¯¯¯¯¯
-NewGen editor (required)

Importing:
¯¯¯¯¯¯¯¯¯¯
Just copy the "Multiboard Timers" trigger to your map.

How to use?:
¯¯¯¯¯¯¯¯¯¯¯¯
//MAIN FUNCTION

mb             = The multiboard where the timer is added.
column         = The column of the multiboard where the timer is added.
row            = The row of the multiboard where the timer is added.
color          = The color string of the timer text. Eg. "FF00AEEF".
fromMinutes    = The minutes where the timer starts to run
fromSeconds    = The seconds where the timer starts to run.
canExpire      = If this is true, the timer uses the three arguments down below.
expireMinutes  = The minutes where the timer expires.
expireSeconds  = The seconds where the timer expires.
runAfterExpire = This trigger is ran when the timer expires.
_____________________________
function MultiboardAddTimer takes multiboard mb, integer column, integer row, string color, integer fromMinutes, integer fromSeconds, boolean canExpire, integer expireMinutes, integer expireSeconds, trigger runAfterExpire returns nothing 
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

//MISC FUNCTIONS

mb     = The multiboard which's timer is used in the action.
column = The column of the timer.
row    = The row of the timer.
_____________________________
function MultiboardPauseTimer takes multiboard mb, integer column, integer row returns nothing
function MultiboardResumeTimer takes multiboard mb, integer column, integer row returns nothing
function MultiboardResetTimer takes multiboard mb, integer column, integer row returns nothing
function MultiboardRemoveTimer takes multiboard mb, integer column, integer row returns nothing
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯


System Trigger:
JASS:
library MultiboardTimers

private struct MTdata
    multiboard mb
    integer column
    integer row
    string color
    integer fromMinutes
    integer fromSeconds
    boolean canExpire
    integer expireMinutes
    integer expireSeconds
    trigger runAfterExpire
    
    integer currentMinutes
    integer currentSeconds
    multiboarditem mbi
    
    boolean isPaused = false
    boolean wantDestroy = false
    
    method runTimer takes nothing returns nothing
        if (.isPaused == false) then
            if (.canExpire == false) then
                set .currentSeconds = .currentSeconds + 1
                if (.currentSeconds > 59) then
                    set .currentMinutes = .currentMinutes + 1
                    set .currentSeconds = 0
                endif
            else
                if ((.fromMinutes + .fromSeconds) > (.expireMinutes + .expireSeconds)) then
                    set .currentSeconds = .currentSeconds - 1
                    if (.currentSeconds < .expireSeconds) and (.currentMinutes == .expireMinutes) then
                        set .currentSeconds = .expireSeconds
                        set .wantDestroy = true
                        if (.runAfterExpire != null) then
                            call TriggerExecute(.runAfterExpire)
                        endif
                    else
                        if (.currentSeconds < 0) then
                            set .currentSeconds = 59
                            set .currentMinutes = .currentMinutes - 1
                        endif
                    endif
                else
                    set .currentSeconds = .currentSeconds + 1
                    if (.currentSeconds > .expireSeconds) and (.currentMinutes == .expireMinutes) then
                        set .currentSeconds = .expireSeconds
                        set .wantDestroy = true
                        if (.runAfterExpire != null) then
                            call TriggerExecute(.runAfterExpire)
                        endif
                    else
                        if (.currentSeconds > 60) then
                            set .currentSeconds = 0
                            set .currentMinutes = .currentMinutes + 1
                        endif
                    endif
                endif
            endif
            if (.currentSeconds < 10) then
                call MultiboardSetItemValue(.mbi, "|c"+.color+I2S(.currentMinutes)+":0"+I2S(.currentSeconds))
            else
                call MultiboardSetItemValue(.mbi, "|c"+.color+I2S(.currentMinutes)+":"+I2S(.currentSeconds))
            endif
        endif   
    endmethod
    
    static method create takes multiboard mb, integer column, integer row, string color, integer fromMinutes, integer fromSeconds, boolean canExpire, integer expireMinutes, integer expireSeconds, trigger runAfterExpire returns MTdata
        local MTdata dat = MTdata.allocate()
        
        set dat.mb = mb
        set dat.column = column
        set dat.row = row
        set dat.color = color
        set dat.fromMinutes = fromMinutes
        set dat.fromSeconds = fromSeconds
        set dat.canExpire = canExpire
        set dat.expireMinutes = expireMinutes
        set dat.expireSeconds = expireSeconds
        set dat.runAfterExpire = runAfterExpire
        
        set dat.currentMinutes = dat.fromMinutes
        set dat.currentSeconds = dat.fromSeconds
        
        set dat.mbi = MultiboardGetItem(mb, row, column)
        call MultiboardSetItemWidth(dat.mbi, 0.04)
        call MultiboardSetItemStyle(dat.mbi, true, false)
        if (dat.currentSeconds < 10) then
            call MultiboardSetItemValue(dat.mbi, "|c"+dat.color+I2S(dat.currentMinutes)+":0"+I2S(dat.currentSeconds))
        else
            call MultiboardSetItemValue(dat.mbi, "|c"+dat.color+I2S(dat.currentMinutes)+":"+I2S(dat.currentSeconds))
        endif
        
        return dat
    endmethod
endstruct

globals
    private MTdata array MTdata_ar
    private integer totalMTdata = 0
endglobals

private function loopHelper takes MTdata dat returns nothing
    loop
        exitwhen (dat.wantDestroy == true)
        call TriggerSleepAction(1.00)
        call dat.runTimer.execute()
    endloop
endfunction

function MultiboardRemoveTimer takes multiboard mb, integer column, integer row returns nothing
    local MTdata dat
    local integer index = 0
    loop
        exitwhen (index == totalMTdata)
        set dat = MTdata_ar[index]
        if (mb == dat.mb) and (column == dat.column) and (row == dat.row) then
            set dat.wantDestroy = true
            call dat.destroy()
            loop
                exitwhen (index == totalMTdata)
                set dat = MTdata_ar[index - 1]
                set index = index + 1
            endloop
            set totalMTdata = totalMTdata - 1
            exitwhen (true)
        endif
        set index = index + 1
    endloop
endfunction

function MultiboardResetTimer takes multiboard mb, integer column, integer row returns nothing
    local MTdata dat
    local integer index = 0
    loop
        exitwhen (index == totalMTdata)
        set dat = MTdata_ar[index]
        if (mb == dat.mb) and (column == dat.column) and (row == dat.row) then
            set dat.currentMinutes = dat.fromMinutes
            set dat.currentSeconds = dat.fromSeconds
            exitwhen (true)
        endif
        set index = index + 1
    endloop
endfunction

function MultiboardResumeTimer takes multiboard mb, integer column, integer row returns nothing
    local MTdata dat
    local integer index = 0
    loop
        exitwhen (index == totalMTdata)
        set dat = MTdata_ar[index]
        if (mb == dat.mb) and (column == dat.column) and (row == dat.row) then
            set dat.isPaused = false
            exitwhen (true)
        endif
        set index = index + 1
    endloop
endfunction

function MultiboardPauseTimer takes multiboard mb, integer column, integer row returns nothing
    local MTdata dat
    local integer index = 0
    loop
        exitwhen (index == totalMTdata)
        set dat = MTdata_ar[index]
        if (mb == dat.mb) and (column == dat.column) and (row == dat.row) then
            set dat.isPaused = true
        endif
        set index = index + 1
    endloop
endfunction

function MultiboardAddTimer takes multiboard mb, integer column, integer row, string color, integer fromMinutes, integer fromSeconds, boolean canExpire, integer expireMinutes, integer expireSeconds, trigger runAfterExpire returns nothing
    local MTdata dat = MTdata.create(mb, column, row, color, fromMinutes, fromSeconds, canExpire, expireMinutes, expireSeconds, runAfterExpire)
    set MTdata_ar[totalMTdata] = dat
    set totalMTdata = totalMTdata + 1
    call loopHelper.execute(dat)
endfunction

endlibrary


The Map:
 
Reaction score
456
Update!

-System uses now only one main function, which is MultiboardAddTimer(..)
-Added new function named MultiboardPauseTimer(..)
-Added new function named MultiboardResumeTimer(..)
-Added new function named MultiboardResetTimer(..)
-Added new function named MultiboardRemoveTimer(..)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      • Ghan
        Administrator - Servers are fun

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top