Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Unit enters any rect

Discussion in 'World Editor Help Zone' started by TerraNexx, Nov 21, 2011.

  1. TerraNexx

    TerraNexx

    Joined:
    Dec 9, 2008
    Messages:
    230
    Resources:
    0
    Resources:
    0
    Can I make an event like this:

    Unit enters any rect

    and action like this:


    Game - Display to (Player group((Owner of (Triggering unit)))) the text: Name of entering rect

    I want to text displayed for every rect when unit enters it, but i don't want to make triggers for each separate..i found Name of current trigger but that still makes me to to all the triggers manually.
     
  2. aldo2000

    aldo2000

    Joined:
    Sep 30, 2011
    Messages:
    148
    Resources:
    0
    Resources:
    0
    Sorry, I'm not good at english, so rect is region or what?
     
  3. TerraNexx

    TerraNexx

    Joined:
    Dec 9, 2008
    Messages:
    230
    Resources:
    0
    Resources:
    0
    yeah what region is in original editor in JNGP it's called rect.
     
  4. WaterKnight

    WaterKnight

    Joined:
    Aug 18, 2009
    Messages:
    4,035
    Resources:
    5
    Maps:
    1
    Tutorials:
    4
    Resources:
    5
    You do not need separate triggers but an event for each rect. And since there is only GetTriggeringRegion() (in Jass) as event response, none for rect, you would have to attach the rect to the region (or directly attach the name as rects have no alphanumeric names).

    When creating a Unit enters rect event in GUI, it actually does not directly link the rect to the event but it creates an instance of the jass type region, which is granted the cells of your rect and registers this region object.
     
  5. TerraNexx

    TerraNexx

    Joined:
    Dec 9, 2008
    Messages:
    230
    Resources:
    0
    Resources:
    0
    So this is only possible in jass?
    I feared so :D
     
  6. WaterKnight

    WaterKnight

    Joined:
    Aug 18, 2009
    Messages:
    4,035
    Resources:
    5
    Maps:
    1
    Tutorials:
    4
    Resources:
    5
    Since you told about JNGP, I assume you use it and have vJass enabled.

    Code (vJASS):
    struct EnterableRects
        static hashtable HT
        static trigger T

        static method Trig takes nothing returns nothing
            set udg_s = LoadStr(thistype.HT, GetHandleId(GetTriggeringRegion()), 0)  //save name in variable s, variables that you have created in GUI (variable editor) are prefixed by "udg_" in jass

            call TriggerExecute(gg_trg_YourTrigger)  //runs YourTrigger, triggers that you have created in GUI are prefixed by ""gg_trg_" in jass, event responses are preserved through TriggerExecute
        endmethod

        static method RegisterRect takes rect source, string name returns nothing
            local region r = CreateRegion()

            call RegionAddRect(r, source)
            call TriggerRegisterEnterRegion(thistype.T, r, null)
            call SaveStr(thistype.HT, GetHandleId(r), 0, name)
        endmethod

        static method onInit takes nothing returns nothing
            set thistype.HT = InitHashtable()
            set thistype.T = CreateTrigger()

            call TriggerAddAction(thistype.T, function thistype.Trig)

            //init your rects with names here, rects that you have created in GUI (3d view) are prefixed by "gg_rct_" in jass
            call thistype.RegisterRect(gg_rct_abc, "abc")
            call thistype.RegisterRect(gg_rct_def, "def")
            call thistype.RegisterRect(gg_rct_ghi, "ghi")
        endmethod
    endstruct
     
  7. TerraNexx

    TerraNexx

    Joined:
    Dec 9, 2008
    Messages:
    230
    Resources:
    0
    Resources:
    0
    So I just have to make all the regions and then save is as a name in the variable, and hmm.

    How do i make that trigger that you called "YourTrigger", what events do i use?

    I do have JNGP and vJass enabled but I don't use it..never been persistent enough to make myself learn it, even tho I'm starting to catch up a bit.
     
  8. WaterKnight

    WaterKnight

    Joined:
    Aug 18, 2009
    Messages:
    4,035
    Resources:
    5
    Maps:
    1
    Tutorials:
    4
    Resources:
    5
    Create your rects in the 3d display, register them at the bottom of the code as shown and the second parameter in the same line would be their assigned name.

    Create a variable s in variable editor (or pick your desired name and adjust udg_s then) and create a trigger page like you know it with CTRL+T, name it YourTrigger or adjust gg_trg_YourTrigger afterwards if you want another name.

    This YourTrigger does not need further events, just your desired actions. Variable s will contain the entered rect's name and all other event responses are as if you used Unit enters rect event, so Triggering unit is the unit who entered. The code here does not account for post hoc movement of the rects (Unit enters rect event from GUI does not either btw).

    If you want, I could also implement to transfer the rect through a variable to YourTrigger but rects do not have that much to gain from either, maybe borders/center.
     
  9. TerraNexx

    TerraNexx

    Joined:
    Dec 9, 2008
    Messages:
    230
    Resources:
    0
    Resources:
    0
    thats awesome man tnx a lot!

    Just one more question:
    If i create conditions in YourTrigger, like
    • ((Triggering unit) is A Hero) Equal to (==) True


    will it work or this jass script of yours only executes actions no matter the conditions?
     
  10. WaterKnight

    WaterKnight

    Joined:
    Aug 18, 2009
    Messages:
    4,035
    Resources:
    5
    Maps:
    1
    Tutorials:
    4
    Resources:
    5
    TriggerExecute
    only fires the actions. You can either move your conditions in the action block with If/Then/Else (use action Skip Remaining Actions so you do not have to encapsulate everything that comes afterwards) or replace
    TriggerExecute
    by
    ConditionalTriggerExecute
    .
     
  11. TerraNexx

    TerraNexx

    Joined:
    Dec 9, 2008
    Messages:
    230
    Resources:
    0
    Resources:
    0
    awesome i use If/then/else all the time but i didn't think about it now :D
    well thanks, you really saved me from tons of work :)

    EDIT:

    After couple of tries I failed to implement this code into my map..Here's what I did:

    I created a trigger called Enterable Regions and converted it to text, then copied your script into it.
    Then I made a rect called "City", and made a variable called Region_Name. I modified lines where those are mentioned.

    Here's what i don't get: what type of variable this has to be? My JNGP crashes every time i try to use this variable anywhere in any action..I've tried with string, real.. It must be something convert-able to string.
     
    Last edited: Nov 21, 2011
  12. -Kobas-

    -Kobas-

    Joined:
    Jan 17, 2010
    Messages:
    5,892
    Resources:
    28
    Icons:
    1
    Tools:
    2
    Maps:
    10
    Spells:
    4
    Template:
    5
    Tutorials:
    6
    Resources:
    28
    You can use locations, regions, range and many more things.
    Can you explain real problem, not the way you wanted to solve it.
    Maybe we can show you more efficient way than using many regions.
     
  13. TerraNexx

    TerraNexx

    Joined:
    Dec 9, 2008
    Messages:
    230
    Resources:
    0
    Resources:
    0
    I want to do the following:
    When hero enters an area, name of that area will be displayed to owner of entering hero.

    That's all.
     
  14. Maker

    Maker

    Joined:
    Mar 6, 2006
    Messages:
    9,174
    Resources:
    17
    Maps:
    2
    Spells:
    14
    Tutorials:
    1
    Resources:
    17
    Changed this:
    call TriggerExecute(gg_trg_ER)


    • ER
      • Events
      • Conditions
      • Actions
        • Set pgrp = (Player group((Owner of (Triggering unit))))
        • Game - Display to pgrp the text: s
        • Custom script: call DestroyForce(udg_pgrp)


    You must have a variable called s, which is string. I'm using player group variable called pgrp to avoid the leak.
     
  15. TerraNexx

    TerraNexx

    Joined:
    Dec 9, 2008
    Messages:
    230
    Resources:
    0
    Resources:
    0

    Tnx Maker but what do i do with this one?
    How do I implement that..into a seperate trigger or what?
    And how to register rects at the end of that code?
     
  16. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,429
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    Yeah, just create a new trigger (the name doesn't matter), then go to "Edit -> Convert to Custom Text". Remove all of the code in the trigger, and then paste the code that was posted above.

    Next, in this section:
    Code (vJASS):
        static method onInit takes nothing returns nothing
            set thistype.HT = InitHashtable()
            set thistype.T = CreateTrigger()

            call TriggerAddAction(thistype.T, function thistype.Trig)

            //init your rects with names here, rects that you have created in GUI (3d view) are prefixed by "gg_rct_" in jass
            call thistype.RegisterRect(gg_rct_abc, "abc")
            call thistype.RegisterRect(gg_rct_def, "def")
            call thistype.RegisterRect(gg_rct_ghi, "ghi")
        endmethod


    You can register your rects. To figure out how, open the region palette and look at all the names you want to register it for. For example, if you want to register it for a rect named "FarmRect", and you want it to display the text "Hi, my name is Joe", then this would be the code:
    Code (vJASS):
    call thistype.RegisterRect(gg_rct_FarmRect, "Hi, my name is Joe")


    Then you add the trigger you want to be fired to display the text. Example, a trigger named ER like the one Maker has:
    Code (vJASS):
        static method Trig takes nothing returns nothing
            set udg_s = LoadStr(thistype.HT, GetHandleId(GetTriggeringRegion()), 0)  //save name in variable s, variables that you have created in GUI (variable editor) are prefixed by "udg_" in jass

            call TriggerExecute(gg_trg_ER)  //runs YourTrigger, triggers that you have created in GUI are prefixed by ""gg_trg_" in jass, event responses are preserved through TriggerExecute
        endmethod


    So let's say you have two more rects named "BarracksRect" and "BarracksObamaRect", and you want "hoohaa" and "jarjar" to be displayed respectively. This is what the total code would look like:
    Code (vJASS):
    struct EnterableRects
        static hashtable HT
        static trigger T

        static method Trig takes nothing returns nothing
            set udg_s = LoadStr(thistype.HT, GetHandleId(GetTriggeringRegion()), 0)  //save name in variable s, variables that you have created in GUI (variable editor) are prefixed by "udg_" in jass

            call TriggerExecute(gg_trg_ER) //runs YourTrigger, triggers that you have created in GUI are prefixed by ""gg_trg_" in jass, event responses are preserved through TriggerExecute
        endmethod

        static method RegisterRect takes rect source, string name returns nothing
            local region r = CreateRegion()

            call RegionAddRect(r, source)
            call TriggerRegisterEnterRegion(thistype.T, r, null)
            call SaveStr(thistype.HT, GetHandleId(r), 0, name)
        endmethod

        static method onInit takes nothing returns nothing
            set thistype.HT = InitHashtable()
            set thistype.T = CreateTrigger()

            call TriggerAddAction(thistype.T, function thistype.Trig)

            //init your rects with names here, rects that you have created in GUI (3d view) are prefixed by "gg_rct_" in jass
            call thistype.RegisterRect(gg_rct_FarmRect, "Hi, my name is Joe.")
            call thistype.RegisterRect(gg_rct_BarracksRect, "hoohaa")
            call thistype.RegisterRect(gg_rct_BarracksObamaRect, "jarjar")
        endmethod
    endstruct


    Once you've done that, just use Maker's code in your trigger.
    • ER
      • Events
      • Conditions
      • Actions
        • Set pgrp = (Player group((Owner of (Triggering unit))))
        • Game - Display to pgrp the text: s
        • Custom script: call DestroyForce(udg_pgrp)


    Basically, the system assigns a string (that you specify) to each rect and registers when each one is entered. Once one is entered, it loads the string into a variable named s (create it in the variable editor, of type "string") that you can display. Therefore, you only need 1 trigger.
     
  17. TerraNexx

    TerraNexx

    Joined:
    Dec 9, 2008
    Messages:
    230
    Resources:
    0
    Resources:
    0
    awesome!! that's what i needed, tnx for showing me how to do it :))

    and i can call more of

    call thistype.RegisterRect

    functions just typing them under these three right?

    EDIT: yeah I've made all like you guys said but my jngp crashes when i try to save the map. Seems like i put the code wrong or something, anyway here's what I did:

    • Region Enter
      • Events
      • Conditions
      • Actions
        • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • ((Triggering unit) is A Hero) Equal to (==) True
            • ((Owner of (Triggering unit)) controller) Equal to (==) User
          • Then - Actions
          • Else - Actions
        • Set Region_PlayerGrp = (Player group((Owner of (Triggering unit))))
        • Game - Display to Region_PlayerGrp the text: Region_Text
        • Custom script: call DestroyForce(udg_Region_PlayerGrp)


    Code (vJASS):
    struct EnterableRects
        static hashtable HT
        static trigger T

        static method Trig takes nothing returns nothing
            set udg_Region_Text = LoadStr(thistype.HT, GetHandleId(GetTriggeringRegion()), 0)  //save name in variable s, variables that you have created in GUI (variable editor) are prefixed by "udg_" in jass

            call TriggerExecute(gg_trg_Region_Enter) //runs YourTrigger, triggers that you have created in GUI are prefixed by ""gg_trg_" in jass, event responses are preserved through TriggerExecute
        endmethod

        static method RegisterRect takes rect source, string name returns nothing
            local region r = CreateRegion()

            call RegionAddRect(r, source)
            call TriggerRegisterEnterRegion(thistype.T, r, null)
            call SaveStr(thistype.HT, GetHandleId(r), 0, name)
        endmethod

        static method onInit takes nothing returns nothing
            set thistype.HT = InitHashtable()
            set thistype.T = CreateTrigger()

            call TriggerAddAction(thistype.T, function thistype.Trig)

            //init your rects with names here, rects that you have created in GUI (3d view) are prefixed by "gg_rct_" in jass
            call thistype.RegisterRect(gg_rct_2nd, "fak jea")
            call thistype.RegisterRect(gg_rct_1st, "hoohaa")
        endmethod
    endstruct
     
    Last edited: Nov 24, 2011
  18. Maker

    Maker

    Joined:
    Mar 6, 2006
    Messages:
    9,174
    Resources:
    17
    Maps:
    2
    Spells:
    14
    Tutorials:
    1
    Resources:
    17
    ^Yeah.
     
  19. TerraNexx

    TerraNexx

    Joined:
    Dec 9, 2008
    Messages:
    230
    Resources:
    0
    Resources:
    0
    huh? could you tell me where the code is wrong