Health scripts: Difference between revisions

From Spring
Jump to navigationJump to search
Knorke (talk | contribs)
m need clarification & exemples
Line 23: Line 23:
dont use the stupid GetUnitValue with stilly number parameter, Spring.GetUnitHealth can get builtremain and percents too, look it up at [[Lua_SyncedRead#Unit_Informations]]
dont use the stupid GetUnitValue with stilly number parameter, Spring.GetUnitHealth can get builtremain and percents too, look it up at [[Lua_SyncedRead#Unit_Informations]]
Using numbers is evil TA style!
Using numbers is evil TA style!
Spring.GetUnitHealth
( number unitID ) -> nil | number health, number maxHealth, number paralyzeDamage,
                            number captureProgress, number buildProgress
*synthax : <code>health,maxHealth,paralyzeDamage,captureProgress,buildProgress=Spring.GetUnitHealth(unitID)</code> isnt?
:or so:
:<code>Spring.GetUnitHealth(health,unitID)</code>
:<code>Spring.GetUnitHealth(buildProgress,unitID)</code> ?

Revision as of 16:57, 13 November 2012

know the health of the unit in AnimDef

  • read the "damage" full health in UnitDef data:

local maxhealth

maxhealth=Spring.GetUnitHealth(unitID)


  • get the % actual of full health:

local health

health=GetUnitValue(4)--HEALTH 4 // get (0-100%)--


  • avoid to control health before unit was fully built :

local builtremain

builtremain=Spring.UnitScript.GetUnitValue(17)--BUILD_PERCENT_LEFT 17// self built % remain 100to0%

--- knorke says:
dont use the stupid GetUnitValue with stilly number parameter, Spring.GetUnitHealth can get builtremain and percents too, look it up at Lua_SyncedRead#Unit_Informations Using numbers is evil TA style! Spring.GetUnitHealth

( number unitID ) -> nil | number health, number maxHealth, number paralyzeDamage,
                           number captureProgress, number buildProgress
  • synthax : health,maxHealth,paralyzeDamage,captureProgress,buildProgress=Spring.GetUnitHealth(unitID) isnt?
or so:
Spring.GetUnitHealth(health,unitID)
Spring.GetUnitHealth(buildProgress,unitID) ?