Health scripts: Difference between revisions

From Spring
Jump to navigationJump to search
AnimDef health check code exemple
 
Maddox (talk | contribs)
m another formatting fix
 
(7 intermediate revisions by 4 users not shown)
Line 1: Line 1:
==know the health of the unit in AnimDef==
==Get the health of the unit in AnimDef==




*read the "damage" full health in UnitDef data:
*read the "damage" full health in UnitDef data:
<code>local maxhealth</code>
<nowiki>
local maxhealth
local percenthealth,health,maxHealth,paralyzeDamage,captureProgress,buildProgress


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


percenthealth=(health/maxHealth)*100
</nowiki>


*get the % actual of full health:
<code>local health</code>


<code>health=GetUnitValue(4)</code>--HEALTH 4  // get (0-100%)--
*print all the data in the chat box and infolog for control :
<nowiki>
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)
</nowiki>
**note the buildprogress and captureprogress values are in the range 0 to 1 (1 = complete)


*avoid to control health before unit was fully built :
<code>local builtremain</code>


<code>builtremain=Spring.UnitScript.GetUnitValue(17)</code>''--BUILD_PERCENT_LEFT 17// self built % remain 100to0%''
 
 
*[[SpringRtsTutorialAnimDef]] return to the list of animDef exemples
 
 
[[Category:Emmanuel]]

Latest revision as of 19:25, 21 September 2017

Get 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 values are in the range 0 to 1 (1 = complete)