• Check out the results of the Techtree Contest #19!
  • 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.
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

[Solved]*Replacement for 2d array.. on just a array..

Status
Not open for further replies.
Level 11
Joined
Sep 12, 2008
Messages
657
hey, i have made a AI for my arena map..
it works perfect, right now it attacks units, moves to heal when needed,
goes into places, etc.
but i wanted to add the code the ability to make heroes learn spells..
i just figured i needed 2d array for that.. ([1, 1] = spell #1 hero #1, [1, 2] = spell #1, hero #2, and so on.)
so i did this instead:
  • Actions
    • -------- ------------------------------ --------
    • -------- ------- Edit Here ------ --------
    • -------- ------------------------------ --------
    • Set ComputerAI_HeroList[1] = Paladin
    • Set ComputerAI_HeroList[2] = Blademaster
    • Set ComputerAI_HeroList[3] = Mountain King
    • Set ComputerAI_HeroList[4] = Tauren Chieftain
    • -------- ------------------------------ --------
    • Set ComputerAI_Spells[1] = Divine Shield
    • Set ComputerAI_Spells[2] = Devotion Aura
    • Set ComputerAI_Spells[3] = Holy Light
    • Set ComputerAI_Spells[4] = Resurrection
    • -------- ------------------------------ --------
    • Set ComputerAI_Spells[5] = Wind Walk
    • Set ComputerAI_Spells[6] = Critical Strike
    • Set ComputerAI_Spells[7] = Mirror Image
    • Set ComputerAI_Spells[8] = Bladestorm
    • -------- ------------------------------ --------
    • Set ComputerAI_Spells[9] = Bash
    • Set ComputerAI_Spells[10] = Thunder Clap
    • Set ComputerAI_Spells[11] = Storm Bolt
    • Set ComputerAI_Spells[12] = Avatar
    • -------- ------------------------------ --------
    • Set ComputerAI_Spells[13] = Shockwave
    • Set ComputerAI_Spells[14] = Endurance Aura
    • Set ComputerAI_Spells[15] = War Stomp
    • Set ComputerAI_Spells[16] = Reincarnation
    • -------- ------------------------------ --------
    • Set ComputerAI_SpellsPerHero = 4
after that, i realised i dont really have a way to find out what spells for what hero..
so i tried setting this:

  • Then - Actions
    • -------- ------------------------------ --------
    • Unit - Create 1 ComputerAI_HeroList[ComputerAI_Index[4]] for (Player(ComputerAI_Index[2])) at ((Player(ComputerAI_Index[2])) start location) facing Default building facing degrees
    • Set ComputerAI_UsedHero[ComputerAI_Index[3]] = (Last created unit)
    • -------- ------------------------------ --------
    • Set ComputerAI_HeroIndex[ComputerAI_Index[3]] = ComputerAI_Index[4]
    • Set Player_HeroIndex[(Player number of (Owner of ComputerAI_UsedHero[ComputerAI_Index[2]]))] = ComputerAI_Index[4]
and it creates the hero (ignore indexes.. they work :P)
ComputerAI_Index[4] = random number between 1 and the herolist count,
so it generates a random hero for each bot.

now i saved it so if i have the player number, i could use it anytime.
and this is my math:
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • ComputerAI_HeroState[ComputerAI_Index[5]] Equal to learn spell
    • Then - Actions
      • Set ComputerAI_LevelCount = Player_HeroLVLCount[(Player number of (Owner of ComputerAI_CurrentHero))]
      • Set ComputerAI_LearnedSpell = ComputerAI_Spells[(ComputerAI_HeroIndex[ComputerAI_Index[5]] x ComputerAI_LevelCount)]
      • Custom script: call UnitAddAbility(udg_ComputerAI_CurrentHero, udg_ComputerAI_LearnedSpell)
  • //Yeah yeah, i realise this will work once.. but aslong as it will work, im happy, and add more stuff, like increase level instead of just adding it..
    • Else - Actions
after a while i realised it aint so smart..
because:
hero #1 * #spell #2 = 1 * 2 = 2, that works.
hero #1 * #anyspellnum works.
hero #2 * #spell #2 = 4. this means it still uses hero #1 spells. which
hero #2 dont posses.

how can i make this work? thx.
 
Are you asking help with the math to find the correct index?

(n - 1) * 4 + x = y

n = index of the hero unit type in the array
x = Between 1 and 4
y = The index of ability to add/learn

For example if you have Mountain King, then n is 3. You want to learn the second ability for him. (3 - 1) * 4 + 2 = 10. And you have Thunder Clap as the second ability, so it works correctly.

You can learn abilities in order, first abil1 to lvl 1, abil 2 to lvl2 and so on. Keep track of the ability to learn with some number. Increase it after each ability learned. If it is #4 then set the number to 1 for the next time.
 
edit:
okay, i managed to combine those 2 triggers i posted before into 1.
heres the code:

  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • (Unspent skill points of ComputerAI_CurrentHero) Greater than or equal to 1
    • Then - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Player_HeroLVLCount[Player_HeroIndex[(Player number of (Owner of ComputerAI_CurrentHero))]] Greater than ComputerAI_SpellsPerHero
        • Then - Actions
          • Set Player_HeroLVLCount[Player_HeroIndex[(Player number of (Owner of ComputerAI_CurrentHero))]] = (Player_HeroLVLCount[Player_HeroIndex[(Player number of (Owner of ComputerAI_CurrentHero))]] + 1)
        • Else - Actions
          • Set Player_HeroLVLCount[ComputerAI_Index[(Player number of (Owner of ComputerAI_CurrentHero))]] = 1
      • -------- ----------------------- --------
      • Set ComputerAI_LevelCount = Player_HeroLVLCount[ComputerAI_Index[5]]
      • Set ComputerAI_LearnedSpell = ComputerAI_Spells[(((ComputerAI_HeroIndex[ComputerAI_Index[5]] - 1) x 4) + ComputerAI_LevelCount)]
      • -------- ----------------------- --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Level of ComputerAI_LearnedSpell for ComputerAI_CurrentHero) Less than 3
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Level of ComputerAI_LearnedSpell for ComputerAI_CurrentHero) Less than or equal to 0
            • Then - Actions
              • Unit - Add ComputerAI_LearnedSpell to ComputerAI_CurrentHero
            • Else - Actions
              • Unit - Increase level of ComputerAI_LearnedSpell for ComputerAI_CurrentHero
          • Hero - Modify unspent skill points of ComputerAI_CurrentHero: Subtract 1 points
        • Else - Actions
    • Else - Actions
the problem:
it keeps reapting number 1, in this:
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • Player_HeroLVLCount[Player_HeroIndex[(Player number of (Owner of ComputerAI_CurrentHero))]] Greater than ComputerAI_SpellsPerHero
    • Then - Actions
      • Set Player_HeroLVLCount[Player_HeroIndex[(Player number of (Owner of ComputerAI_CurrentHero))]] = (Player_HeroLVLCount[Player_HeroIndex[(Player number of (Owner of ComputerAI_CurrentHero))]] + 1)
    • Else - Actions
      • Set Player_HeroLVLCount[ComputerAI_Index[(Player number of (Owner of ComputerAI_CurrentHero))]] = 1
for example, when i putted game - display text on the ELSE actions, it allways repeated it, and never stopped.
when i putted it in the THEN, it never showed up.

EDIT: found out the bug =]
i made it check if its GREATER then max spell count, instead of less then =]
it works now, you can close this, thanks for the formula maker :D
 
Last edited:
Status
Not open for further replies.
Back
Top