Has anyone had any luck with a threat/aggro system at all?
I have been trying to develop something with little luck so far. What I've been aiming to achieve is a trigger that makes units always attack the unit that has done the most damage to it.
I know there were one or two custom scripts used to achieve it in Wc3 but I wondered if anyone had had any more success in the new editor?
I don't have the editor opened at the moment, but could it be possible to change a unit's "Attack target priority" via triggers? A higher number there means enemies attack that unit. I have this on a couple units in my game.
Has anyone had any luck with a threat/aggro system at all?
I have been trying to develop something with little luck so far. What I've been aiming to achieve is a trigger that makes units always attack the unit that has done the most damage to it. I know there were one or two custom scripts used to achieve it in Wc3 but I wondered if anyone had had any more success in the new editor?
i can do this seems simple enough, ill make something and get back to you.
Why not just issue an attack order on the unit with the highest threat? Counting the threat itself is just numbers so that shouldn't be a problem.
Counting the threat is ok but distinguishing where the threat came from is the part I am struggling with. You can make a trigger for "Unit is damaged" and then save "triggering damage amount" as a local or global variable. But distinguishing between the sources of the damage and then issuing an attack order for the highest source is the difficult part.
If anyone has any ideas they would be much appreciated!
Well you need a threat table for each unit that can have threat, and using the custom values of units seems like the simplest way to do this. If there's a limited number of units that can cause threat, just make a global array of those units and then set the enemy's custom value of the corresponding index to indicate how much threat it has. Or instead of a global array, you can store the index of each player unit to one of that unit's custom values.
For example, if you have 5 players which each have 5 units, the array would have indexes 0-4 for the units of the first player, 5-9 for the units of the second player, 10-14 for the third, 15-19 for the fourth and 20-24 for the fifth. When one of those units cause threat to an enemy, set that enemy's custom value X to the amount of threat caused by unit X (where X is that unit's index in that array). Each time an enemy takes damage, go through the enemy's custom values and find the highest one. Then make the enemy attack the unit of the corresponding index.
To give you more of an idea of what I am hoping to do: I am aiming for a wc3 warchasers style map with 4 players and only one unit each. The map would then be filled with NPC controlled units.
I would like to be able to have groups of NPC units that work with their own individual threat system. Correct me if I am wrong but I think you're suggestion would mean the player's units having one value for threat at any time.
Example: Player 1 unit attacks NPC X and builds 100 threat then attacks NPC Y and builds 100 threat. Overall threat is now 200 and attacking X represtents 200 threat on X.
I had hoped to make it possible for player to attack more than one NPC unit and have individual threat for each. Or maybe this is hoping too much?
No, you would have the thread stored in the NPC units per player, not in the player units. For example:
When player 1 builds 100 threat on NPC unit A, you add 100 to unit A's custom value 1. When player 2 builds 100 threat on NPC unit A, you add 100 to unit A's custom value 2. Same for 3 and 4. Then when they attack unit B, you add the threat to unit B's custom values 1, 2, 3 or 4 depending on which player attacked it. The point is to store each player's threat separately to the NPC unit they built it on.
And each time a unit gets added threat, you go through that unit's threat table (custom values 1, 2, 3, and 4), check which is highest, and order to attack that player. For example if NPC unit A has 100 threat in custom value 1, 105 threat in custom value 2, 0 threat in custom value 3 and 50 threat in custom value 4, you go through the values and notice that 105 is the highest, and order the unit to attack player 2.
If you want to avoid "threat bouncing", you check if 105 is let's say 10% higher than the threat of the unit it is currently attacking. For example if the unit was attacking player 1 who has 100 threat, and then player 2 builds 105 threat on the NPC, you check if 105 is higher than 100*10% = 110, and it's not, so don't switch target yet. But when player 2 reaches 111 threat, it becomes higher than 100*10% (assuming player 1 still has only 100 threat on the unit) and the unit switches its target to player 2.
Has anyone had any luck with a threat/aggro system at all?
I have been trying to develop something with little luck so far. What I've been aiming to achieve is a trigger that makes units always attack the unit that has done the most damage to it. I know there were one or two custom scripts used to achieve it in Wc3 but I wondered if anyone had had any more success in the new editor?
@Tbome: Go
I don't have the editor opened at the moment, but could it be possible to change a unit's "Attack target priority" via triggers? A higher number there means enemies attack that unit. I have this on a couple units in my game.
Why not just issue an attack order on the unit with the highest threat? Counting the threat itself is just numbers so that shouldn't be a problem.
i can do this seems simple enough, ill make something and get back to you.
Counting the threat is ok but distinguishing where the threat came from is the part I am struggling with. You can make a trigger for "Unit is damaged" and then save "triggering damage amount" as a local or global variable. But distinguishing between the sources of the damage and then issuing an attack order for the highest source is the difficult part.
If anyone has any ideas they would be much appreciated!
Well you need a threat table for each unit that can have threat, and using the custom values of units seems like the simplest way to do this. If there's a limited number of units that can cause threat, just make a global array of those units and then set the enemy's custom value of the corresponding index to indicate how much threat it has. Or instead of a global array, you can store the index of each player unit to one of that unit's custom values.
For example, if you have 5 players which each have 5 units, the array would have indexes 0-4 for the units of the first player, 5-9 for the units of the second player, 10-14 for the third, 15-19 for the fourth and 20-24 for the fifth. When one of those units cause threat to an enemy, set that enemy's custom value X to the amount of threat caused by unit X (where X is that unit's index in that array). Each time an enemy takes damage, go through the enemy's custom values and find the highest one. Then make the enemy attack the unit of the corresponding index.
Thanks for your continued help!
To give you more of an idea of what I am hoping to do: I am aiming for a wc3 warchasers style map with 4 players and only one unit each. The map would then be filled with NPC controlled units.
I would like to be able to have groups of NPC units that work with their own individual threat system. Correct me if I am wrong but I think you're suggestion would mean the player's units having one value for threat at any time.
Example: Player 1 unit attacks NPC X and builds 100 threat then attacks NPC Y and builds 100 threat. Overall threat is now 200 and attacking X represtents 200 threat on X.
I had hoped to make it possible for player to attack more than one NPC unit and have individual threat for each. Or maybe this is hoping too much?
No, you would have the thread stored in the NPC units per player, not in the player units. For example:
When player 1 builds 100 threat on NPC unit A, you add 100 to unit A's custom value 1. When player 2 builds 100 threat on NPC unit A, you add 100 to unit A's custom value 2. Same for 3 and 4. Then when they attack unit B, you add the threat to unit B's custom values 1, 2, 3 or 4 depending on which player attacked it. The point is to store each player's threat separately to the NPC unit they built it on.
And each time a unit gets added threat, you go through that unit's threat table (custom values 1, 2, 3, and 4), check which is highest, and order to attack that player. For example if NPC unit A has 100 threat in custom value 1, 105 threat in custom value 2, 0 threat in custom value 3 and 50 threat in custom value 4, you go through the values and notice that 105 is the highest, and order the unit to attack player 2.
If you want to avoid "threat bouncing", you check if 105 is let's say 10% higher than the threat of the unit it is currently attacking. For example if the unit was attacking player 1 who has 100 threat, and then player 2 builds 105 threat on the NPC, you check if 105 is higher than 100*10% = 110, and it's not, so don't switch target yet. But when player 2 reaches 111 threat, it becomes higher than 100*10% (assuming player 1 still has only 100 threat on the unit) and the unit switches its target to player 2.