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!
Is there a way to make it so that a computer controlled unit will automatically dodge other units? I'm trying to add AI to an RKR map but I've tried a lot of different things and non of which have worked.
I don't know about actual AI scripts, I've not used them much in the past, but maybe you can try using triggers - a unit comes with x range of it, order it to walk in the opposite direction.
These functions control AI behavior (they don't apply to the object editor - they are functions called in your AI in real-time).
SetGroupsFlee() tells the AI to flee battle when either the captain's group health (i.e. average health among the entire captain's group) is low or if they are much weaker than the force they are facing, or they are losing the battle.
SetHeroesFlee() and SetUnitsFlee() tell the hero/unit to flee when its health gets low or they can't attack. It also seems to affect moving out of harm's way in battle in my observations.
If you don't use these functions (i.e. set them to false), your AI will be rather suicidal. It's better to asses the situation in your code and turn these on/off as needed or leave them ON/TRUE if you don't want to write that much code.
"Can they be combined with some JASS to make this AI ?"
You can use jass or vJass to write your AI files. I found the AI editor had some issues in the code it generated so I've been using jass for my AI for over a year (and vJass in the last 6 months). The AI editor also limits what you can accomplish with the AI (eg. such as fixing the Random Hero bug, relative costs bug, etc).
You can use pretty much any functions in the common.ai file. However, you can't use trigger code nor any enum functions (group/unit etc).
EDIT: As a footnote, these function won't accomplish what it sounds like you are trying to do. It sounds like you want them to move to a target instead of attack move.
You mean the "Dodge AI" the OP was asking about? I'm not sure I understand exactly what you want to accomplish. Do you want them to move to a target instead of attack move? Or do you never want them to engage in battle and always avoid enemy units? Not sure exactly what you want to do.
In either case, this is probably easier to accomplish with triggers as Element of Water pointed out earlier. It's best to combine your AI files within the limits of its capabilities, then use triggers to add the more intricate stuff.
EDIT: If you want to make an AI file, look at the AI files that come with the game to give you an idea of how things need to be laid out (and the threads you need to create). Then download jasshelper and use the command line version to compile and error-check your AI files. I have mine laid out rather different but that is because it is written in vjass and resolves a number of bugs.
Well, I tried long ago but there are some functions I wasn't able to understand.
There are function that you can understand what they do just by they name, like AddAssult function but also there are many more I couldn't understand what they do. Are there some tutorials around explaing what do each function do ?
You could use something like call SetPlayerAlliance(ai_player, Player(PlayerNum_WhoYouWantToTreatAsPassive), ALLIANCE_PASSIVE, false)
I don't know of any tutorials. I just read through everything in common.ai, and tested many of the functions through trial and error (to see what they do). From common.ai you can follow the code and see what it does, and what the natives do by the way they are called and under what circumstances. You can also write your own functions to replace the ones in common.ai (as I did to suit what I wanted to accomplish and to overcome some AI bugs).
I wouldn't edit the actual common.ai file. I just rewrote some functions (such as PlayGame(), StartExpansion() and StartUpgrade() etc and renamed them to xStartExpansion() etc) and put them into my own xCommon.ai and !import it at the top of my ai file. If you're not using vJass, then just write the functions at the top of your ai file.
I find it easier to use vJass and use one import file. For example, I'll write my ai files separated into related sections. This way I can just write a race specific file for each race without having to copy over all the other common function.
----
ImportAi.j
//! import "xCommon.ai"
//! import "UtilFunctions.ai"
//! import "Attacks.ai"
//! import "Units.ai"
//! import "Heroes.ai"
//! import "human.ai" (or whatever race you are working on)
----
Then I can work with separate files. Once I've written all the common non race specific ai stuff, I can then just work on each race specific ai file using the common functions.
How can I add my own functions, it will be nothing more than mere words since the functions added by blizzard works by calling the codes from the WC engine by using the appropriate function. Do I miss something ?
I don't know how can I explain this to you. OK, I'll give you an example:
JASS:
native CreateUnit takes player id,integer unitid,real x,real y,real face returns unit
When you call this function it calls a C or C++ code ,or whatever language blizzard used, in the game engine to create the unit you want according to the argument the function takes. So creating your own function will not call the appropriate code from the engine unless you change the game engine itself. To make things more clearly, the way a patch work, in the older version before the patch 1.17 if you try to use function from a newer patch it will give you errors even if you replaced the common.ai and common.j and all this files by any MPQ application by the new files of the patch it will not work because those functions cant find the codes it calls from the engine. I hope you understand what I mean.
I'm not talking about rewriting natives. You can't edit the low-level code. And also, that is why I said not to change the common.ai file itself, but rather you can rewrite the non-native functions in it and create your OWN xCommon.ai to resolve some of the Blizzard bugs (such as relative costs, Random Hero, etc). You CAN write your OWN non-native functions found in common.ai and call those functions instead of the non-native functions in common.ai.
For example, you can write your own build loop to replace the one in common.ai to get around the relative costs bug (which is what I did).
And the example function you provided is from common.j (which you wouldn't want to replace anyway). Typically in a standard AI file you wouldn't want to use CreateUnit() anyway. It sort of defeats the purpose of creating a build order using the AI functions ( and you would have to do a lot of unnecessary coding to deduct resource costs and unit positioning etc).
You will have to excuse me if I told you I am not completely understanding. Can you show me an example of what you did; it could explain to me what you mean.
To avoid posting hundreds of lines of code, I'll give you a small example of how I replaced the common.ai build loop to use my own.
These functions are the same as those found in common.ai, but with an 'x' in front of their name. The functions they call are my own to resolve the aforementioned bugs and provide additional functionality not provided in common.ai
To replace the main build loop, you could put this code at the top of your ai file (below your globals and structs).
You can then write your own xOneBuildLoop() function.
You will then need to change your main function to call your own build loop instead of the one in common.ai like this
JASS:
//===========================================================================
// Main startup function
//===========================================================================
function main takes nothing returns nothing
// Initialize Blizzard AI
//
call InitAI()
call SetMeleeAI()
call SetHeroLevels(function SelectHeroAbility)
call Sleep(0.1)
call StartThread(function UpdateLoop)
call StartThread(function MainBuildLoop)
call StartThread(function MainAttackLoop)
call xPlayGame()
endfunction
But if you are just starting out, you should probably just stick to writing your own basic ai files before you get into writing your own code to replace some of the code in common.ai. Worry about fixing the Blizzard bugs later when you are more familiar with how the AI works and its limits within the AI file environment.
Edit: Note that you are more limited in AI files. For example, the I2S() function does not work in the AI file environment and thus you need to write your own. You can't use any enum functions or triggers either. So you have to compensate for this in other ways.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.