• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Trigger] Best recipe code?

Status
Not open for further replies.
Greetings everyone
----------
Intro:
I'm making a map wich has 7 orbs.
You need to pick up any 3 to gain an ability.
There are 84 possible combos.
Sometimes a diffirent hero type gets a diffirent spell.
----------

I use to have an event for every possible recipe (a unit aquires an item) plus a ITE to check the conditions and then give the ability. I was still new to trigger when I invented this method:

  • Frost amor
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • And - All (Conditions) are true
            • Conditions
              • (Item-type of (Item carried by (Hero manipulating item) in slot 1)) Equal to Orb of frost
              • (Item-type of (Item carried by (Hero manipulating item) in slot 2)) Equal to Orb of frost
              • (Item-type of (Item carried by (Hero manipulating item) in slot 3)) Equal to Orb of mana
          • And - All (Conditions) are true
            • Conditions
              • (Item-type of (Item carried by (Hero manipulating item) in slot 1)) Equal to Orb of frost
              • (Item-type of (Item carried by (Hero manipulating item) in slot 2)) Equal to Orb of mana
              • (Item-type of (Item carried by (Hero manipulating item) in slot 3)) Equal to Orb of frost
          • And - All (Conditions) are true
            • Conditions
              • (Item-type of (Item carried by (Hero manipulating item) in slot 1)) Equal to Orb of mana
              • (Item-type of (Item carried by (Hero manipulating item) in slot 2)) Equal to Orb of frost
              • (Item-type of (Item carried by (Hero manipulating item) in slot 3)) Equal to Orb of frost
    • Actions
      • Item - Remove (Item carried by (Hero manipulating item) in slot 1)
      • Item - Remove (Item carried by (Hero manipulating item) in slot 2)
      • Item - Remove (Item carried by (Hero manipulating item) in slot 3)
      • Unit - Add Frost Armor to (Hero manipulating item)
      • Special Effect - Create a special effect attached to the overhead of (Hero manipulating item) using Abilities\Spells\Orc\AncestralSpirit\AncestralSpiritCaster.mdl
      • Wait 0.80 seconds
      • Special Effect - Destroy (Last created special effect)
      • Special Effect - Create a special effect attached to the overhead of (Hero manipulating item) using Abilities\Spells\Items\ResourceItems\ResourceEffectTarget.mdl
      • Wait 0.10 seconds
      • Special Effect - Destroy (Last created special effect)
^ and I have 84 of them. I'm aware of the poor programming style.

Anyway so after 6 months of exp I invented a new method:

Only one of these
  • Counter
    • Events
      • Unit - A unit Acquires an item
    • Conditions
    • Actions
      • Set Temp_Unit = (Triggering unit)
      • For each (Integer Temp_Int) from 1 to 7, do (Actions)
        • Loop - Actions
          • Set iOrbs[Temp_Int] = 0
      • For each (Integer Temp_Int) from 1 to 6, do (Actions)
        • Loop - Actions
          • If ((Item-type of (Item carried by Temp_Unit in slot Temp_Int)) Equal to Orb of frost) then do (Set iOrbs[1] = (iOrbs[1] + 1)) else do (-------- 0 --------)
          • If ((Item-type of (Item carried by Temp_Unit in slot Temp_Int)) Equal to Orb of fire) then do (Set iOrbs[2] = (iOrbs[2] + 1)) else do (-------- 0 --------)
          • If ((Item-type of (Item carried by Temp_Unit in slot Temp_Int)) Equal to Orb of lighting) then do (Set iOrbs[3] = (iOrbs[3] + 1)) else do (-------- 0 --------)
          • If ((Item-type of (Item carried by Temp_Unit in slot Temp_Int)) Equal to Orb of light) then do (Set iOrbs[4] = (iOrbs[4] + 1)) else do (-------- 0 --------)
          • If ((Item-type of (Item carried by Temp_Unit in slot Temp_Int)) Equal to Orb of nature) then do (Set iOrbs[5] = (iOrbs[5] + 1)) else do (-------- 0 --------)
          • If ((Item-type of (Item carried by Temp_Unit in slot Temp_Int)) Equal to Orb of dark) then do (Set iOrbs[6] = (iOrbs[6] + 1)) else do (-------- 0 --------)
          • If ((Item-type of (Item carried by Temp_Unit in slot Temp_Int)) Equal to Orb of mana) then do (Set iOrbs[7] = (iOrbs[7] + 1)) else do (-------- 0 --------)
      • If (iOrbs[1] Equal to 3) then do (Trigger - Run FrostFrostFrost <gen> (ignoring conditions)) else do (-------- 0 --------)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
        • Then - Actions
          • -------- If true then run trigger --------
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
        • Then - Actions
          • -------- If true then run trigger --------
        • Else - Actions
