Advertisement
itoibo

health object

Jul 3rd, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. integer HEALTH = 200;
  2. // Set this to the total health. The maximum point-
  3. // blank cannon shot will deal 30 damage which will be
  4. // deduced from the total health.
  5.  
  6. //integer statusChan1 = -51069;
  7. integer wallOne;
  8. //integer chanOne = -135790;
  9. integer tChan = -135790;
  10. //integer chanOneTalk = -456987;
  11.  
  12.  
  13.  
  14.  
  15. vector scale;
  16. integer flipSwitch = FALSE;
  17. float delay = 0.2;
  18.  
  19. float age;                                  // Life of each particle
  20. float maxSpeed;                          // Max speed each particle is spit out at
  21. float minSpeed;                           // Min speed each particle is spit out at
  22. string texture;                     // Texture used for particles, default used if blank
  23. float startAlpha;                         // Start alpha (transparency) value
  24. float endAlpha;                           // End alpha (transparency) value
  25. vector startColor;                // Start color of particles <R,G,B>
  26. vector endColor;      // End color of particles <R,G,B> (if interpColor == TRUE)
  27. vector startSize;               // Start size of particles
  28. vector endSize;                       // End size of particles (if interpSize == TRUE)
  29. vector push;                        // Force pushed on particles
  30.  
  31. // System paramaters
  32.  
  33. float rate;                               // How fast (rate) to emit particles
  34. float radius;                             // Radius to emit particles for BURST pattern
  35. integer count;                             // How many particles to emit per BURST
  36. float outerAngle;                         // Outer angle for all ANGLE patterns
  37. float innerAngle;                        // Inner angle for all ANGLE patterns
  38. vector omega;                         // Rotation of ANGLE patterns around the source
  39. float life;                                 // Life in seconds for the system to make particles
  40.  
  41.  
  42. // MASK FLAGS: set  to "TRUE" to enable
  43. integer glow;
  44. integer bounce;                             // Make particles bounce on Z plane of objects
  45. integer interpColor;                         // Color - from start value to end value
  46. integer interpSize;                          // Size - from start value to end value
  47. integer wind;                               // Particles effected by wind
  48. integer followSource;                       // Particles follow the source
  49. integer followVel;                           // Particles turn to velocity direction
  50. // Choose a pattern from the following:
  51. // PSYS_SRC_PATTERN_EXPLODE
  52. //PSYS_SRC_PATTERN_DROP
  53. // PSYS_SRC_PATTERN_ANGLE_CONE_EMPTY
  54. // PSYS_SRC_PATTERN_ANGLE_CONE
  55. // PSYS_SRC_PATTERN_ANGLE
  56. integer pattern;
  57. // = PSYS_SRC_PATTERN_EXPLODE;
  58.  
  59. integer flags;
  60.  
  61. // Select a target for particles to go towards
  62. // "" for no target, "owner" will follow object owner
  63. //    and "self" will target this object
  64. //    or put the key of an object for particles to go to
  65. key target;
  66.  
  67.  
  68.  
  69. // --->> first is a user defined function to create the particle display.  
  70.  
  71. StartSmoke()
  72. {
  73. scale = llGetScale();
  74. age = 15;
  75. maxSpeed = 0.01;
  76. minSpeed = 0.0;
  77. texture = "";
  78. startAlpha = 1.0;
  79. endAlpha = 0.0;
  80. startColor = <1.0,1.0,1.0>;
  81. endColor = <0,0,0>;
  82. startSize = scale/2;
  83. endSize = scale;
  84. push = <0.0,0.0,0.9>;
  85. rate = 0.05;
  86. radius = scale.x/2;
  87. count = 6;
  88. outerAngle = 1.0; // 0.1;
  89. innerAngle = 1.0; //0.65;
  90. omega = <0,0,100.0>;
  91. life = 0;          
  92. //---->>>> This first part is where you make choices in how your particles will appear.
  93. // MASK FLAGS: set  to "TRUE" to enable
  94. glow = TRUE;
  95. bounce = TRUE;
  96. interpColor = TRUE;
  97. interpSize = TRUE;
  98. wind = TRUE;
  99. followSource = FALSE;
  100. followVel = TRUE;
  101. // Choose a pattern from the following:
  102. // PSYS_SRC_PATTERN_EXPLODE
  103. //PSYS_SRC_PATTERN_DROP
  104. // PSYS_SRC_PATTERN_ANGLE_CONE_EMPTY
  105. // PSYS_SRC_PATTERN_ANGLE_CONE
  106. // PSYS_SRC_PATTERN_ANGLE
  107. pattern = PSYS_SRC_PATTERN_EXPLODE;
  108. // Select a target for particles to go towards
  109. // "" for no target, "owner" will follow object owner
  110. //    and "self" will target this object
  111. //    or put the key of an object for particles to go to
  112. key target;
  113.  
  114. //--->> This is the part where your choices are assembled into machine readable code.
  115. //--->> You don't have to change anything from here down.
  116.      
  117.       flags = 0;
  118.     if (target == "owner") target = llGetOwner();
  119.     if (target == "self") target = llGetKey();
  120.     if (glow) flags = flags | PSYS_PART_EMISSIVE_MASK;
  121.     if (bounce) flags = flags | PSYS_PART_BOUNCE_MASK;
  122.     if (interpColor) flags = flags | PSYS_PART_INTERP_COLOR_MASK;
  123.     if (interpSize) flags = flags | PSYS_PART_INTERP_SCALE_MASK;
  124.     if (wind) flags = flags | PSYS_PART_WIND_MASK;
  125.     if (followSource) flags = flags | PSYS_PART_FOLLOW_SRC_MASK;
  126.     if (followVel) flags = flags | PSYS_PART_FOLLOW_VELOCITY_MASK;
  127.     if (target != "") flags = flags | PSYS_PART_TARGET_POS_MASK;
  128.  
  129.     llParticleSystem([  PSYS_PART_MAX_AGE,age,
  130.                         PSYS_PART_FLAGS,flags,
  131.                         PSYS_PART_START_COLOR, startColor,
  132.                         PSYS_PART_END_COLOR, endColor,
  133.                         PSYS_PART_START_SCALE,startSize,
  134.                         PSYS_PART_END_SCALE,endSize,
  135.                         PSYS_SRC_PATTERN, pattern,
  136.                         PSYS_SRC_BURST_RATE,rate,
  137.                         PSYS_SRC_ACCEL, push,
  138.                         PSYS_SRC_BURST_PART_COUNT,count,
  139.                         PSYS_SRC_BURST_RADIUS,radius,
  140.                         PSYS_SRC_BURST_SPEED_MIN,minSpeed,
  141.                         PSYS_SRC_BURST_SPEED_MAX,maxSpeed,
  142.                         PSYS_SRC_TARGET_KEY,target,
  143.                         PSYS_SRC_INNERANGLE,innerAngle,
  144.                         PSYS_SRC_OUTERANGLE,outerAngle,
  145.                         PSYS_SRC_OMEGA, omega,
  146.                         PSYS_SRC_MAX_AGE, life,
  147.                         PSYS_SRC_TEXTURE, texture,
  148.                         PSYS_PART_START_ALPHA, startAlpha,
  149.                         PSYS_PART_END_ALPHA, endAlpha
  150.                             ]);
  151. }
  152.  
  153.  
  154. StartFire()
  155. {
  156. scale = llGetScale();
  157. age = 1.0;
  158. maxSpeed = 0.01;
  159. minSpeed = 3.0;
  160. texture = "";
  161. startAlpha = 0.8;
  162. endAlpha = 0.0;
  163. startColor = <1.0,1.0,0.0>;
  164. endColor = <1,0,0>;
  165. startSize = scale/2;
  166. endSize = scale;
  167. push = <0.0,0.0,15>;
  168. rate = 0.01;
  169. radius = scale.x/2;
  170. count = 2;
  171. outerAngle = 0.1;
  172. innerAngle = 180;//2;
  173. omega = <0,0,0>;
  174. life = 0;          
  175. //---->>>> This first part is where you make choices in how your particles will appear.
  176. // MASK FLAGS: set  to "TRUE" to enable
  177. glow = TRUE;
  178. bounce = TRUE;
  179. interpColor = TRUE;
  180. interpSize = TRUE;
  181. wind = TRUE;
  182. followSource = FALSE;
  183. followVel = TRUE;
  184. // Choose a pattern from the following:
  185. // PSYS_SRC_PATTERN_EXPLODE
  186. //PSYS_SRC_PATTERN_DROP
  187. // PSYS_SRC_PATTERN_ANGLE_CONE_EMPTY
  188. // PSYS_SRC_PATTERN_ANGLE_CONE
  189. // PSYS_SRC_PATTERN_ANGLE
  190. pattern = PSYS_SRC_PATTERN_EXPLODE;
  191. // Select a target for particles to go towards
  192. // "" for no target, "owner" will follow object owner
  193. //    and "self" will target this object
  194. //    or put the key of an object for particles to go to
  195. key target;
  196.  
  197. //--->> This is the part where your choices are assembled into machine readable code.
  198. //--->> You don't have to change anything from here down.
  199.      
  200.       flags = 0;
  201.     if (target == "owner") target = llGetOwner();
  202.     if (target == "self") target = llGetKey();
  203.     if (glow) flags = flags | PSYS_PART_EMISSIVE_MASK;
  204.     if (bounce) flags = flags | PSYS_PART_BOUNCE_MASK;
  205.     if (interpColor) flags = flags | PSYS_PART_INTERP_COLOR_MASK;
  206.     if (interpSize) flags = flags | PSYS_PART_INTERP_SCALE_MASK;
  207.     if (wind) flags = flags | PSYS_PART_WIND_MASK;
  208.     if (followSource) flags = flags | PSYS_PART_FOLLOW_SRC_MASK;
  209.     if (followVel) flags = flags | PSYS_PART_FOLLOW_VELOCITY_MASK;
  210.     if (target != "") flags = flags | PSYS_PART_TARGET_POS_MASK;
  211.  
  212.     llParticleSystem([  PSYS_PART_MAX_AGE,age,
  213.                         PSYS_PART_FLAGS,flags,
  214.                         PSYS_PART_START_COLOR, startColor,
  215.                         PSYS_PART_END_COLOR, endColor,
  216.                         PSYS_PART_START_SCALE,startSize,
  217.                         PSYS_PART_END_SCALE,endSize,
  218.                         PSYS_SRC_PATTERN, pattern,
  219.                         PSYS_SRC_BURST_RATE,rate,
  220.                         PSYS_SRC_ACCEL, push,
  221.                         PSYS_SRC_BURST_PART_COUNT,count,
  222.                         PSYS_SRC_BURST_RADIUS,radius,
  223.                         PSYS_SRC_BURST_SPEED_MIN,minSpeed,
  224.                         PSYS_SRC_BURST_SPEED_MAX,maxSpeed,
  225.                         PSYS_SRC_TARGET_KEY,target,
  226.                         PSYS_SRC_INNERANGLE,innerAngle,
  227.                         PSYS_SRC_OUTERANGLE,outerAngle,
  228.                         PSYS_SRC_OMEGA, omega,
  229.                         PSYS_SRC_MAX_AGE, life,
  230.                         PSYS_SRC_TEXTURE, texture,
  231.                         PSYS_PART_START_ALPHA, startAlpha,
  232.                         PSYS_PART_END_ALPHA, endAlpha
  233.                             ]);
  234. }
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246. //////////////////////////////////////////////////////////
  247. //                     INTERNALS                        //
  248. //////////////////////////////////////////////////////////
  249.  
  250. //////////////////////////////////////////////////////////
  251. // Wizardry and Steamworks (c) 2013,  GPLv3             //
  252. //////////////////////////////////////////////////////////
  253.  
  254. string progress(integer percent, integer length, list symbols) {
  255.     percent /= (integer)((float)100.0/(length));
  256.     string p = llList2String(symbols,0);
  257.     integer itra = 0;
  258.     do {
  259.         if(itra>percent-1) p += llList2String(symbols,2);
  260.         else p += llList2String(symbols,1);
  261.     } while(++itra<length);
  262.     return p + llList2String(symbols,3);
  263. }
  264.  
  265. //////////////////////////////////////////////////////////
  266. // Wizardry and Steamworks (c) 2013,  GPLv3             //
  267. //////////////////////////////////////////////////////////
  268.  
  269. vector wasPercentToGradient(float percent, string rgb) {
  270.     if(llStringLength(rgb) != 2) {
  271.         llSay(DEBUG_CHANNEL, "Assert failed, rgb parameter must consist of a pair of either r, g, or b.");
  272.         return ZERO_VECTOR;
  273.     }
  274.     string a = llGetSubString(rgb, 0, 0);
  275.     string b = llGetSubString(rgb, 1, 1);
  276.     list col = [ "r", "g", "b" ];
  277.     integer ax = llListFindList(col, (list)a);
  278.     integer bx = llListFindList(col, (list)b);
  279.     if(ax == -1 || bx == -1) {
  280.         llSay(DEBUG_CHANNEL, "Asset failed, rgb parameters must contain either r, g, or b letters.");
  281.         return ZERO_VECTOR;
  282.     }
  283.     col = llListReplaceList(col, (list)((100-percent)/100), ax, ax);
  284.     col = llListReplaceList(col, (list)(percent/100), bx, bx);
  285.     return 2*<llList2Float(col, 0), llList2Float(col, 1), llList2Float(col, 2)>;
  286. }
  287.  
  288. float h;
  289.  
  290.  
  291.  
  292. listenOne()
  293. {
  294.     wallOne = llListen(tChan, "wall controller 1", "", "");
  295. }
  296.  
  297.  
  298. default
  299. {
  300.     state_entry()
  301.     {
  302.          llCollisionFilter("Cannonball","",TRUE);
  303.         listenOne();
  304.  
  305.  
  306.  
  307.         llParticleSystem([]);
  308.         h = HEALTH;
  309.         llSetText("Health: " + progress((integer)(h/HEALTH*100), 10, ["[", "█", "░", "]"]), wasPercentToGradient((integer)(h/HEALTH*100), "rg"), 1.0);
  310.     }
  311.    
  312.    
  313.     listen(integer channel, string name, key id, string msg)
  314.     {
  315.         if(msg=="status")
  316.         {
  317.             //llSleep(0.1);
  318.             llShout(0, (string)h);
  319.             llRegionSay(tChan, (string)h);
  320.         }
  321.         else if(msg=="cleanup")
  322.         {
  323.             //llDie();
  324.             //llRegionSay(chanOneTalk, "block is dead");
  325.             llShout(0, "Cleaning up");
  326.             state dead;
  327.         }
  328.         else
  329.         {
  330.             //llShout(0, "some message was received.");
  331.         }
  332.     }
  333.      
  334.    
  335.    
  336.    
  337.    
  338.     collision_start(integer num)
  339.     {
  340.         h -= llVecMag(llDetectedVel(0));
  341.         llSetText("Health: " + progress((integer)(h/HEALTH*100), 10, ["[", "█", "░", "]"]), wasPercentToGradient((integer)(h/HEALTH*100), "rg"), 1.0);
  342.        
  343.         llSetTimerEvent(delay);
  344.        
  345.         if((h/HEALTH*100) <= 95 && (h/HEALTH*100) >= 50)
  346.         {
  347.             StartSmoke();
  348.             llSleep(10.0/(h/HEALTH*100));
  349.             llParticleSystem([]);
  350.         }
  351.        
  352.        
  353.         if(h <= 0)
  354.         {
  355.             state dead;
  356.         }
  357.        
  358.             //llShout(0, (string)h + " " + (string)HEALTH + " " + (string)(h/HEALTH*100));
  359.     }
  360.  
  361.     timer()
  362.     {
  363.         //llShout(0, "Timer is on");
  364.                
  365.         if((h/HEALTH*100) <= 50 && (h/HEALTH*100) >= 25)
  366.         {
  367.             StartSmoke();
  368.         }
  369.        
  370.         else if((h/HEALTH*100) <= 25)
  371.         {
  372.             flipSwitch =! flipSwitch;
  373.             delay = 1.0;
  374.             if(flipSwitch)
  375.             {
  376.                 StartSmoke();
  377.             }
  378.             else if(!flipSwitch)
  379.             {
  380.                 StartFire();
  381.             }
  382.         }
  383.        
  384.         else
  385.         {
  386.             llParticleSystem([]);
  387.         }
  388.     }
  389. }
  390.  
  391.  
  392. state dead
  393. {
  394.     state_entry()
  395.     {
  396.         llSetText("☠", <1,0,0>, 1.0);
  397.         llSleep(1.0);
  398. //        llDie();
  399.     }
  400. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement