Difference between revisions of "User:Nexii Malthus/Object-based health"
Jump to navigation
Jump to search
m |
|||
Line 1: | Line 1: | ||
[[Category:LSL Combat2|Combat2]] | [[Category:LSL Combat2|Combat2]] | ||
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. | 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. | 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. |
Revision as of 10:46, 6 August 2024
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
}
}