• 🏆 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!

[JASS] Combine Triggers

Status
Not open for further replies.
Level 16
Joined
May 1, 2008
Messages
1,605
Moin moin =)

It's me again and I have a simple question. At all not simple for me, because if I try something
like this, it always gets buggy somehow.

As you see in the title, I want combine triggers. Let's say I have this two triggers:
JASS:
function Actions1 takes nothing returns nothing
    local real x = GetRectCenterX(gg_rct_WhoKnows)
    local real y = GetRectCenterY(gg_rct_WhoKnows)
    
    call SetUnitX(GetTriggerUnit(),x)
    call SetUnitY(GetTriggerUnit(),y)
endfunction

//===========================================================================
function InitTrig_Enter1 takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterEnterRectSimple(t,gg_rct_KnowsWho)
    call TriggerAddAction(t,Actions1)
endfunction

JASS:
function Actions2 takes nothing returns nothing
    local real x = GetRectCenterX(gg_rct_KnowsWho)
    local real y = GetRectCenterY(gg_rct_KnowsWho)
    
    call SetUnitX(GetTriggerUnit(),x)
    call SetUnitY(GetTriggerUnit(),y)
endfunction

//===========================================================================
function InitTrig_Enter1 takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterEnterRectSimple(t,gg_rct_WhoKnows)
    call TriggerAddAction(t,Actions2)
endfunction

Again, how must I do this, that I can use this in one trigger PLUS: I have more of this "Rect Enter" triggers, so I thought, that I need 3 globals for x,y and u (the triggerunit()). So how to combine all this, to one (bigger) good working trigger? =)

Greetings - Thanks - Peace
Dr. Boom
 
Something like this would probably work:
JASS:
globals
    hashtable hash = InitHashtable()                
endglobals

function GetEnteredRect takes nothing returns rect
    return LoadRectHandle(hash,GetHandleId(GetTriggeringRegion()),0)
endfunction

function TriggerRegisterEnterRect takes trigger t, rect r returns event
    local region rectRegion = CreateRegion()
    call RegionAddRect(rectRegion,r)
    call SaveRectHandle(hash,GetHandleId(rectRegion),0,r)
    return TriggerRegisterEnterRegion(t,rectRegion,null)
endfunction

Just use TriggerRegisterEnterRect(trig,rect) and then use GetEnteredRect() in the actions function, like so:
JASS:
function Actions1 takes nothing returns nothing
    local rect r = GetEnteredRect()
    local real x = GetRectCenterX(r)
    local real y = GetRectCenterY(r)
    
    call SetUnitX(GetTriggerUnit(),x)
    call SetUnitY(GetTriggerUnit(),y)
endfunction

//===========================================================================
function InitTrig_Enter1 takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterEnterRect(t,gg_rct_KnowsWho)
    call TriggerRegisterEnterRect(t,gg_rct_WhoKnows)
    call TriggerAddAction(t,Actions1)
endfunction

Untested, but that should work.
 
Level 16
Joined
May 1, 2008
Messages
1,605
This maybe could work, but I don't understand this at all.

When a unit enters WhoKnows, how this triggers should know, that the unit should instantly move to KnowsWho?
Because as far as I understand, only the rect, which is entered is store in the hash, but not the rect, where the unit should be after.
 
Level 16
Joined
May 1, 2008
Messages
1,605
Ahh I understand it, but this doesn't solve the question I had or? =O

Because I want combine both triggers (I posted) into only one trigger, but I can't see the way in this example =O
So it's like in one trigger, I have 2 events (enter rect 1 or 2), 1 condition for both (TriggerUnit = xx) and 2 actions (for action when enter rect 1 or rect 2)
 
Level 22
Joined
Nov 14, 2008
Messages
3,256
This will probably do it.

JASS:
function Actions1 takes nothing returns nothing
    local rect r = GetEnteredRect()
    if r == gg_rct_KnowsWho then
         call SetUnitX(GetTriggerUnit(),GetRectCenterX(gg_rct_WhoKnows))
         call SetUnitY(GetTriggerUnit(),GetRectCenterY(gg_rct_WhoKnows))
    else
         call SetUnitX(GetTriggerUnit(),GetRectCenterX(gg_rct_KnowsWho))
         call SetUnitY(GetTriggerUnit(),GetRectCenterY(gg_rct_KnowsWho))
    endif
endfunction
 
Level 20
Joined
Jul 6, 2009
Messages
1,885
Just put it like this (example)
JASS:
function Actions1 takes nothing returns nothing
    local real x = GetRectCenterX(gg_rct_WhoKnows)
    local real y = GetRectCenterY(gg_rct_WhoKnows)
    
    call SetUnitX(GetTriggerUnit(),x)
    call SetUnitY(GetTriggerUnit(),y)
endfunction

function Actions2 takes nothing returns nothing
    local real x = GetRectCenterX(gg_rct_KnowsWho)
    local real y = GetRectCenterY(gg_rct_KnowsWho)
    
    call SetUnitX(GetTriggerUnit(),x)
    call SetUnitY(GetTriggerUnit(),y)
endfunction

//===========================================================================
function InitTrig_Enter1 takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterEnterRectSimple(t,gg_rct_KnowsWho)
    call TriggerAddAction(t,Actions1)
    set t = CreateTrigger()
    call TriggerRegisterEnterRectSimple(t,gg_rct_WhoKnows)
    call TriggerAddAction(t,Actions2)
    set t = null
endfunction
 
Status
Not open for further replies.
Top