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

AI on attack do it once!

Discussion in 'Triggers & Scripts' started by CaptainHero, Nov 14, 2014.

  1. CaptainHero

    CaptainHero

    Joined:
    Sep 30, 2012
    Messages:
    197
    Resources:
    1
    Spells:
    1
    Resources:
    1
    So yeah i am trying to make the AI use my custom buff spells.
    already mentioned it here a bit: http://www.hiveworkshop.com/forums/triggers-scripts-269/trigger-computer-autocast-259235/
    The problem I'm now facing, at least it seems that way is:
    The AI is going ape shit, when a couple of potential good looking, with mana, casters and valid targets are in range, they spam the spell, well not even.. overwrite everything from start over and over again.. Probably the event "A unit is attacked" happens quite often when the AI is determined to attack your sorry ass.

    Anyway that's my theory. Might just be i made a mistake in the code.

    Trigger Is Attaked
    • AIA
      • Events
        • Unit - A unit Is attacked
      • Conditions
        • (Unit-type of (Attacking unit)) Equal to Guardian
        • ((Owner of (Attacking unit)) controller) Equal to Computer
      • Actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (Load 0 of (Key (Owner of (Attacking unit))) from AI) Equal to False
          • Then - Actions
            • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • (Unit-type of (Attacking unit)) Equal to Guardian
              • Then - Actions
                • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                  • If - Conditions
                    • (Mana of (Attacking unit)) Greater than or equal to 140.00
                  • Then - Actions
                    • Set AI_Unit1 = (Attacking unit)
                    • Set AI_Duration1 = 0.58
                    • Game - Display to (All players) the text: go
                    • Trigger - Run AIE <gen> (checking conditions)
                  • Else - Actions
              • Else - Actions
          • Else - Actions


    Trigger AIE
    • AIE
      • Events
      • Conditions
      • Actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • AI_Integer[1] Equal to 0
          • Then - Actions
            • Trigger - Turn on DCAIE <gen>
          • Else - Actions
        • Game - Display to (All players) the text: (String(AI_Integer[2]))
        • Set AI_Integer[2] = (AI_Integer[2] + 1)
        • Set AI_UnitA1[AI_Integer[2]] = AI_Unit1
        • Set AI_Deadboolean[AI_Integer[2]] = False
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (AI_UnitA1[AI_Integer[2]] is in AI_Group) Equal to True
          • Then - Actions
            • Set AI_Integer[2] = (AI_Integer[2] - 1)
          • Else - Actions
            • Set AI_Integer[1] = (AI_Integer[1] + 1)
            • Unit Group - Add AI_UnitA1[AI_Integer[2]] to AI_Group
            • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • (Load 0 of (Key (Owner of AI_UnitA1[2])) from AI) Equal to False
              • Then - Actions
                • Hashtable - Save True as 0 of (Key (Owner of AI_UnitA1[AI_Integer[2]])) in AI
                • Game - Display to (All players) the text: (String(AI_Integer[2]))
                • Game - Display to (All players) the text: start
                • Set AI_Player[AI_Integer[2]] = (Owner of AI_UnitA1[AI_Integer[2]])
                • Set AI_Duration2[AI_Integer[2]] = AI_Duration1
                • Set AI_Point[AI_Integer[2]] = (Position of AI_UnitA1[AI_Integer[2]])
                • Set AI_GroupA[AI_Integer[2]] = (Units within 700.00 of AI_Point[AI_Integer[2]])
                • Unit Group - Pick every unit in AI_GroupA[AI_Integer[2]] and do (Actions)
                  • Loop - Actions
                    • Game - Display to (All players) the text: (Name of (Picked unit))
                    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                      • If - Conditions
                        • And - All (Conditions) are true
                          • Conditions
                            • ((Picked unit) is in AI_GroupB) Equal to False
                            • ((Picked unit) has buff Bloodlust) Equal to False
                            • ((Picked unit) is alive) Equal to True
                            • ((Picked unit) is A structure) Equal to False
                            • ((Picked unit) is Mechanical) Equal to False
                            • ((Picked unit) is Magic Immune) Equal to False
                            • ((Picked unit) is A sapper) Equal to False
                            • ((Picked unit) is hidden) Equal to False
                            • (Percentage life of (Picked unit)) Less than 100.00
                      • Then - Actions
                        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                          • If - Conditions
                            • Or - Any (Conditions) are true
                              • Conditions
                                • ((Picked unit) belongs to an ally of AI_Player[AI_Integer[2]]) Equal to True
                                • (Owner of (Picked unit)) Equal to AI_Player[AI_Integer[2]]
                          • Then - Actions
                            • Unit Group - Add (Picked unit) to AI_GroupT[AI_Integer[2]]
                          • Else - Actions
                      • Else - Actions
                • Set AI_UnitR1[AI_Integer[2]] = (Random unit from AI_GroupT[AI_Integer[2]])
                • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                  • If - Conditions
                    • (Number of units in AI_GroupT[AI_Integer[2]]) Greater than 0
                  • Then - Actions
                    • Unit Group - Add AI_UnitR1[AI_Integer[2]] to AI_GroupB
                    • Unit - Order AI_UnitA1[AI_Integer[2]] to Human Paladin - Holy Light AI_UnitR1[AI_Integer[2]]
                  • Else - Actions
                • Game - Display to (All players) the text: Target
                • Game - Display to (All players) the text: (Name of AI_UnitR1[AI_Integer[2]])
                • Unit Group - Remove all units from AI_GroupA[AI_Integer[2]]
                • Unit Group - Remove all units from AI_GroupT[AI_Integer[2]]
              • Else - Actions


    Trigger DCAIE
    • DCAIE
      • Events
        • Time - Every (1.00 / 32.00) seconds of game time
      • Conditions
      • Actions
        • For each (Integer AI_Integer[3]) from 1 to AI_Integer[2], do (Actions)
          • Loop - Actions
            • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • AI_Deadboolean[AI_Integer[3]] Equal to False
              • Then - Actions
                • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                  • If - Conditions
                    • AI_curDuration[AI_Integer[3]] Greater than 0.05
                    • AI_curDuration[AI_Integer[3]] Less than or equal to 0.08
                  • Then - Actions
                    • Unit Group - Remove AI_UnitR1[AI_Integer[3]] from AI_GroupB
                    • Hashtable - Save False as 0 of (Key (Owner of AI_UnitA1[AI_Integer[3]])) in AI
                    • Set AI_curDuration[AI_Integer[3]] = (AI_curDuration[AI_Integer[3]] + (1.00 / 32.00))
                  • Else - Actions
                    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                      • If - Conditions
                        • AI_curDuration[AI_Integer[3]] Greater than or equal to AI_Duration2[AI_Integer[3]]
                      • Then - Actions
                        • Unit Group - Remove AI_UnitA1[AI_Integer[3]] from AI_Group
                        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                          • If - Conditions
                            • (AI_UnitR1[AI_Integer[3]] is in AI_GroupB) Equal to True
                          • Then - Actions
                            • Unit - Order AI_UnitA1[AI_Integer[3]] to Stop
                          • Else - Actions
                        • Set AI_curDuration[AI_Integer[3]] = 0.00
                        • Set AI_Integer[1] = (AI_Integer[1] - 1)
                        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                          • If - Conditions
                            • AI_Integer[1] Equal to 0
                          • Then - Actions
                            • Set AI_Integer[2] = 0
                            • Trigger - Turn off (This trigger)
                          • Else - Actions
                      • Else - Actions
                        • Set AI_curDuration[AI_Integer[3]] = (AI_curDuration[AI_Integer[3]] + (1.00 / 32.00))
              • Else - Actions


    The thing i want to achieve with the triggers is to make every ai player slow the f*** down, and cast the spell max every 0,03 sec, or with no parallels spells running, since i could imagine that at some points the caster freezes because, the valid target got buffed by someone else beforehand.. or whatever the system also stops working at some point..
    the dummy spell is channel with 0,03 duration, and prevents all other actions, and the base id is holy light or bolt whatever... the actually buff is then cast by a dummy caster, with a bit more stuff happening there but that's all good, casting point of the dummy is 0,000

    Tanks for reading. Here is a potato, well just the written word, so yeah..

    _______________

    oh and i want that the unit really casts the spell, not as a passive
    so the cooldown gets activated and the faerie dragons mana leak works on him..


    XXXXXXXXXXXXXXXXXXXX

    Solved.. the event when a unit finishes casting a spell works a lot better, luckily for me all the casters who cast the custom buffs, can also cast other spells... and this comes very handy since the other approach would force the ai to always cast the custom buff spell, now the buffs comes always second, if at all..
    / obviously check if the finished spell is your custom buff, in that case dont start a endless loop, well until your caster wasted all his precious mana.

    note there are also some code errors above
     
    Last edited: Nov 16, 2014