Skip to content
User Avatar
#3749
Auto-translated
Azgalor
Hello! So, I've started working on the combat script again. I want to create two battles with two heroes, but I'm already struggling with how to optimize it. The thing is, I don't have a clear idea yet of these heroes being real "bosses" that the player only attacks. For now, they're more like regular bots with large armies, roaming around and consuming everything on the map. I want it so that when my hero attacks them, or they attack my hero, it triggers the combat script. Right now, I'm just thinking of writing the entire combat twice, once for when the player attacks and once for when they defend, but maybe there's a way to simplify this so that the game only needs to track who attacked whom once, and then use that hero's variable in all functions (like UnitCastGlobalSpell)?
The best optimization option is to only implement the scenario where you attack. How you do it is up to you. Overall, I haven't worked with this myself, but if you attach a trigger to your hero that activates on contact, you can "disable" the standard attack and, using this trigger, activate the interaction and MakeHeroInterractWithObject (or something like that), essentially making your hero attack the enemy. Then you'll only need one script.
I might be wrong about disabling the standard attack, but you can experiment with SetObjectEnabled and so on. There are many workarounds you can come up with. For example, you could create a loop that checks the distance between your heroes, and if the distance is 2 tiles, your hero will attack the enemy using this script... (but I wouldn't recommend this option :))


Не уходи безропотно во тьму,
Будь яростней пред ночью всех ночей,
Не дай погаснуть свету своему!

Хоть мудрый знает – не осилишь тьму
Во мгле словами не зажжёшь лучей –
Не уходи безропотно во тьму.