Programmer here. Most of my engine-related experience is with Unity, so forgive me if some of my terminology is off.
What I want to do is create a custom ability in the editor, which will trigger code that will...
Get references to both the unit using the ability and the target, and
Execute simple attack roll code using attack and defense variables.
If the attack lands, then cast the attacking unit's regular attack ability on the target (so that the engine will automagically handle damage calculations). If it doesn't land, then cast an alternate ability that just uses the attack animation but otherwise does nothing.
I have very little experience using the Starcraft 2 editor, but at a glance it doesn't look like we can add custom fields/values to units in the data module, so if I wanted to give each unit different attack and defense values, then I would have to declare them separately as variables in the trigger editor / in galaxy script. Am I wrong on this point?
A general rundown / input on how I would accomplish this with the SC2 editor would be greatly appreciated.
What kind of ability are you refering? If it's the "Attack" ability of a unit, then doing this in triggers would definitly cause lag. If it's just an ability that will be used say not more than once or twice per sec max, it could be fine. But all this depends on what is your goal.
What do you mean by attack roll code, is that like heartstone with HP and Attack points?
"If the attack lands" so if the ability hit the target (unit), then the caster will attack the target (once?)
So for what is this going to be used? What should happend other than Unit A cast ability, if it hit Unit B then attack, if not deal no damage? Is the ability you want to create a missile that targets a point on the ground and when it lands it does a search to see if a unit is near-by and does its stuff..?
What kind of ability are you refering? If it's the "Attack" ability of a unit, then doing this in triggers would definitly cause lag. If it's just an ability that will be used say not more than once or twice per sec max, it could be fine. But all this depends on what is your goal.
What do you mean by attack roll code, is that like heartstone with HP and Attack points?
"If the attack lands" so if the ability hit the target (unit), then the caster will attack the target (once?)
So for what is this going to be used? What should happend other than Unit A cast ability, if it hit Unit B then attack, if not deal no damage? Is the ability you want to create a missile that targets a point on the ground and when it lands it does a search to see if a unit is near-by and does its stuff..?
Yeah it would be the attack ability, each unit would call it for each attack, and there would be a lot of units... =[
By attack roll code I meant DnD style attack rolls, where if the attack roll (e.g if(random(1, 20) > defense)) is successful, then it would cast the unit's attack ability on the target, but from what you said I'm guessing this would be too intensive for the game. Thankfully it's not a deal-breaker for the map I had in mind.
Other than cast an ability, the ability would just be dealing damage to the target unit like normal. The idea would be to add a measure of chance to battles so that more units or higher quality units wouldn't necessarily mean winning.
Hummm, so like eatch unit type would have some attack roll probabilities, say between 1 and 20 and a defense roll everytimes it is attacked...
I think it could be done through a couple of effects and short duration behaviors. Not sure exacly how, but I think it could be possible. Having like a % chance of getting x y or z behavior and then have a bunch behavior of comparisons between the caster and the target...
I'm sure someone can come up with a decent solution. It's just too late for me to investigate further tonight. Best luck !
That's what I get for posting before thoroughly researching something. I just looked up a few tutorials on behaviors, and like you said I can probably do this with behaviors and maybe validators(?), I just need to structure it all so that the value of Effect: Chance is based on the attacker's attack attribute and the target's defense attribute, or have it use switch-like behavior and use specific effects for specific enemy targets (e.g orc archers).
Hook a trigger to the appropriate event. There are at least 2 which might or might not be what you want.
You have an ability cast event. Make sure to specify what stage of casting you want to trigger at as otherwise it will trigger multiple times per cast. There is also attacked which fires when a unit is about to use a weapon effect tree against a victim. Both of these allow you to get the origin and target, even various types of target. The events can also be explicitly targeted at certain weapons or abilities for greater efficiency.
Once you have your trigger thread running when you want it to you can apply your attack and defence roll logic as you want. Use an if statement and add your hit condition.
You can use the catalog natives to look up a unit's weapons damage effect or damage effect tree and apply that if desired. You could also trigger the damage entirely by doing external mathematics, eg a JRPG style damage calculation, and the use the deal damage native to deal the damage.
StarCraft II offers you a lot of standard functionality in the form of data. This probably contrasts Unity which encourages you to write your own data processing systems. For optimum productivity using StarCraft II it is recommended to use a mixture of data providing the standard common functionality with triggers complimenting the data to provide any non standard logic. For example, you can hook a trigger to fire when a certain effect fires, and use that trigger to provide complicated mechanics not possible with data alone such as dealing damage based on the square root of current resource count. One could fire this effect using a standard missile effect from a standard unit weapon and the result is a seamless (from the user point of view) unit attack that deals damage based on the square root of resource count.
Hook a trigger to the appropriate event. There are at least 2 which might or might not be what you want.
You have an ability cast event. Make sure to specify what stage of casting you want to trigger at as otherwise it will trigger multiple times per cast. There is also attacked which fires when a unit is about to use a weapon effect tree against a victim. Both of these allow you to get the origin and target, even various types of target. The events can also be explicitly targeted at certain weapons or abilities for greater efficiency.
Once you have your trigger thread running when you want it to you can apply your attack and defence roll logic as you want. Use an if statement and add your hit condition.
You can use the catalog natives to look up a unit's weapons damage effect or damage effect tree and apply that if desired. You could also trigger the damage entirely by doing external mathematics, eg a JRPG style damage calculation, and the use the deal damage native to deal the damage.
StarCraft II offers you a lot of standard functionality in the form of data. This probably contrasts Unity which encourages you to write your own data processing systems. For optimum productivity using StarCraft II it is recommended to use a mixture of data providing the standard common functionality with triggers complimenting the data to provide any non standard logic. For example, you can hook a trigger to fire when a certain effect fires, and use that trigger to provide complicated mechanics not possible with data alone such as dealing damage based on the square root of current resource count. One could fire this effect using a standard missile effect from a standard unit weapon and the result is a seamless (from the user point of view) unit attack that deals damage based on the square root of resource count.
This is incredibly helpful, thank you!
I'm still feeling out what can be done with the data module, but tonight I'll fool around with it and see if I can get the basics implemented.
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
Programmer here. Most of my engine-related experience is with Unity, so forgive me if some of my terminology is off.
What I want to do is create a custom ability in the editor, which will trigger code that will...
I have very little experience using the Starcraft 2 editor, but at a glance it doesn't look like we can add custom fields/values to units in the data module, so if I wanted to give each unit different attack and defense values, then I would have to declare them separately as variables in the trigger editor / in galaxy script. Am I wrong on this point?
A general rundown / input on how I would accomplish this with the SC2 editor would be greatly appreciated.
Alright few questions to start the discussion:
What kind of ability are you refering? If it's the "Attack" ability of a unit, then doing this in triggers would definitly cause lag. If it's just an ability that will be used say not more than once or twice per sec max, it could be fine. But all this depends on what is your goal.
What do you mean by attack roll code, is that like heartstone with HP and Attack points?
"If the attack lands" so if the ability hit the target (unit), then the caster will attack the target (once?)
So for what is this going to be used? What should happend other than Unit A cast ability, if it hit Unit B then attack, if not deal no damage? Is the ability you want to create a missile that targets a point on the ground and when it lands it does a search to see if a unit is near-by and does its stuff..?
Working on projects:
Hummm, so like eatch unit type would have some attack roll probabilities, say between 1 and 20 and a defense roll everytimes it is attacked...
I think it could be done through a couple of effects and short duration behaviors. Not sure exacly how, but I think it could be possible. Having like a % chance of getting x y or z behavior and then have a bunch behavior of comparisons between the caster and the target...
I'm sure someone can come up with a decent solution. It's just too late for me to investigate further tonight. Best luck !
Working on projects:
That's what I get for posting before thoroughly researching something. I just looked up a few tutorials on behaviors, and like you said I can probably do this with behaviors and maybe validators(?), I just need to structure it all so that the value of Effect: Chance is based on the attacker's attack attribute and the target's defense attribute, or have it use switch-like behavior and use specific effects for specific enemy targets (e.g orc archers).
Thanks for your help!
Hook a trigger to the appropriate event. There are at least 2 which might or might not be what you want.
You have an ability cast event. Make sure to specify what stage of casting you want to trigger at as otherwise it will trigger multiple times per cast. There is also attacked which fires when a unit is about to use a weapon effect tree against a victim. Both of these allow you to get the origin and target, even various types of target. The events can also be explicitly targeted at certain weapons or abilities for greater efficiency.
Once you have your trigger thread running when you want it to you can apply your attack and defence roll logic as you want. Use an if statement and add your hit condition.
You can use the catalog natives to look up a unit's weapons damage effect or damage effect tree and apply that if desired. You could also trigger the damage entirely by doing external mathematics, eg a JRPG style damage calculation, and the use the deal damage native to deal the damage.
StarCraft II offers you a lot of standard functionality in the form of data. This probably contrasts Unity which encourages you to write your own data processing systems. For optimum productivity using StarCraft II it is recommended to use a mixture of data providing the standard common functionality with triggers complimenting the data to provide any non standard logic. For example, you can hook a trigger to fire when a certain effect fires, and use that trigger to provide complicated mechanics not possible with data alone such as dealing damage based on the square root of current resource count. One could fire this effect using a standard missile effect from a standard unit weapon and the result is a seamless (from the user point of view) unit attack that deals damage based on the square root of resource count.