Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Scripted by iMagic (Graal2007722)
- /*
- This function equates the player damage serverside and clientside since clientr vars can
- only be read on client, not altered.
- */
- function onActionServerHealth(cmd, player, health) {
- temp.pl = findplayer(player);
- if (cmd == "update") {
- temp.pl.clientr.health = health;
- }
- if (cmd == "rectify") {
- if (temp.health > 50) {
- temp.pl.clientr.health = 50;
- } else {
- temp.pl.clientr.health = 0;
- }
- }
- }
- //#CLIENTSIDE
- // Enums make it easier to iterate through the health object.
- enum HEALTH_PERCENT {
- HUNDRED = "tb_imagic-hp-100.gani",
- EIGHTY = "tb_imagic-hp-80.gani",
- SIXTY = "tb_imagic-hp-60.gani",
- FORTY = "tb_imagic-hp-40.gani",
- TWENTY = "tb_imagic-hp-20.gani",
- CERO = "tb_imagic-hp-0.gani"
- };
- const MAX_HEALTH = 51;
- const MIN_HEALTH = 0;
- // Ensures the health is never above or under the established max or min.
- function onHealthBoundaries() {
- if (!(clientr.health in |MIN_HEALTH, MAX_HEALTH|)) {
- triggeraction(player.x, player.y, "ServerHealth", "rectify", player.account, clientr.health);
- }
- if (clientr.health <= 0) {
- onDeath();
- }
- onUpdateHealthBar();
- }
- // Handles displaying the player's health bar to the nearest percentage.
- function onUpdateHealthBar() {
- if (clientr.health == 50) {
- player.attr[3] = HEALTH_PERCENT.HUNDRED;
- } else if (clientr.health in |40,49|) {
- player.attr[3] = HEALTH_PERCENT.EIGHTY;
- } else if (clientr.health in |30,39|) {
- player.attr[3] = HEALTH_PERCENT.SIXTY;
- } else if (clientr.health in |20,29|) {
- player.attr[3] = HEALTH_PERCENT.FORTY;
- } else if (clientr.health in |1,19|) {
- player.attr[3] = HEALTH_PERCENT.TWENTY;
- } else if (clientr.health == 0) {
- player.attr[3] = HEALTH_PERCENT.CERO;
- }
- triggeraction(player.x, player.y, "ServerHealth", "update", player.account, clientr.health);
- scheduleEvent(3, "onClearBar", "");
- }
- // Some testing commands, dont mind this.
- function onPlayerChats() {
- switch (player.chat) {
- case "hp":
- this.chat = clientr.health;
- break;
- case "-5":
- clientr.health -= 5;
- this.chat = clientr.health;
- break;
- case "+5":
- clientr.health += 5;
- this.chat = clientr.health;
- break;
- }
- onHealthBoundaries();
- }
- // Handles the player death event.
- function onDeath() {
- freezeplayer(2);
- onUpdateHealthBar();
- player.ani = "dead";
- sleep(2);
- clientr.health = 50;
- player.ani = "revive";
- triggeraction(player.x, player.y, "ServerHealth", "update", player.account, clientr.health);
- }
- function onClearBar() {
- player.attr[3] = "";
- }
Advertisement
Add Comment
Please, Sign In to add comment