Aller au contenu

Photo

Make Your Own AI!


  • Veuillez vous connecter pour répondre
11 réponses à ce sujet

#1
The Fred

The Fred
  • Members
  • 2 516 messages
I know a lot of people moan about the terrible AI of the game, and as I was reading one of those threads on it I had an idea. Specifically, Arkalzeth was saying he wanted a Warlock/Barbarian to do very specific things instead of spamming essence-less blasts, so I thought up a system which would let you do that.

Basically, this system lets you attach HotU-style AI scripts to your party members. You need to write the script and put the compiled version in your /override folder along with the system itself, and at the moment it's still kinda basic, but for things like making a character always buff or whatever it should (touch wood, so to speak) work just fine. Since it was suggested I start a thread for it, I have (this is it, obviously).

You can get the system here, on the Vault where it is explained in a bit more detail, but since I was asked, here are a few points about it.

When does this custom script run?
It is run by the combat round script, so it ought to fire about once every round, so long as the character is in combat.

Is this compatible with other stuff?
This should be compatible with anything which doesn't change the Character Screen, which this uses, so it is NOT directly compatible with TonyK's AI (though I plan to release a compatible version at some point). However, as _MAU_ pointed out, you can run the script "gui_fredai_change" from the console to use this system even with things like TonyK's.

How does this play with Puppet Mode?
As far as I know, this won't even run in puppet mode, which is probably what most people usually want. However, you can assign a script which will put your characters into what's effectively a puppet mode anyway, if you want, yet still letting it do stuff which you do want them to do.

So, any other questions, ask away. FAQs I'll put up here. Hopefully, some people might find this useful.

Modifié par The Fred, 16 décembre 2010 - 12:51 .


#2
The Fred

The Fred
  • Members
  • 2 516 messages

Vaalyah wrote...
In the explanatory part at the vault, you say the script does nothing on its own, since it needs an AI script. But then you say the script sets priorities so that NPCs can heal or follow the leader. So... does this script do something or not? I'm confused.

This is a pretty basic system; all it does is hook into what's already coded. So, there's a hierachy of what happens in each companion's AI. Normally, it goes something like this:
Do very basic companion-specific stuff, like healing and following the boss.
Run normal combat round (all enemies go from here).
Check first for a HotU override script (companions are unlikely to have these).
- If found, run it, and abort if it says to abort
- Otherwise, continue with the normal combat round
Do stuff like attacking, casting spells etc as normal.

What I do is change the HotU bit to run my own script. This will then in turn run any script you chose to attach, and only then drop through to any HotU script which may already have been attached by the module builder (so it should be compatible even if mod-builders use this system already). Then, it will drop through to normal AI. Admittedly, this may not be the best way of doing things, but it's one of the simplest and most reliable I could think of.

Modifié par The Fred, 16 décembre 2010 - 12:48 .


#3
Vaalyah

Vaalyah
  • Members
  • 953 messages
Ah, now I've fully understood! Thank you for your kind explanation! :-)

#4
manageri

manageri
  • Members
  • 394 messages
So the script assigned by this thing is run by the "hench_o0_ai" script? If so, wouldn't moving that part of the script to take place before the puppet mode check at the start make this work with puppet mode on? Am I even looking at the right script (I really don't know crap about the AI)?

#5
The Fred

The Fred
  • Members
  • 2 516 messages
OK, here goes. According to the toolset, your companions run "gb_comp_combat" at the end of each combat round.

This then checks for Puppet Mode (and so would be the thing to change) and runs HenchmanCombatRound() from "x0_inc_henai".

HenchmanCombatRound() does a few henchman-/companion-specific things, then it calls the DetermineCombatRound() function which all creatures run.

IIRC, *this* then checks for a HotU override script. However, what actually gets run is *my* script, "fredai".

"fredai" then runs whatever script you told the system to run - this is your custom override AI script. If this doesn't call for the AI to stop (by using SetCreatureOverrideAIScriptFinished() to tell the system that you've already given the character instructions) it runs any script which *was* the HotU override AI script as specified by the modul builder (if the module builder used this system already for this companion).

This script then runs like it always should have, and if *this one* doesn't tell the AI to stop, it drops all the way back to DetermineCombatRound(), which makes the character do default stuff.

Of course, non of this ever happens if you are controlling the character, or that character is not in combat.

Hope that helps ;-)

Modifié par The Fred, 17 décembre 2010 - 05:43 .


#6
manageri

manageri
  • Members
  • 394 messages
Thanks, looks like I'll need to mess with at least 3 different scripts since there's puppet mode checks all over.

#7
manageri

manageri
  • Members
  • 394 messages
Alright, after removing the puppet mode check in "gb_comp_combat" and
moving the HotU ai code in "hench_o0_ai" to before that script's puppet
check, I got the custom ai running with puppet mode. The problem now
is, the change in "gb_comp_combat" somehow causes characters to stop
attacking at the end of the round if they're in puppet mode whether they
have a custom AI script assigned or not. I tried queueing up like 10
potions and switching control and those commands were all followed so
it's only stopping attack, not clearing all actions. Here's what it
looks like now:

void main()
{
     HenchResetCombatRound();

if (/*!GetAssociateState(NW_ASC_MODE_PUPPET) &&*/     //<------------- commented out puppet check
      !GetHasPlayerQueuedAction(OBJECT_SELF) &&
      !GetSpawnInCondition(NW_FLAG_SET_WARNINGS) &&   
      !HenchCheckEventClearAllActions(TRUE))
    {
        HenchDetermineCombatRound();
    }
    if(GetSpawnInCondition(NW_FLAG_END_COMBAT_ROUND_EVENT))
    {
        SignalEvent(OBJECT_SELF, EventUserDefined(EVENT_END_COMBAT_ROUND));
    }
}


Any ideas what could be causing it?

#8
The Fred

The Fred
  • Members
  • 2 516 messages
Hmm, I'm not sure. It's possible the script just isn't fired in Pupper Mode, or there's another check for it somewhere.

#9
manageri

manageri
  • Members
  • 394 messages
Thanks again, everything seems to work almost perfectly now. I'll post the scripts after some testing for people who might be interested.

#10
The Fred

The Fred
  • Members
  • 2 516 messages
That's cool. I have a couple of ideas about things which could be added to this, so I might cook up an update sometime if I get chance.

#11
manageri

manageri
  • Members
  • 394 messages
Uploaded to the vault now: http://nwvault.ign.c...s.Detail&id=354

#12
The Fred

The Fred
  • Members
  • 2 516 messages
OK, I've just uploaded a version which ought to be compatible with TonyK's, version 2.2. Sorry it's a little late, but it should work fine now.