and 84 of these
  • FrostFrostFrost
    • Events
    • Conditions
    • Actions
      • Item - Remove (Item carried by Temp_Unit of type Orb of frost)
      • Item - Remove (Item carried by Temp_Unit of type Orb of frost)
      • Item - Remove (Item carried by Temp_Unit of type Orb of frost)
      • -------- repeat this for every hero type --------
      • If ((Unit-type of Temp_Unit) Equal to Spirit of vengeance) then do (Unit - Add Frost bolt to Temp_Unit) else do (-------- 0 --------)
I havent tested it yet but my logic says that this should work.

Is this the best possible way to make recieps in GUI or is there a better way do do it?

Help are appriciated
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
Ugh i dont feel like writing this out though...

set every orb to an array

orb[1] = frost
orb[2] = ice
orb[3] = lightning

orbCount = 3
orbCountSq = (orbCount * orbCount)

than do

orbabil[1 + (1 * orbCount) + ( 1 * orbCountSq))] = frostFrostFrost
orbabil[1 + (1 * orbCount) + ( 2 * orbCountSq))] = frostFrostIce

than loop from 1 to orbCount
Code:
int numOrbs = 0
if unit has orb[mainloop] than
  if numOrbs = 0 then
    set orbToAdd = orbToAdd + mainloop
    numOrbs = 1
  elseif numOrbs = 1 then
    set orbToAdd = orbToAdd + (mainloop * orbCount)
    numOrbs = 2
  elseif numOrbs = 2 then
    set orbToAdd = orbToAdd + (mainLoop * orbCountSq)
  else
    //too many orbs lol
  endif
endif
if orbToAdd > orbCountSq then
  give unit ability orbabil[orbToAdd]
endif
 
Thanks, I don't think there is a command that says 'if unit has item of typy' or something (if unit has orb[mainloop]) anyway this is what i have sof far:

[text]Indexer
Events
Map initialization
Conditions
Actions
Set orb[1] = Orb of frost
Set orb[2] = Orb of fire
Set orb[3] = Orb of lighting
Set orb[4] = Orb of light
Set orb[5] = Orb of nature
Set orb[6] = Orb of dark
Set orb[7] = Orb of mana
-------- [1+(1*7)+(x*49)] --------
Set orbIndex[57] = FrostFrostFrost <gen>
Set orbIndex[106] = FrostFrostFire <gen>
Set orbIndex[155] = FrostFrostLightning <gen>
[/TRIGGER]
  • OrbCounter
    • Events
      • Unit - A unit Acquires an item
    • Conditions
    • Actions
      • Set Temp_Unit = (Triggering unit)
      • Set iNumOrbs = 0
      • For each (Integer Temp_Int) from 1 to 7, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
            • Then - Actions
            • Else - Actions
Can you please help me with that?

I really like the idea that you put the triggers into a array.
I was wondering if we can make a formula that makes 3 Frost orbs = 1, 2 Frost orbs + 1 Fire orb = 2, 3 Frost orbs + lightning = 3, ect.
I'll try to figure it out while I wait for your reply :)

EDIT: after more than two hours I've found something:
PHP:
1 = n(1)
2 = n(2)
3 = n(5)
4 = n(14)
5 = n(41)
6 - n(122)
7 = n(365)

