MegaGlest Forum

Modding and game content creation => Maps, tilesets and scenarios => Topic started by: esraacs on 19 June 2015, 00:04:21

Title: lua scripting attack for specific units
Post by: esraacs on 19 June 2015, 00:04:21
by using lua scripting how can i give attack command to specific units like defense tower and air ballista ?
I tried this
createUnit('defense_tower', 0, startLocation(0))      
givePositionCommand(lastCreatedUnit(), 'attack',startLocation(0))
createUnit('air_ballista', 0, startLocation(0))      
givePositionCommand(lastCreatedUnit(), 'attack',startLocation(0))

and this
createUnit('defense_tower', 0, startLocation(0))      
givePositionCommand(lastCreatedUnit(), 'attack_on',startLocation(0))
createUnit('air_ballista', 0, startLocation(0))      
givePositionCommand(lastCreatedUnit(), 'attack_on',startLocation(0))

it gives that invalid command in both cases
how can give attack command to these units using lua scripting ?
Title: Re: lua scripting attack for specific units
Post by: Omega on 19 June 2015, 04:58:47
If you consult the XMLs, you'll find that the defense tower does not have an attack command. It has an attack skill and an attack_stopped command (which is usually referred to as "hold position" for regular units). The major difference is that you cannot pick the target of the defense tower (and other units using this pattern). The reason for this is that attack commands require a move skill and for obvious reasons, it doesn't make sense to have buildings move.

It's been too long since I experimented with that, but IIRC, there's no way to give a  move skill that will not have the building at least rotate, and thus there's no way to give the defense tower a way to choose its target without engine modifications (but again, it's been a long time and maybe someone else has found a way to make that work). All the same, it won't work with the Megapack.

You can tell the defense tower to use its attack stopped command ("attack on") with giveAttackStoppedCommand (https://docs.megaglest.org/MG/Lua#giveAttackStoppedCommand.28unitID.2C_valueName.2C_ignoreRequirements.29).