/////////////////////////////////////////////////////////////////////////// // Copyright (C) Wizardry and Steamworks 2011 - License: GNU GPLv3 // // Please see: http://www.gnu.org/licenses/gpl.html for legal details, // // rights of fair usage, the disclaimer and warranty conditions. // /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// // CONFIGURATION // /////////////////////////////////////////////////////////////////////////// // Set this to the total health. The maximum point- // blank cannon shot will deal 30 damage which will be // deduced from the total health. integer HEALTH = 100; /////////////////////////////////////////////////////////////////////////// // INTERNALS // /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// // Copyright (C) 2013 Wizardry and Steamworks - License: GNU GPLv3 // /////////////////////////////////////////////////////////////////////////// string wasProgress(integer percent, integer length, list symbols) { percent /= (integer)((float)100.0/(length)); string p = llList2String(symbols,0); integer itra = 0; do { if(itra>percent-1) p += llList2String(symbols,2); else p += llList2String(symbols,1); } while(++itra<length); return p + llList2String(symbols,3); } /////////////////////////////////////////////////////////////////////////// // Copyright (C) 2013 Wizardry and Steamworks - License: GNU GPLv3 // /////////////////////////////////////////////////////////////////////////// vector wasPercentToGradient(float percent, string rgb) { if(llStringLength(rgb) != 2) { llSay(DEBUG_CHANNEL, "Assert failed, rgb parameter must consist of a pair of either r, g, or b."); return ZERO_VECTOR; } string a = llGetSubString(rgb, 0, 0); string b = llGetSubString(rgb, 1, 1); list col = [ "r", "g", "b" ]; integer ax = llListFindList(col, (list)a); integer bx = llListFindList(col, (list)b); if(ax == -1 || bx == -1) { llSay(DEBUG_CHANNEL, "Asset failed, rgb parameters must contain either r, g, or b letters."); return ZERO_VECTOR; } col = llListReplaceList(col, (list)((100-percent)/100), ax, ax); col = llListReplaceList(col, (list)(percent/100), bx, bx); return 2*<llList2Float(col, 0), llList2Float(col, 1), llList2Float(col, 2)>; } float h; default { state_entry() { h = HEALTH; llSetText("Health: " + wasProgress((integer)(h/HEALTH*100), 10, ["[", "█", "░", "]"]), wasPercentToGradient((integer)(h/HEALTH*100), "rg"), 1); } collision_start(integer num) { h -= llVecMag(llDetectedVel(0)); llSetText("Health: " + wasProgress((integer)(h/HEALTH*100), 10, ["[", "█", "░", "]"]), wasPercentToGradient((integer)(h/HEALTH*100), "rg"), 1); if(h <= 0) state dead; } } state dead { state_entry() { llSetText("☠", <1,0,0>, 1); llSetTimerEvent(1); } timer() { llDie(); } }