Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Scripted by iMagic (Graal2007722)
- const MAX_HEALTH = 50;
- const MIN_HEALTH = 0;
- public function onDamage(damage, killer) {
- if (player.account == killer) { return; }
- if (!this.isDying) {
- temp.enemy = findplayer(killer);
- if (clientr.health > MIN_HEALTH) {
- clientr.health -= temp.damage;
- }
- if (clientr.health < MIN_HEALTH) {
- clientr.health = MIN_HEALTH;
- onDeath();
- (@"-System/Health").onShowKiller(killer);
- }
- if (this.ClearBarScheduled) {
- cancelEvents("onClearBar");
- this.ClearBarScheduled = false;
- scheduleEvent(3, "onClearBar", "");
- this.ClearBarScheduled = true;
- }
- onUpdateHealthBar();
- }
- }
- public function onHeal(player,health) {
- temp.pl = findplayer(player);
- temp.hp = temp.pl.clientr.health + temp.healt;
- if (temp.hp > MAX_HEALTH) {
- temp.pl.clientr.health = MAX_HEALTH;
- } else {
- temp.pl.clientr.health += temp.health;
- }
- onUpdateHealthBar();
- }
- function onGetClosest(health) {
- temp.array = {0, 1, 20, 40, 60, 80, 100};
- temp.health_percent = (clientr.health / MAX_HEALTH) * 100;
- temp.current = temp.array[0];
- for (temp.i : temp.array) {
- if (abs(temp.health_percent - temp.i) < abs(temp.health_percent - temp.current)) {
- temp.current = temp.i;
- if (temp.current == 1) {
- temp.current = 20;
- }
- }
- } return format("imagic-hp-%s.gani", temp.current);
- }
- function onUpdateHealthBar() {
- if (!(clientr.health in |MIN_HEALTH, MAX_HEALTH + 1|)) {
- if (clientr.health > MAX_HEALTH) {
- clientr.health = MAX_HEALTH;
- }
- }
- player.attr[3] = onGetClosest();
- if (!this.ClearBarScheduled) {
- scheduleEvent(3, "onClearBar", "");
- this.ClearBarScheduled = true;
- }
- (@"-System/Health").onDisplayHealth(player.clientr.health, MAX_HEALTH);
- }
- function onPlayerChats() {
- if (player.chat.lower().starts("/hp")) {
- temp.token = player.chat.tokenize(" ");
- player.clientr.health = temp.token[1];
- player.chat = player.clientr.health;
- onUpdateHealthBar();
- }
- }
- function onDeath() {
- onUpdateHealthBar();
- this.isDying = true;
- freezeplayer2();
- player.ani = "dead";
- scheduleEvent(3, "onRevive", "");
- }
- // Revives the player.
- function onRevive() {
- clientr.health = MAX_HEALTH;
- player.ani = "revive";
- onUpdateHealthBar();
- scheduleEvent(2, "onNotDead", "");
- }
- function onNotDead() {
- this.isDying = false;
- unfreezeplayer();
- }
- // Clears the Healthbar
- function onClearBar() {
- this.ClearBarScheduled = false;
- player.attr[3] = "";
- }
Advertisement
Add Comment
Please, Sign In to add comment