This is all preliminary and it works great for a nice simple system. I've tried to comment it out reasonably well.
I'm sure it's not the most efficient coding so please feel free to update it as you like, that's why I'm posting it here instead of the Library - I'm sure it needs "smoothing out".
----------- Object worn on Avatar ---------------
(Usually an invisible prim attached to mouth/skull/nose/what have you)
CODE
/////////////// Simple Combat Display and HUD - Uniform Mass Collision v1.1 \\\\\\\\\\\\\\\\\\\\\\\\\\\\
//////////////////////////////// by: Haplo Voss
// If you do actually use this as a model, by all means have at it. I'd appreciate it if you would
// leave my name in the credits above, and anyone else who might add / change this as it moves along
//
// This is a very simple system and does not attemp to dilineate where an impact occurred. I have
// left plenty of moddable variables to add any sort of chat based weapon-specific report you want
// still leaving it open to any impact at all if you so choose. Why? NO MODDED WEAPONS NEEDED :)
key gID;
string owner;
// Setup the meters. Probably a better way to do this.
string display_E = "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||";
string display_AS = display_E;
string display_ARM = display_E;
string display_E_S = " ";
string display_AS_S = display_E_S;
string display_ARM_S = display_E_S;
// These are the meter descriptors
string display_e;
string display_as;
string display_arm;
string class = "Warrior"; //(Generic - rename accordingly)
// This block contains your starting points for calculation maths. Do not change from 80.
// If you know a way to update to make all variables work that's great, this script as it sits... doesn't
integer health = 80;
integer endurance = 80;
integer armor = 80;
//These are your damage scale variables. You will define them below.
integer he_damage;
integer en_damage;
integer ar_damage;
//Display Text Color variables
float r = 0; float g = 1; float b = 1;
//////////////////////////////////////////////////////////////////////////////////////
armor_calc(integer damage)
{
if (damage > ar_damage)
{
health = (health - he_damage);
armor = (armor - ar_damage);
}
else if (damage < (ar_damage + 1))
{
armor = 0;
health = (health - (he_damage + 8));
endurance = (endurance - en_damage);
r = 1; g = 0; b = 0;
}
}
health_calc(integer damage)
{
if (health < 1)
{
health = 0;
armor = 0;
endurance = (endurance - (en_damage + 6));
}
}
endurance_calc(integer damage)
{
if (endurance < 1)
{
endurance = 0;
process_text(0);
llSay(0, "You are DEAD!!!");
llRequestPermissions(llGetOwner(),PERMISSION_TRIGGER_ANIMATION);
llStartAnimation("driver3");
llSleep(5);
llStopAnimation("driver3");
health = 80;
endurance = 80;
armor = 80;
display_e = display_E;
display_as = display_AS;
display_arm = display_ARM;
r = 0; g = 1; b = 1;
}
}
process_text(integer none)
{
display_e = "";
display_as = "";
display_arm = "";
display_e = llGetSubString(display_E,0,health/2) + llGetSubString(display_E_S,0,(40 - (health/2)));
display_as = llGetSubString(display_AS,0,endurance/2)+ llGetSubString(display_AS_S,0,(40 - (endurance/2)));
display_arm = llGetSubString(display_ARM,0,armor/2) + llGetSubString(display_ARM_S,0,(40 - (armor/2)));
llSetText(owner + " - " + class + "\n" +
"[ " + display_e + " ] : Health :\n" +
"[ " + display_as + " ] : Stamina :\n" +
"[ " + display_arm + " ] : Armor :",<r,g,b>,1);
}
health_level(string weapon)
{
armor_calc(armor);
health_calc(health);
endurance_calc(endurance);
process_text(0);
}
recharge()
{
if ((health + 2) < 80){health += 3;}
if ((endurance + 3) < 80){endurance += 4;}
if ((armor + 2) < 80){armor += 2;}
process_text(0);
}
default
{
state_entry()
{
llRequestPermissions(llGetOwner(),PERMISSION_TRIGGER_ANIMATION);
gID = llGetOwner();
owner = llKey2Name(gID);
llSetText("",<1,1,1>,1);
process_text(0);
llSetTimerEvent(4); // (Time it takes for each incriment towards recharge.
llListen (9919,"","","");
}
listen (integer channel, string name, key id, string msg)
{
// This is an example of a specific weapon definition
if (msg == "blaster")
{
he_damage = 3;
en_damage = 2;
ar_damage = 8;
health_level(msg); //Use this to pass information to the sub if you want
//Even more options within the call.
}
else if (msg != "") // This would be your standard undefined weapon "hit"
{
he_damage = 3;
en_damage = 2;
ar_damage = 5;
health_level(msg);
}
}
timer ()
{
if (armor > 40){r=.5; g=1; b=1;}
if (armor > 40){r=.1; g=1; b=1;}
recharge();
}
}
-------------- Object attached to HUD -----------
(This registers avatar collisions and feeds them to the display object)
CODE
integer energon;
integer damage;
integer status;
key gID;
key avID;
vector Gpos;
rotation Lrot;
default
{
state_entry()
{
//llSetText("",<0,0,0>,1);
gID = llGetOwner();
avID = llDetectedKey(0);
Gpos = llGetPos();
Lrot = llGetLocalRot();
llSay(0, "Hello, Avatar!");
}
collision (integer detected)
{
if ( (llDetectedType(0) & SCRIPTED) && (llDetectedVel(0) != <0,0,0>) && (llGetOwnerKey(llDetectedKey(0)) != llGetOwner()) )
{
llOwnerSay(llDetectedName(0) + " Agh!"); //Just for general debugging. Let's you know when the HUD
// *Actually* registers a hit.
llSay(9919,"blaster");
}
}
}
So as you can see, you can alter the HUD attachment to discern incoming weapons as well if you were to have the "bullet" say its name on collision or something similar - if you wanted to use a weapon - specific system.
Take care everyone and thank you again for all of the help and support I always receive in here.
It's not the most efficient code I know, but as I said, please feel free to update / alter it and post your results. I would be interested to see and especially learn from them.
- Haplo