Armor

Version:

5.0

Added on:

06 Jan 2015 20:12

Tags:

Description:
Armor. The armor protects you from enemies, if you get hurt sometimes you don't even lose a heart.
  1. /*********************************************Armor Script*********************************************/
  2.  
  3. uint elapsedhealth = 0;
  4. uint armorLevel = 0;
  5. int defend = 0;
  6.  
  7. const int Tab = 9;
  8. array<string> armor = {
  9.     "Rabbit Fur",
  10.   "Leather",
  11.   "Bronze",
  12.   "Iron",
  13.   "Your Armor"
  14. };
  15.  
  16. array<int> armorDurabilityMax = {
  17.     999999999,
  18.   25,
  19.   60,
  20.   100,
  21.   //maxDurability for your armor
  22. };
  23.  
  24. array<int> armorDurability = {
  25.     999999999,
  26.   25,
  27.   60,
  28.   100,
  29.   //mainDurability for your armor
  30. };
  31.  
  32. bool alreadyDefended = false;
  33.  
  34. void onLevelBegin() {
  35.     elapsedhealth = jjLocalPlayers[0].health;
  36. }
  37.  
  38. bool inDefense = false;
  39.  
  40. void onMain() {
  41.  
  42. if (jjGameTicks % 140 == 0) {
  43.     elapsedhealth = p.health;
  44.   alreadyDefended = false;
  45. }
  46.  
  47. if (elapsedhealth > p.health && p.health != 0 && p.health != 1) {
  48.     if (!alreadyDefended) {
  49.     defend = jjRandom() % 15 + 1;
  50.   if (defend == 7) {
  51.       p.health = p.health + 1;
  52.   } else if (defend == 4) {
  53.       if (armorLevel > 0) {
  54.       p.health = p.health + 1;
  55.     }
  56.   } else if (defend == 12) {
  57.       if (armorLevel > 0) {
  58.       p.health = p.health + 1;
  59.  
  60.     }
  61.   } else if (defend == 5) {
  62.       if (armorLevel > 1) {
  63.       p.health = p.health + 1;
  64.     }
  65.   } else if (defend == 15) {
  66.       if (armorLevel > 2) {
  67.       p.health = p.health + 1;
  68.     }
  69.   } else if (defend == 1) {
  70.       if (armorLevel > 2) {
  71.       p.health = p.health + 1;
  72.     }
  73.   } else if (defend == /*your defend number*/) {  //Note: do not put the same number as another IF in here.
  74.         if (armorLevel > /*...*/) { //You can understand this. If "armorLevel" is bigger than a certain level.    <-
  75.     p.health = p.health + 1;
  76.     }
  77.   }
  78.   armorDurability[armorLevel] -= jjRandom() % 3 + 1;
  79.   alreadyDefended = true;
  80.   }
  81. }
  82.     if (armorDurability[armorLevel] > armorDurabilityMax[armorLevel]) {
  83.       armorDurability[armorLevel] = armorDurabilityMax[armorLevel];
  84.   }
  85.   if (armorDurability[armorLevel] < 1) {
  86.       armorLevel = 0;
  87.     armorDurability[0] = 999999999;
  88.   }
  89.  
  90. }
  91.  
  92. int defense;
  93.  
  94. bool onDrawScore(jjPLAYER@ p, jjCANVAS@ canvas) {
  95.     if (jjKey[Tab]) {
  96.     canvas.drawString(jjSubscreenWidth - 420, jjSubscreenHeight - 300, "Armor Type: " + armor[armorLevel], STRING::SMALL, STRING::NORMAL);
  97.   switch(armorLevel) {
  98.       case 0:
  99.         defense = 1;
  100.       break;
  101.     case 1:
  102.         defense = 3;
  103.       break;
  104.     case 2:
  105.         defense = 4;
  106.       break;
  107.     case 3:
  108.         defense = 6;
  109.       break;
  110.   }
  111.   canvas.drawString(jjSubscreenWidth - 420, jjSubscreenHeight - 280, "Defense: " + defense, STRING::SMALL, STRING::NORMAL);
  112.   if (armorLevel != 0) {
  113.   canvas.drawString(jjSubscreenWidth - 420, jjSubscreenHeight - 260, "Durability: " + armorDurability[armorLevel], STRING::SMALL, STRING::NORMAL);
  114.   } else {
  115.   canvas.drawString(jjSubscreenWidth - 420, jjSubscreenHeight - 260, "Durability: ^", STRING::SMALL, STRING::NORMAL);
  116.   }
  117.   }
  118.   return true;
  119. }
  120.  
  121. void onObjectHit(jjOBJ@ obj, jjOBJ@ bullet, jjPLAYER@ p, int force) {
  122.     switch(obj.eventID) {
  123.       case OBJECT::CHIPS:
  124.         armorLevel = jjRandom() % 4;
  125.       armorDurability[armorLevel] = armorDurabilityMax[armorLevel];
  126.         obj.scriptedCollisions = false;
  127.         obj.behavior = BEHAVIOR::EXPLOSION2;
  128.         obj.frameID = 0;
  129.         jjSample(p.xPos, p.yPos, SOUND::COMMON_PICKUPW1, 30);
  130.       jjAlert("Equipped " + armor[armorLevel] + " Armour!");
  131.         break;
  132.   }
  133. }
  134.  
  135. /*You can always add different methods to get a certain armor.
  136. I just put that if you collect chips it will equip a random armor.*/
  137.  
  138. /***************************************************************************************************************************************/