Hero gains a attribute event

Accname

2D-Graphics enthusiast
Reaction score
1,462
no there aint. but you, as the maker of the map, should always know whenever the hero will get an attribute bonus or not. there aint that many ways to get one.
 

Wratox1

Member
Reaction score
22
no there aint. but you, as the maker of the map, should always know whenever the hero will get an attribute bonus or not. there aint that many ways to get one.

im not talking about attribute bonus, i have a trigger that will add 1 strength for example, and i want to be able to detect when a hero gains the attribute
 

esb

Because none of us are as cruel as all of us.
Reaction score
329
Well then, when the trigger that adds 1 strength runs, run the other one.
 

Wratox1

Member
Reaction score
22
Well then, when the trigger that adds 1 strength runs, run the other one.

omg why didnt i think of that! thank you!
+rep!

i have another question:
with the event:
Trigger:
  • Unit - A unit enters weapon1 <gen>


if i have many regions, and adding this event for all of them to 1 trigger, how can i check which region was entered?
or what is the simplest way to do it?
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
unfotunately there aint an easy way to do this.

one way would be that you store all these regions inside an array variable. when the event triggers, that means any of this regions has been entered, you run an iteration through all regions and check whether they contain the triggering unit or not.

thats not a very good method cause its rather uneffective. but its the easiest.

another way you could do it is creating a simple trigger like this for all regions:
Trigger:
  • Events
    • Unit - Unit enters region X
    • Conditions
    • Actions
      • set Temp_Region = region X
      • Trigger - Run MYTRIGGER (checking conditions)


and all the actions you want to do are within the other trigger called MYTRIGGER in the example.
Temp_Region would then be the region your unit entered.
(Triggering Unit) or (Entering Unit) would still work if you use it in the other trigger.

the second method is alot more effective performance-wise but its alot more work for you as well.
 

Wratox1

Member
Reaction score
22
unfotunately there aint an easy way to do this.

one way would be that you store all these regions inside an array variable. when the event triggers, that means any of this regions has been entered, you run an iteration through all regions and check whether they contain the triggering unit or not.

thats not a very good method cause its rather uneffective. but its the easiest.

another way you could do it is creating a simple trigger like this for all regions:
Trigger:
  • Events
    • Unit - Unit enters region X
    • Conditions
    • Actions
      • set Temp_Region = region X
      • Trigger - Run MYTRIGGER (checking conditions)


and all the actions you want to do are within the other trigger called MYTRIGGER in the example.
Temp_Region would then be the region your unit entered.
(Triggering Unit) or (Entering Unit) would still work if you use it in the other trigger.

the second method is alot more effective performance-wise but its alot more work for you as well.

well, i was trying to not having to create 1 trigger for each region..
but how uneffective is it to have a loop running through all the regions compared to the other method? is it noticeable in-game?
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
well, i'd say that depends on 2 factors. how many regions do you have and how fast are the computers you want to run that map on.

basically i dont think it would be that much of a problem since the comparison and the iteration itself shouldnt be that harmful to the performance.
just imagine, if you have 100 regions it will run 100 if/then/else statements every time one of the regions is entered.

another problem with this method would be if 2 regions overlap. this might result with your trigger thinking both regions have been entered at once even though the unit was standing within one of them before it entered the second.
 

Wratox1

Member
Reaction score
22
well, i'd say that depends on 2 factors. how many regions do you have and how fast are the computers you want to run that map on.

basically i dont think it would be that much of a problem since the comparison and the iteration itself shouldnt be that harmful to the performance.
just imagine, if you have 100 regions it will run 100 if/then/else statements every time one of the regions is entered.

another problem with this method would be if 2 regions overlap. this might result with your trigger thinking both regions have been entered at once even though the unit was standing within one of them before it entered the second.

hmm, i think i will do the second method, because when someone enters a region, i have a boolean that i will set to false=the region is not active anymore, an with the first method i will have to either have alot of if-then-elses or find a way to check the indexnumber of the entered region and the compare it with the boolean index..
 

Ashlebede

New Member
Reaction score
43
The part about regions overlapping can be easily avoided with [ljass]GetTriggeringRegion()[/ljass] instead of checking if the triggering unit is in the region. I think it has a GUI equivalent, but I'm too lazy to plug in my USB device, open up world editor, wait 5 minutes for its startup... although I ain't sure whether GUI can compare [ljass]region[/ljass]s and [ljass]rect[/ljass]s...

Best would be to have multiple triggers, though.

Oh, and you can delete a region when it's not active anymore instead of setting booleans or whatever. That way its events just don't trigger anymore and I think you save a couple bytes of RAM.

[ljass]call RemoveRegion(GetTriggeringRegion()) //clears the region[/ljass]
[ljass]call RemoveRect(gg_rct_My_Regions_Name) //clears the rect (part of the region which is in fact just the same, in GUI)[/ljass]

