SmartAI templates

Sorry if this is already a feature and I’m just being stupid (often the case)…

SmartAI is brilliant and flexible, but I feel its flexibility would be greatly enhanced by allowing templates to be built. At present, any creature we wish to add smartAI to requires its own unique entries in the database. If two creatures have the exact same behaviours, they require their own unique smartAI entries. Rather than having to add the same smartAI to a dozen creatures (and bloating the database), wouldn’t it be nicer to declare one set of behaviours, name them as a template, and then use that name in the ‘scripts’ entry. Essentially, this would empower smartAI with the potential to be applied like any hard-coded script.

Forgive me if this is not a valid suggestion or if it shouldn’t be made here. It’s not a Blizzlike feature (or maybe that is how they do certain things), but since it’s a behind-the-scenes feature it could be very useful.

Thanks

Scy

SAI has exactly what you suggest: https://trinitycore.atlassian.net/wiki/display/tc/smart_scripts#smart_scripts-PredefinedSAItemplates

Thanks for the reply. I’m obviously missing something here. How are these predefined templates added to an npc other than by invoking SmartAI? Is it possible to add custom templates? What I’m thinking is something like this:

I want all wolves to have a common behavior (e.g. cast some sort of howl spell before entering combat and occasionally do a special bite or something). I thus want to be able to make a SmartAI template for this called ‘WolfAI’ and then be able to apply it to any wolves I want by setting Scripts to ‘WolfAI’. Is this somehow already achievable?

Does anyone have a link then to a guide for these templates? The document referenced by Nay lists everything very nicely, but doesn’t do much to explain their usage. I’ve looked for one, of course, but no joy.

The templates are added to the creature with SMART_ACTION_INSTALL_AI_TEMPLATE (1 action vs N).

More templates can be added by changing the switch at https://github.com/TrinityCore/TrinityCore/blob/6.x/src/server/game/AI/SmartScripts/SmartScript.cpp#L2403 (which is a terrible way to do it).

These templates aren’t used that much (or at all), they are not as useful as you think.

Ah, thanks very much for that clarification. And yes, it is a terrible way to do it. With modification, I suppose, it could be what I want, but it’s clumsy as hell. I think I’ll see if I can tinker with the code myself. Maybe add a new DB table, ‘AI_Templates’ with columns ID and Name. Then set SmartAI to work off a negative ID… kind of the way loot refs, etc, are done. E.g. Put the word ‘WolfAI’ in a creature’s scripts field and the AI_templates table is referenced to find a template ID, then that is referenced to a set of SmartAI behaviours…