• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Unit enters any rect

Status
Not open for further replies.
Level 6
Joined
Dec 9, 2008
Messages
233
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.
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
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.
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
Since you told about JNGP, I assume you use it and have vJass enabled.

JASS:
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
 
Level 6
Joined
Dec 9, 2008
Messages
233
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.
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
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.
 
Level 6
Joined
Dec 9, 2008
Messages
233
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?
 
Level 6
Joined
Dec 9, 2008
Messages
233
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:
Level 6
Joined
Dec 9, 2008
Messages
233
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.
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
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.
 
Level 6
Joined
Dec 9, 2008
Messages
233
JASS:
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


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?
 
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:
JASS:
    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:
JASS:
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:
JASS:
    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:
JASS:
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.
 
Level 6
Joined
Dec 9, 2008
Messages
233
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)
JASS:
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:
Status
Not open for further replies.
Top