111 = 3
112 = 4
122 = 5
222 = 6
113 = 7
123 = 8
223 = 9
133 = 11
233 = 12 
333 = 15 
114 = 16
124 = 17
224 = 18
134 = 20
234 = 21
334 = 24
144 = 29
244 = 30
344 = 33
444 = 42
the formula is 3 times the previous one - 1.
So what I can do is index the elemental triggers and say:
run trigger[(iOrbs[1]*1)+(iOrbs[2]*2)+(iOrbs[3]*5)+(iOrbs[4]*14)+(iOrbs[5]*41)+(iOrbs[6]*122)+(iOrbs[7]*365)

can this work?
 
Last edited:
Level 19
Joined
Aug 8, 2007
Messages
2,765
hm, gui is so inferior to JASS

i didn't really say to put the triggers into the array i meant to put the abilities into an array, that way you dont have to make a gazillion triggers.

you can have a variable array orbsPossessed

Code:
for i = 7 downto 0 //or in GUI, just tempint from 1 to 7
  for i2 = 6 downto 1 //or in GUI, tempint2 from 1 to 6
    if unit has orb[i] in slot i2 == true then
      set orbsPossessed[i] = orbsPossessed[i] + 1
    endif
  endfor
endfor

than instead of unit has item orb[loop], you can just do orbsPossessed[loop] > 0. you could also modify my old code



Code:
int numOrbs = 0
if orbsPossessed[mainloop] == 1 than
  if numOrbs = 0 then
    set orbToAdd = orbToAdd + mainloop
    numOrbs = 1
  elseif numOrbs = 1 then
    set orbToAdd = orbToAdd + (mainloop * orbCount)
    numOrbs = 2
  elseif numOrbs = 2 then
    set orbToAdd = orbToAdd + (mainLoop * orbCountSq)
  else
    //too many orbs lol
  endif
elseif (numOrbs == 1 or numOrbs == 0) and orbsPossessed[mainloop] == 2 then
  if numOrbs == 0 then
    set orbToAdd = orbToAdd + mainloop  + (mainloop * orbCount)
  elseif numOrbs == 1 then
    set orbToAdd = orbToAdd + (mainloop * orbCount) + (mainloop * orbCountSq)
elseif numOrbs == 0 and orbsPossessed[mainloop] == 3 then
  set orbToAdd = orbToAdd + mainloop + (mainloop * orbCount) + (mainloop * orbCountSq)
endif

//end loop "main loop"

if orbToAdd > orbCountSq and orbToAdd < (orbCountSq * orbCountSq + orbCount + 1) then
  give unit ability orbabil[orbToAdd]
endif

for i = 7 downto 0
  set orbsPossessed[i] = 0
endfor
note the last three lines, you have to reset it if its a global variable
in regards to your forumla question, thats what this is. its a simple 3d array emulator through cubic dimension principles.
 
Ah I understand. I don't think it will be wise to put the abilities into an array because the abilities are diffirent for diffirent hero types. The number of abilities will also keep increasing with the updates so it might go into the thousands.

I have edited my previous post and has found a rather better (or so I think) method for 3D arrays because it's values are lower. So I was thinking about replacing my first loop with yours and then launch the trigger as explained in my edited post.

Thanks for all your help :)
+rep
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
Whatever you like, my code is written in base {orbCount} an extremely odd version of base {orbCount} because of how GUI doesn't use array 0) so it supports every permutation of every orb. You could always add another base to the orb array for hero but that would overflow ez.
 
I was thinking about indexing an ability list for each hero type and then multiple the orb code based on the hero type but I was afraid that I will hit the OP limit. Anyway here is the final trigger ^^
  • Counter
    • Events
      • Unit - A unit Acquires an item
    • Conditions
    • Actions
      • Set Temp_Unit = (Triggering unit)
      • Set iNumOrbs = 0
      • For each (Integer Temp_Int) from 1 to 7, do (Actions)
        • Loop - Actions
          • Set iOrbs[Temp_Int] = 0
          • For each (Integer Temp_IntB) from 1 to 6, do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Item-type of (Item carried by Temp_Unit in slot Temp_IntB)) Equal to Item[Temp_Int]
                • Then - Actions
                  • Set iOrbs[Temp_Int] = (iOrbs[Temp_Int] + 1)
                  • Set iNumOrbs = (iNumOrbs + 1)
                • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Temp_Unit is A Hero) Equal to True
        • Then - Actions
          • If (iNumOrbs Equal to 3) then do (Trigger - Run Trigger[(iOrbs[1] + ((2 x iOrbs[2]) + ((5 x iOrbs[3]) + ((14 + iOrbs[4]) + ((41 x iOrbs[5]) + ((122 x iOrbs[6]) + (365 x iOrbs[7])))))))] (ignoring conditions)) else do (-------- 0 --------)
        • Else - Actions
The outcome looks actually simple (well it is suppose to BE simple lol)
 
Status
Not open for further replies.
Top