iMagicBae

Untitled

Apr 13th, 2020
399
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Scripted by iMagic (Graal2007722)
  2.  
  3. /*
  4.     This function equates the player damage serverside and clientside since clientr vars can
  5.     only be read on client, not altered.
  6. */
  7.  
  8. function onActionServerHealth(cmd, player, health) {
  9.   temp.pl = findplayer(player);
  10.   if (cmd == "update") {
  11.     temp.pl.clientr.health = health;
  12.   }
  13.   if (cmd == "rectify") {
  14.     if (temp.health > 50) {
  15.       temp.pl.clientr.health = 50;
  16.     } else {
  17.       temp.pl.clientr.health = 0;
  18.     }
  19.   }
  20. }
  21.  
  22. //#CLIENTSIDE
  23.  
  24.   // Enums make it easier to iterate through the health object.
  25. enum HEALTH_PERCENT {
  26.   HUNDRED = "tb_imagic-hp-100.gani",
  27.   EIGHTY = "tb_imagic-hp-80.gani",
  28.   SIXTY = "tb_imagic-hp-60.gani",
  29.   FORTY = "tb_imagic-hp-40.gani",
  30.   TWENTY = "tb_imagic-hp-20.gani",
  31.   CERO = "tb_imagic-hp-0.gani"
  32. };
  33.  
  34. const MAX_HEALTH = 51;
  35. const MIN_HEALTH = 0;
  36.  
  37.   // Ensures the health is never above or under the established max or min.
  38. function onHealthBoundaries() {
  39.   if (!(clientr.health in |MIN_HEALTH, MAX_HEALTH|)) {
  40.     triggeraction(player.x, player.y, "ServerHealth", "rectify", player.account, clientr.health);
  41.   }
  42.   if (clientr.health <= 0) {
  43.     onDeath();
  44.   }
  45.   onUpdateHealthBar();
  46. }
  47.  
  48.   // Handles displaying the player's health bar to the nearest percentage.
  49. function onUpdateHealthBar() {
  50.   if (clientr.health == 50) {
  51.     player.attr[3] = HEALTH_PERCENT.HUNDRED;
  52.   } else if (clientr.health in |40,49|) {
  53.     player.attr[3] = HEALTH_PERCENT.EIGHTY;
  54.   } else if (clientr.health in |30,39|) {
  55.     player.attr[3] = HEALTH_PERCENT.SIXTY;
  56.   } else if (clientr.health in |20,29|) {
  57.     player.attr[3] = HEALTH_PERCENT.FORTY;
  58.   } else if (clientr.health in |1,19|) {
  59.     player.attr[3] = HEALTH_PERCENT.TWENTY;
  60.   } else if (clientr.health == 0) {
  61.     player.attr[3] = HEALTH_PERCENT.CERO;
  62.   }
  63.   triggeraction(player.x, player.y, "ServerHealth", "update", player.account, clientr.health);
  64.   scheduleEvent(3, "onClearBar", "");
  65. }
  66.  
  67. // Some testing commands, dont mind this.
  68. function onPlayerChats() {
  69.   switch (player.chat) {
  70.     case "hp":
  71.     this.chat = clientr.health;
  72.     break;
  73.  
  74.     case "-5":
  75.     clientr.health -= 5;
  76.     this.chat = clientr.health;
  77.     break;
  78.  
  79.     case "+5":
  80.     clientr.health += 5;
  81.     this.chat = clientr.health;
  82.     break;
  83.   }
  84.   onHealthBoundaries();
  85. }
  86.  
  87.   // Handles the player death event.
  88. function onDeath() {
  89.   freezeplayer(2);
  90.   onUpdateHealthBar();
  91.   player.ani = "dead";
  92.   sleep(2);
  93.   clientr.health = 50;
  94.   player.ani = "revive";
  95.   triggeraction(player.x, player.y, "ServerHealth", "update", player.account, clientr.health);
  96. }
  97.  
  98. function onClearBar() {
  99.   player.attr[3] = "";
  100. }
Advertisement
Add Comment
Please, Sign In to add comment