Health scripts: Difference between revisions

From Spring
Jump to navigationJump to search
Flozi (talk | contribs)
Line 5: Line 5:
<code>local maxhealth</code>
<code>local maxhealth</code>


<code>maxhealth=Spring.GetUnitHealth(unitID)</code>
<code>
local percenthealth,health,maxHealth,paralyzeDamage,captureProgress,buildProgress


health,maxHealth,paralyzeDamage,captureProgress,buildProgress=Spring.GetUnitHealth(unitID)


*get the % actual of full health:
percenthealth=(health/maxHealth)*100
<code>local health</code>
</code>


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


*print all the data in the chat box and infolog for control :
<code>


*avoid to control health before unit was fully built :
Spring.Echo("health="..health,"maxHealth="..maxHealth,"paralyzeDamage="..paralyzeDamage,"captureProgress="..captureProgress,"buildProgress="..buildProgress,"percenthealth="..percenthealth.." %")
<code>local builtremain</code>


<code>builtremain=Spring.UnitScript.GetUnitValue(17)</code>''--BUILD_PERCENT_LEFT 17// self built % remain 100to0%''
--health=19921.25390625,maxHealth=20000,paralyzeDamage=0,captureProgress=0,buildProgress=1,percenthealth=99.606269836426 %
(unitID)</code>
**note the buildprogress and captureprogress are in range from 0 to 1 (1 = complete)


---
'''knorke says:'''<br />
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 : <code>health,maxHealth,paralyzeDamage,captureProgress,buildProgress=Spring.GetUnitHealth(unitID)</code> isnt? -- '''THIS ONE CORRECT'''


:then why this code output the maxhealth and not the health ?? : <code>maxhealth=Spring.GetUnitHealth(unitID)</code>
 
*[[SpringRtsTutorialAnimDef]] return to the list of animDef exemples
 


[[Category:Emmanuel]]
[[Category:Emmanuel]]

Revision as of 15:26, 18 March 2013

know the health of the unit in AnimDef

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

local maxhealth

local percenthealth,health,maxHealth,paralyzeDamage,captureProgress,buildProgress

health,maxHealth,paralyzeDamage,captureProgress,buildProgress=Spring.GetUnitHealth(unitID)

percenthealth=(health/maxHealth)*100


  • print all the data in the chat box and infolog for control :

Spring.Echo("health="..health,"maxHealth="..maxHealth,"paralyzeDamage="..paralyzeDamage,"captureProgress="..captureProgress,"buildProgress="..buildProgress,"percenthealth="..percenthealth.." %")

--health=19921.25390625,maxHealth=20000,paralyzeDamage=0,captureProgress=0,buildProgress=1,percenthealth=99.606269836426 % (unitID)

    • note the buildprogress and captureprogress are in range from 0 to 1 (1 = complete)