HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

TriggerRegisterMouseClickInRect

02-17-2007, 02:49 PM#1
my_pkpk
In KaTTaNa's trackable demo ( Bomb Away ), there has a custom TriggerRegister function called TriggerRegisterMouseClickInRect, seems in the demo this function works pretty well, but I just see the implementation of this function in the j file, never find out where it got called. Can anyone explain it a bit for me ? thanks.

KaTTaNa's demo can be found here : http://www.wc3jass.com/files/Bombs.w3x
02-17-2007, 05:51 PM#2
The)TideHunter(
This is the function:

Collapse JASS:
function TriggerRegisterMouseClickInRect takes trigger whichTrigger, rect whichRect, force whichForce returns nothing
    local real x
    local real y = GetRectMinY(whichRect) + 64
    local real maxY = GetRectMaxY(whichRect)
    local real maxX = GetRectMaxX(whichRect)
    loop
        exitwhen y > maxY - 64
        set x = GetRectMinX(whichRect) + 64
        loop
            exitwhen x > maxX - 64
            call NewTrackable("war3mapImported\\4x4Trackable.mdl", x, y, whichForce, null, whichTrigger)
            set x = x + 128
        endloop
        set y = y + 128
    endloop
endfunction

All it is doing, is creating a trackable every 128x128 in the rect, pretty simple.
So whenever you click anywhere in the rect, it will set off the trigger.
The registration of the trackable in the trigger is in another function, called NewTrackable.

Here it is:

Collapse JASS:
function NewTrackable takes string path, real x, real y, force visiblePlayers, trigger trackEvent, trigger hitEvent returns nothing
    local trackable tc
    local integer i = 0
    local string model
    loop
        exitwhen i > 11
        set model = ""
        if ( IsPlayerInForce(Player(i), visiblePlayers) and GetPlayerController(Player(i)) == MAP_CONTROL_USER ) then
            if ( GetLocalPlayer() == Player(i) ) then
                set model = path
            endif
            set tc = CreateTrackable(model, x, y, 0)
            call SetHandleReal(tc, "x", x)
            call SetHandleReal(tc, "y", y)
            call SetHandleString(tc, "path", path)
            call SetHandleInt(tc, "player", i)
            if ( trackEvent != null ) then
                call TriggerRegisterTrackableTrackEvent(trackEvent, tc)
            endif
            if ( hitEvent != null ) then
                call TriggerRegisterTrackableHitEvent(hitEvent, tc)
            endif
        endif
        set i = i + 1
    endloop
endfunction
02-18-2007, 03:35 AM#3
my_pkpk
thanks, but I'm curious about how TriggerRegisterMouseClickInRect works if it doesn't get called via "Call TriggerRegisterMouseClickInRect( ..... )" something. At least we can't find it in the compiled j file.
Normally, we need to call a function to get it to work, like "call TriggerRegisterTrackableHitEvent(hitEvent, tc)" does, so that TriggerRegisterTrackableHitEvent works ,right ?
Kidda confused me .
02-26-2007, 12:41 PM#4
my_pkpk
still wanna bump it up, see if anyone can help.
02-26-2007, 01:30 PM#5
wantok
He never actually uses that function. He uses this one instead.

Collapse JASS:
function Trig_Init_Trackables_Actions takes nothing returns nothing
    local trigger hit = CreateTrigger()
    local trigger track = CreateTrigger()

    local real x
    local real y = GetRectMinY(gg_rct_Bomb_area) + 64
    local real maxY = GetRectMaxY(gg_rct_Bomb_area)
    local real maxX = GetRectMaxX(gg_rct_Bomb_area)
    loop
        exitwhen y > maxY - 64
        set x = GetRectMinX(gg_rct_Bomb_area) + 64
        loop
            exitwhen x > maxX - 64
            call NewTrackable("war3mapImported\\4x4Trackable.mdl", x, y, GetPlayersAll(), track, hit)
            set x = x + 128
        endloop
        set y = y + 128
    endloop
    
    call TriggerAddAction(hit, function TrackableHit)
    call TriggerAddAction(track, function TrackableTrack)
endfunction

//===========================================================================
function InitTrig_Init_Trackables takes nothing returns nothing
    set gg_trg_Init_Trackables = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Init_Trackables, function Trig_Init_Trackables_Actions )
endfunction