Page 1 of 1

Simpe Mana system (gadget inside)

Posted: 03 Nov 2011, 22:15
by knorke
Mana for all units! But only one mana at a time.
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:
Image
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,},
and then use
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
example 2
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)
So yeah, not that groundbreaking but maybe usefull to have some "easy gadget example."
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.

Re: Simpe Mana system (gadget inside)

Posted: 03 Nov 2011, 22:59
by jK
you should use Spring.[Set|Get]UnitRulesParam instead of GG.GetMana

Re: Simpe Mana system (gadget inside)

Posted: 03 Nov 2011, 23:03
by knorke
yes, i wanted to eventually change it like that.

Re: Simpe Mana system (gadget inside)

Posted: 03 Nov 2011, 23:07
by smoth
jK wrote:you should use Spring.[Set|Get]UnitRulesParam instead of GG.GetMana
why?

Re: Simpe Mana system (gadget inside)

Posted: 04 Nov 2011, 00:22
by jK
Cause it is the engine interface to save per unit/team/game vars.
Any code (LuaUI, LuaRules, ...) will be read the values w/o any proprietary interfaces.

Re: Simpe Mana system (gadget inside)

Posted: 04 Nov 2011, 01:36
by smoth
so it is accessible by all? as in other players can see my mana?

Re: Simpe Mana system (gadget inside)

Posted: 04 Nov 2011, 01:39
by knorke

Re: Simpe Mana system (gadget inside)

Posted: 04 Nov 2011, 03:47
by Google_Frog
Did you consider a GG.AdjustMana that returns whether the mana was adjusted? In your example the unit checks if it has enough mana to perform an action then performs the action and subtracts the mana.

Instead a single function could test if mana can be subtracted and subtract it at the same time. For example here is a simpler weapon that requires mana.

Code: Select all

function script.BlockShot()
  return not GG.AdjustMana(unitID, -1.5)
end

Re: Simpe Mana system (gadget inside)

Posted: 04 Nov 2011, 04:06
by knorke
Did you consider a GG.AdjustMana that returns whether the mana was adjusted?
yes, but it is the simple mana system.
One could also add more parameters to AdjustMana like make it possible to change recharge, maximum and whatnot.
Those who understand return not GG.AdjustMana(unitID, -1.5) will not need this anyway ;)

Re: Simpe Mana system (gadget inside)

Posted: 04 Nov 2011, 04:34
by MidKnight
@Google: That impairs readability and introduces a whole bunch of icky cases. What if I want negative mana?
Also, if we're adding return values to functions, wouldn't it make sense to have adjustMana return the adjusted value if successful?