Basically if there is anything to do with a unit that recharges/is limited to be done only X times/uses up power it can be done with this, instead of writing similiar code everything.
It is called "mana" but to the player it can be displayed as "Magic", "Stamina" or something else.
omg a picture:

The battery level of the Electro Tank is low and the Bomb Segway has 2 more bombs left to place.
Simply look at the top of the gadget and add your own units like:
Code: Select all
[UnitDefNames["magicman"].id] = {recharge=2, maxMana=40,startMana=10, manaName="Magic Power", manaSymbol="|", showManaNumber=true, showInToolTip=true,},
GG.GetMana (unitID)
and
GG.AdjustMana (unitID, difference)
to do whatever you want ie
-energy weapons that must recharge
-weapons that overheat
-limit mine layers in how many mines they can place (ala starcraft vultures)
-other specials that you want to be limited, ie "teleport", "time limited cloak", "time limited quaddamage" etc
example 1
The electro tank has a battery that is drained when it zaps your nuts.
If the battery is empty, it stops zapping. The battery slow recharges.
Code: Select all
function script.AimWeapon( heading, pitch )
--enough battery power to shot?
if (GG.GetMana (unitID) >= 2) then
return true
else
return false
end
end
function script.FireWeapon()
--use up battery power. (recharging is done by gadget)
GG.AdjustMana (unitID, -1.5)
end
The bomb segway can place bombs via a special command, but only 3 bombs at once. Over time it slowly gets new bombs.
(recharge=0 for hard limit)
Code: Select all
function gadget:AllowCommand(unitID, unitDefID, teamID, cmdID, cmdParams, cmdOptions)
if mineLayerNames[unitDefID] then
if (cmdID == CMD_LAY_MINE) then
--is there a bomb that can be placed?
if (GG.GetMana (unitID) >= 1) then
--place the bomb
--...blablabla...
--use up one bomb:
GG.AdjustMana (unitID, -1)
Atm it abuses the unit tooltip to draw a manabar but that is more a test/debug thing. Instead add to healthbars widget or make the unit do funny animations based on mana etc.