User:Nexii Malthus/Object-based health
< User:Nexii Malthus
Jump to navigation
Jump to search
Revision as of 10:44, 6 August 2024 by Nexii Malthus (talk | contribs)
This is pretty much as simple as it gets. No damage adjustment, just processing final damage. We initialise with a set amount of health which other scripts can read via llGetHealth. The presence of the final_damage event marks this as a DAMAGEABLE object for sensors and collisions.
For object-based health the script needs to manually manage it's own health, applying the final damage to the health amount and setting the objects health.
default
{
state_entry()
{
llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_HEALTH, 300.0]);
}
final_damage(integer count)
{
float health = llGetHealth(llGetKey());
while(count --> 0)
{
list damage = llDetectedDamage(count);
float amount = llList2Float(damage, 0);
health -= amount;
}
if(health < 0) health = 0;
else if(health > 300.0) health = 300.0;
llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_HEALTH, health]);
if(health == 0) state dead;
}
}
state dead
{
state_entry()
{
// We are dead, jim
}
}