Skip to content

Wizard Doesn't Do Tactics

Dragonfolk2000Dragonfolk2000 Member Posts: 390
edited October 13 in Builders - Scripting
I've got a wererat with levels in wizard. The desired tactic is to cast all two defensive spells (Shield and Endure Elements), cast offensive spells on the nearest PC, then run into melee to fight. They're a wererat so their DR helps a bit with that last part. But what they end up doing is casting Daze and then running into combat. I can't figure out how to change or alter the existing behavior to do what I'm trying to do. I think it's in the OnSpawn script but I'm having trouble understanding how to make it do what I want it to. Does anybody know?

Comments

  • ForSeriousForSerious Member Posts: 471
    It might not be what you want, but the closest I got was the insta-buff on spawn flag:
    SetSpawnInCondition(NW_FLAG_FAST_BUFF_ENEMY);

    The last time I looked into modifying the combat AI, I was amazed at how convoluted it is. I still want to figure it out, but it keeps getting pushed back.
  • TerrorbleTerrorble Member Posts: 183
    edited October 16
    So, the NPC (wererat wizard) is casting the defensive spells on the PC?
    And the PC is a friendly target?

    Edit: sorry, I just reread what you posted and understand.

    I'll try to post later how I get NPCs to (usually) do certain things.
    Post edited by Terrorble on
  • Dragonfolk2000Dragonfolk2000 Member Posts: 390
    edited October 17
    ForSerious wrote: »
    It might not be what you want, but the closest I got was the insta-buff on spawn flag:
    SetSpawnInCondition(NW_FLAG_FAST_BUFF_ENEMY);

    The last time I looked into modifying the combat AI, I was amazed at how convoluted it is. I still want to figure it out, but it keeps getting pushed back.

    I can work with this but it seems only some spells are triggering. Shield doesn't activate but Endure Elements does.

    Update: Many spells that would be considered buff spells aren't cast ahead of time. Sure. Okay. Someone should make a list of everything that gets cast through that spawn flag.
    Post edited by Dragonfolk2000 on
  • ForSeriousForSerious Member Posts: 471
    Haha, probably. We could also dig a bunch and find where the buff spells are defined and override it.
  • ForSeriousForSerious Member Posts: 471
    Found it!
    x0_i0_talent
    line 1695. It starts listing what spells it will cast. SPELL_SHIELD is not one of the if cases.
    The if cases are setup so that only the best version of the spell is cast.
  • TerrorbleTerrorble Member Posts: 183
    edited October 17
    I've tried to force some custom creature AI behavior in certain situations with some success (and lots of confusing failures). I've toyed around with a couple ways and will share what I remember.


    In nw_c2_default9 I do:
        if( GetLocalInt(OBJECT_SELF,"ECRE") == 1 )
        {
            SetSpawnInCondition(NW_FLAG_END_COMBAT_ROUND_EVENT);
        }
    

    If I want the creature to do something special at the end of a combat round, I set ECRE|Int|1 in their variables list in the palette.

    If I want them to add an action to cast shield and endure elements, then in x2_def_userdef I do:
        else if(nUser == EVENT_END_COMBAT_ROUND) // END OF COMBAT
        {
            if( GetLocalInt(OBJECT_SELF,"ECRE") == 1 )
            {
                if( GetTag(OBJECT_SELF) == "wereratwiz" )
                {
                    if( !GetHasSpellEffect(SPELL_SHIELD,OBJECT_SELF) && GetHasSpell(SPELL_SHIELD,OBJECT_SELF) ) ActionCastSpellAtObject(SPELL_SHIELD,OBJECT_SELF);
                    else
                    if( !GetHasSpellEffect(SPELL_ENDURE_ELEMENTS,OBJECT_SELF) && GetHasSpell(SPELL_ENDURE_ELEMENTS,OBJECT_SELF) ) ActionCastSpellAtObject(SPELL_ENDURE_ELEMENTS,OBJECT_SELF);
                    else    DeleteLocalInt(OBJECT_SELF,"ECRE");  //Get rid of the variable so we don't waste time checking anymore
                }
            }
    
        }
    

    Since this is adding actions to the creature's action queue, it can work, but depending on what is happening to the creature, not all the time. Meaning, the default ai will clear all their actions to do some other action in some cases, or sometimes they never stop attacking to do any other action in their queue. If that's the case, try throwing a ClearAllActions(); before adding the actions and see what you get.

    It's been quite a while since I've worked on this, but I think what I found is that the best stuff to put in the ECRE section is code to identify when you want your creature to do something specific. Then create a custom ai script that runs for the creature at that point.
    For example:
    if( conditions_under_which_I'd_like_this_creature_to_do_a_thing == TRUE )
    SetCreatureOverrideAIScript(OBJECT_SELF,"ai_custom");

    Model your ai_custom after x2_ai_shadow. I'll share how I think this should look.
        SetCreatureOverrideAIScriptFinished(OBJECT_SELF);
    
    //Every time something happens to the creature, its ai gets called.  To avoid it from interrupting itself, we have this next check.
    if(__InCombatRound())
            return;
    //Ok, whatever we were doing is done, so let's clear any other actions that may or may not be present and do our custom ai.
        ClearAllActions();
    
        object oEnemy = bkAcquireTarget();
        if (GetIsObjectValid(oEnemy))
        {
            //Pretty sure this is what __InCombatRound() checks.  If we set __TurnCombatRoundOn() to TRUE, then we won't interrupt what comes after it.
            __TurnCombatRoundOn(TRUE);
    
            //Determine what action to take.
               //Note: never assign more than one action here at a time.
    
                if( GetTag(OBJECT_SELF) == "wereratwiz" )
                {
                    if( !GetHasSpellEffect(SPELL_SHIELD,OBJECT_SELF) && GetHasSpell(SPELL_SHIELD,OBJECT_SELF) ) ActionCastSpellAtObject(SPELL_SHIELD,OBJECT_SELF);
                    else
                    if( !GetHasSpellEffect(SPELL_ENDURE_ELEMENTS,OBJECT_SELF) && GetHasSpell(SPELL_ENDURE_ELEMENTS,OBJECT_SELF) ) ActionCastSpellAtObject(SPELL_ENDURE_ELEMENTS,OBJECT_SELF);
                    else        
    //It might be appropriate to delete the override ai script from the creature at this point if it's finished all the special behavior and you want it to go back to standard ai. 
        SetCreatureOverrideAIScript(OBJECT_SELF,"");
       //Don't quote me on this working by just setting the script string to blank.  I don't have my mod available to look and see how I actually did it.
                }
    
            //Now that we've added whatever action to do, turn off the combat round - or else maybe the ai breaks.
            __TurnCombatRoundOn(FALSE);
        }
    
Sign In or Register to comment.