You need to use both of these for the best result. Along with

[ljass]call DestroyTrigger(GetTriggeringTrigger())[/ljass]

To disable the whole trigger and make it unretrievable, but save some RAM.
 

AoW_Hun7312

I'm a magic man, I've got magic hands.
Reaction score
76
Trigger:
  • Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- Repeat for # of regions. --------
      • Set Regions[0] = Region 000 <gen>
      • Set Regions[1] = Region 001 <gen>
      • Set Regions[2] = Region 002 <gen>
      • -------- Replace 2 with the last index. --------
      • Set LastRegionIndex = 2
      • For each (Integer A) from 0 to LastRegionIndex, do (Actions)
        • Loop - Actions
          • Trigger - Add to Detect Entering Unit <gen> the event (Unit - A unit enters Regions[(Integer A)])


Trigger:
  • Detect Entering Unit
    • Events
    • Conditions
    • Actions
      • For each (Integer A) from 0 to LastRegionIndex, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Regions[(Integer A)] contains (Triggering unit)) Equal to True
            • Then - Actions
              • -------- Your actions here. --------
            • Else - Actions
 

Ashlebede

New Member
Reaction score
43
May I ask what use it is to use an initialization trigger to add events if you still have to enter the regions manually? >_> (except waste a couple bytes of RAM...)

You'd have to make an equal number of [ljass]if,then,else[/ljass]'s, anyways, the only difference being you have to check which region [ljass]Regions[(Integer A)][/ljass] is, which means even more tests... so it's basically worse performance, though it most definitely doesn't make any significant difference. It doesn't increase readability or anything, either.

If it's the same actions for every region, then, yes, it is a good idea, though. But then there would be no real need to check which region is entered. Just a single trigger for the whole thing, without conditions...
 

Jedi

New Member
Reaction score
63
You need to wait 0.00 seconds or something like that since unit enters region event fires when unit enters, but region contains unit check is unit's origin in region.
 

Wratox1

Member
Reaction score
22
region overlapping wont be a problem, but thanks anyway!

If it's the same actions for every region, then, yes, it is a good idea, though. But then there would be no real need to check which region is entered. Just a single trigger for the whole thing, without conditions...
well thats the problem, its the same for every region, except that i set a boolean-array to false, and i need to know which array-slot? to set to false.. the region-array and the boolean-array have equal amount of "slots"(what is it called?) and 1 region has its corresponding boolean..
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
@Ashlebede: There really is a GetTriggeringRegion() Funktion? lol, i never knew, i asked that several times nobody ever told me that.

well, of course, if there is then just use it.
 

Ashlebede

New Member
Reaction score
43
@Ashlebede: There really is a GetTriggeringRegion() Funktion? lol, i never knew, i asked that several times nobody ever told me that.

well, of course, if there is then just use it.

Note, however, that it returns a [ljass]region[/ljass], not a [ljass]rect[/ljass]. That means you probably cannot compare [ljass]GetTriggeringRegion()[/ljass] and [ljass]gg_rct_My_Regions_Name[/ljass] without using Jass and/or storing the regions in a [ljass]region[/ljass] variable.

The difference between a region and a rect is that the rect is always a rectangle. The region is an area which can contain one or more rects.

The solution would be creating a [ljass]handle[/ljass] (there is no [ljass]region[/ljass] type in GUI, what is called "region" is in fact a [ljass]rect[/ljass]) global variable and give it a [ljass]region[/ljass]-type value to compare to have something to compare [ljass]GetTriggeringRegion()[/ljass] with.

The pros : you can be sure which region was entered, this is the most accurate method.

The cons : it requires custom script for event registration and conditions. This also means a second trigger for event registration (unless your trigger is converted to Jass).

An example usage:

JASS:
function InitTrig_MyTrigger takes nothing returns nothing
    local region r=CreateRegion()
    set gg_trg_MyTrigger=CreateTrigger()

    call PolledWait(.1)//make sure the other trigger's init was run

    call RegionAddRect(r,gg_rct_My_Regions_Name) //add the rect to the region (doesn't work with handle-type vars

    call TriggerRegisterEnterRegion(gg_trg_OtherTrigger,r,null) //add an event

    set udg_My_Handle_Variable = r //this handle can only be used for comparison with the region, not as a parameter for functions.

    set r = null //leak clearing
endfunction


Trigger:
  • //Hand-written
    • Events
    • --------Added in the other trigger--------
    • Conditions
    • --------Whatever you need here--------
    • Actions
      • Custom Script : if udg_My_Handle_Variable==GetTriggeringRegion() then
      • --------Actions---------
      • Custom Script : endif


There really is a GetTriggeringRegion() Funktion? lol, i never knew, i asked that several times nobody ever told me that.

There is always a way to find out which elements "trigger the trigger" for every element, as far as I know. In fact, your whole map could be in a single trigger... although performance-wise, it would be verry stupid. But it could.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top