iirc there is no callin that tells you when a unit has finished doing a command.
There is UnitCmdDone()
I've coded the logic of this one to happen in the AllowCommand callin, but it seems odd to me that the effect should be there too -> I just assumed AllowCommand is a "OK, you can do this command, add it to the queue", where the UnitCommand callin would actually execute it.
Maybe it depends on the type of the command. I assume most state-change (e.g. fire/move state) commands would be executed immediately in the AllowCommand and others (attack, patrol, build, cast spell) would be executed somewhere else.
https://springrts.com/wiki/SetMoveTypeDataExample is a state-change command, so AllowCommand seems okay.
On other hand the life-leech gadget seems more like an action similiar to attack, that should not be immediately.
Player can select a target etc, unit probally has to move into range before it can execute the attack, the action should be queue-able and so on.
Imo best handled with CommandFallBack() ,it is documentated in wiki.
Any way is to put the all actual logic (setting unit health/states, moving in range, spawning effects, animations,..) of an action that takes a while to complete into GameFrame() and CommandFallBack() merely returns "finished=true" once the action is complete.
Also how does one control the following:
- range (if unit, area or a position is a target)
- cooldown
- facing (whether or not a unit needs to face the target)
It comes down to question: "How can a command be blocked based on a condition?"
The life-leech gadget already does some check:
Code: Select all
if not Spring.ValidUnitID(targetUnitID) or Spring.GetUnitIsDead(targetUnitID) then return false end
So the action is already limited to target only not-dead units.
Limiting by range or cooldown works no different, so just add more conditions in similiar way
Code: Select all
if (distance (unit, target) > 400) then ...
if getUnitMana (unit) < 20 then ...
- ^ how these two can be dynamically changed (by putting the command on/off cooldown or extending/shortening range, if possible)
In above conditions replace the numbers constants with values read from UnitRulesParam(unitID) or some table or whatever.
Code: Select all
if (distance (unit, target) > spGetUnitRulesParam(unitID, "lifeLeechRange"))then ...
To change button descriptions or disabling buttons: EditUnitCmdDesc()
extensibility with lups or ceg
"Extensibility" seems like bit strange word: Such things become clear when writing a gadget.
If the gadget makes a unit lose/gain health with SetUnitHealth() then author naturally understands where to call SpawnCEG("blood-splatter") to make the blood-splatter-effect (or whatever) appear at good moment.