|
So i'm trying to make an AI, who owns only one unit which is a ghost in this example. The ghost has standard abilities; Snipe and EMP. So I want the ghost to walk around and find an enemy. Once it has acquired an enemy if that unit has mana then I want the ghost to EMP once, then spend the rest of it's energy on snipe. If the enemy does not have energy just spend all energy on snipe. If the enemy has no energy nor is biological then the ghost shouldn't do anything but auto attack.
This is what i have so far:
Events Timer - Every 1.0 seconds of Game Time Local Variables ClosestUnit = No Game Link <Game Link - Unit> Conditions Actions Unit Group - Pick each unit in (Ghost units in (Entire map) owned by player Any Player matching Excluded: Missile, Dead, Hidden, with at most Any Amount) and do (Actions) Actions General - If (Conditions) then do (Actions) else do (Actions) If (Controller of player (Owner of (Picked unit))) == Computer Then Variable - Set ClosestUnit = (Unit type of (Closest unit to (Position of (Picked unit)) in (Any units in (Entire map) owned by player Any Player matching Excluded: Self, Ally, Robotic, Structure, Missile, Uncommandable, Stasis, Under Construction, Dead, Hidden, Summoned, with at most UI - Display (Name of ClosestUnit) for (All players) to Subtitle area UI - Display (Text((Owner of (Picked unit)))) for (All players) to Subtitle area General - If (Conditions) then do (Actions) else do (Actions) If Or Conditions ClosestUnit == Ghost ClosestUnit == High Templar ClosestUnit == Raven ClosestUnit == Sentry ClosestUnit == Infestor (Spellcaster) Then UI - Display (Name of ClosestUnit) for (All players) to Subtitle area Unit - Order (Picked unit) to (Ghost - EMP Round targeting (Position of (Closest unit to (Position of (Picked unit)) in (Any units in (Entire map) owned by player Any Player matching Excluded: Self, Ally, Structure, Missile, Uncommandable, Stasis, Dead, Hidden, Summoned, with at most (Replace Existing Orders) Else Unit - Order (Closest unit to (Position of (Picked unit)) in (Any units in (Entire map) owned by player Any Player matching Excluded: Self, Ally, Structure, Missile, Uncommandable, Stasis, Dead, Hidden, Summoned, with at most Any Amount)) to (Ghost - Sniper Round targeting (Closest unit to (Position of (Picked unit)) in (Any units in (Entire map) owned by player Any Player matching Excluded: Self, Structure, Missile, Uncommandable, Stasis, Under Construction, Dead, Hidden, Summoned, with at m (Replace Existing Orders)
I know it looks like a giant wall of text but most of it is just nonesense. The problem is that every time i try to find the closest unit it returns itself, which makes sense because the closest unit to the point of the position of your unit is your unit. But what doesn't make sense is when i says Excluding self in the unit filter it still returns itself. This problem persists with my Attack trigger also(which i didn't post). In my attack trigger i try to find the closest hostile unit to attack but it ends up A-attacking its own position even though I excluded self. I don't know why, please help!
|
"Self" doesn't do anything in triggers because there is no scope that you can throw into the function. So, you may ignore a few fields in the filter. I'm not entirely sure which work and which won't, but I only trust the ones that only rely on the found unit and no other info.
a few further comments:
1. Save the Ghost unit in a global variable. Global variables are added where the triggers are and can be used everywhere then. 2. You should save the received unit group in a variable. 3. Filter the units in the unit group for alliance. There are functions that give you all or at least some of the required functionality. 4. Avoid using the whole map when you try to find units. It depends how you want it to do, but a circular area around the ghost should be enough, I don't know how it is implemented, but I imagine having 5k units on the map might make this cost quite a lot performance compared to a smaller area.
|
Instead of "any units in (entire) map", you can and should use a better unit group. If you look at the list you can quite easily see there's many useful options to filter the type of unit you want, such as "units in region with alliance to player" You'd want to set it to enemy of owner of the ghost unit.
|
Well for one thing this shouldn't even be done in a trigger; you should be using an threaded action definition or mostly likely 2 (all ai or multitasking require this to work properly). You then should be running a while loop check if the unit is alive. If there's only one unit then you should not be using a picked each unit loop but rather a global variable as suggested or better a parameter depending on how the unit is selected/built (a parameter will also solve a lot of your issues too).
You need to be more specific in what you want; for example do you just want the unit the move around randomly and then just engage any enemies that come into range or do you want to you specifically target a unit even if its not insight and engage it as long as its alive? The other issue you'll run into with your trigger in its current state is if the unit commits to an attack or not such as it switching targets when it shouldn't be. You should also be able to check the energy on the target unit and not have the mulitple conditions for all the different unit types.
Your debugging text is returning your unit because thats half of what you've asked it to do, but thats not necessarily means your unit is doing something wrong.
No worries around the wall of text; im an advanced trigger from mapster and understand it perfectly although there is a function in the editor that should also you to include the correct formating too.
|
I just want the unit to search around the map for a hostile unit and attack it, its an arena-based map so probably would want to prioritize the unit with the lowest health but thats not nessesary. Right now i have it so it attacks the closest unit.
I'm a newbie programmer and i've never done functions nor even ever heard of threading. Perhaps you can explain a little or if its too complicated direct me to a guide or something, i would greatly appreciate it!
|
Yup sounds like your very very new but this is something you'll definitely need to know as you should actually be using as little triggers as possible. First there's two things function definitions and action definitions. You'll most likely only need action definitions for this part but functions are the same just with the ability to return information. Action definition are just added to a trigger just like any other regular action but they have to be create beforehand; they are basically just another trigger like thread without an event. Now the main thing is that unlike triggers, actions definitions can be multi-threaded (there is a checkbox inside the action to enable this); now it is this threading that not only allows the set of actions to act independently to any other set of actions but also allows it work at its own pace/time thus helping a lot of time with lagg. To compare the different, doing it in trigger the ai would have to move, stop moving, shoot, resume move, etc. Now you can see where this would be an issue in things like stutter step micro because you issue a lot of orders with a lot of waits; definitions on the other hand would allow you to have one whole mechanic for moving and another whole different one for shooting so the units would stead shoot and move at the same time simultaneously with the two threads working together. Granted you may not need this specific mechanic but the concept still applies.
Actions definitions use parameters to grab the information from the trigger they are in and use it within the set of actions within the definition. Like in a trigger you make need to use the triggering unit however since you do not have an event in a definition you use a parameter (kinda of like a variable); within the action defintion create a parameter like unit and then within the trigger with the definition you include the triggering unit within the action to specify that the parameter refers to.
Now the only other things you will have to get to know real well is loops such as "for each integer", "while", "repeat", etc.
Right now your going to have a lot of lag as with your periodic triggers what if you actions can't complete within the time of the next periodic event. Actions defintion will run without holding up anything and will run a whole lot smoother and faster. I hope this helps.
|
You should take a screenshot and post that instead; it's much easier to read with proper syntax.
|
|
|
|