iMagicBae

Untitled

May 27th, 2020
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Scripted by iMagic (Graal2007722)
  2. const MAX_HEALTH = 50;
  3. const MIN_HEALTH = 0;
  4.  
  5. public function onDamage(damage, killer) {
  6.   if (player.account == killer) { return; }
  7.   if (!this.isDying) {
  8.     temp.enemy = findplayer(killer);
  9.     if (clientr.health > MIN_HEALTH) {
  10.       clientr.health -= temp.damage;
  11.     }
  12.     if (clientr.health < MIN_HEALTH) {
  13.       clientr.health = MIN_HEALTH;
  14.       onDeath();
  15.       (@"-System/Health").onShowKiller(killer);
  16.     }
  17.     if (this.ClearBarScheduled) {
  18.      cancelEvents("onClearBar");
  19.      this.ClearBarScheduled = false;
  20.      scheduleEvent(3, "onClearBar", "");
  21.      this.ClearBarScheduled = true;
  22.     }
  23.     onUpdateHealthBar();
  24.   }
  25. }
  26.  
  27. public function onHeal(player,health) {
  28.   temp.pl = findplayer(player);
  29.   temp.hp = temp.pl.clientr.health + temp.healt;
  30.   if (temp.hp > MAX_HEALTH) {
  31.     temp.pl.clientr.health = MAX_HEALTH;
  32.   } else {
  33.     temp.pl.clientr.health += temp.health;
  34.   }
  35.   onUpdateHealthBar();
  36. }
  37.  
  38. function onGetClosest(health) {
  39.   temp.array = {0, 1, 20, 40, 60, 80, 100};
  40.   temp.health_percent = (clientr.health / MAX_HEALTH) * 100;
  41.   temp.current = temp.array[0];
  42.   for (temp.i : temp.array) {
  43.     if (abs(temp.health_percent - temp.i) < abs(temp.health_percent - temp.current)) {
  44.       temp.current = temp.i;
  45.       if (temp.current == 1) {
  46.         temp.current = 20;
  47.       }
  48.     }
  49.   } return format("imagic-hp-%s.gani", temp.current);
  50. }
  51.  
  52. function onUpdateHealthBar() {
  53.   if (!(clientr.health in |MIN_HEALTH, MAX_HEALTH + 1|)) {
  54.     if (clientr.health > MAX_HEALTH) {
  55.       clientr.health = MAX_HEALTH;
  56.     }
  57.   }
  58.   player.attr[3] = onGetClosest();
  59.   if (!this.ClearBarScheduled) {
  60.     scheduleEvent(3, "onClearBar", "");
  61.     this.ClearBarScheduled = true;
  62.   }
  63.   (@"-System/Health").onDisplayHealth(player.clientr.health, MAX_HEALTH);
  64. }
  65.  
  66. function onPlayerChats() {
  67.   if (player.chat.lower().starts("/hp")) {
  68.     temp.token = player.chat.tokenize(" ");
  69.     player.clientr.health = temp.token[1];
  70.     player.chat = player.clientr.health;
  71.     onUpdateHealthBar();
  72.   }
  73. }
  74.  
  75. function onDeath() {
  76.   onUpdateHealthBar();
  77.   this.isDying = true;
  78.   freezeplayer2();
  79.   player.ani = "dead";
  80.   scheduleEvent(3, "onRevive", "");
  81. }
  82.  
  83.   // Revives the player.
  84. function onRevive() {
  85.   clientr.health = MAX_HEALTH;
  86.   player.ani = "revive";
  87.   onUpdateHealthBar();
  88.   scheduleEvent(2, "onNotDead", "");
  89. }
  90.  
  91. function onNotDead() {
  92.   this.isDying = false;
  93.   unfreezeplayer();
  94. }
  95.  
  96.   // Clears the Healthbar
  97. function onClearBar() {
  98.   this.ClearBarScheduled = false;
  99.   player.attr[3] = "";
  100. }
Advertisement
Add Comment
Please, Sign In to add comment