Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require "base/internal/ui/reflexcore";
- yk_fightHealth =
- {
- healthTimer = 0;
- flashTimer = 0;
- };
- registerWidget("yk_fightHealth");
- ---------------
- -- CONSTANTS --
- ---------------
- local healthAlarm = 1.2;
- local barWidth = 480;
- local barHeight = 40;
- local barHealthOffsetX = 0;
- local barHealthOffsetY = 0;
- local frameBorder = 5;
- -- I want to use these colors for the truehealth/stack/arenamode bar
- --local colorHealth = Color(255, 160, 0);
- --local colorOverHealth = Color(0, 224, 255);
- local colorHealth = Color(112, 255, 255);
- local colorOverHealth = Color(0, 96, 255);
- local colorHealthDamage = Color(255, 0, 64);
- local colorHealthDamage = Color(255, 0, 64);
- local colorHealthPickup = Color(255, 255, 255);
- local colorFrame = Color(4, 2, 0, 160);
- local colorTrim = Color(255, 255, 255);
- local drainSpeed = 225; --228
- local flashDirection = 1;
- local flashLength = 0.15;
- ---------------
- -- VARIABLES --
- ---------------
- local oldHealth = 0;
- local healthDamage = 0;
- local healthPickup = 0;
- local lostHealthDamage = 0;
- local lostHealthPickup = 0;
- local drainHealthDamage = false;
- local drainHealthPickup = false;
- colorHealthFinal = Color(
- lerp(colorHealth.r, colorOverHealth.r, 0.5),
- lerp(colorHealth.g, colorOverHealth.g, 0.5),
- lerp(colorHealth.b, colorOverHealth.b, 0.5)
- );
- ---------------
- function yk_fightHealth:draw()
- -- PLAYER, FIRST OUT
- local player = getPlayer();
- if player == nil or
- player.state == PLAYER_STATE_EDITOR or
- player.state == PLAYER_STATE_SPECTATOR or
- world.gameState == GAME_STATE_GAMEOVER or
- isInMenu()
- then return false end;
- if not player.connected then return end;
- -- IF YOU DIE, CLEAR EVERYTHING
- if player.health <= 0 then
- self.healthTimer = 0;
- oldHealth = 0;
- healthDamage = 0;
- healthPickup = 0;
- lostHealthDamage = 0;
- lostHealthPickup = 0;
- drainHealthDamage = false;
- drainHealthPickup = false;
- end
- -- SECOND OUT
- if not shouldShowHUD() then return end;
- -- FLASH TIMER
- if self.flashTimer >= flashLength then
- flashDirection = -1;
- elseif self.flashTimer <= 0 then
- flashDirection = 1;
- end
- self.flashTimer = self.flashTimer + (flashDirection * deltaTime);
- -- CALCULATE DAMAGE COLOR
- local colorHealthDamageFinal = Color(colorHealthDamage.r, colorHealthDamage.g, colorHealthDamage.b,
- lerp(colorHealthDamage.a, colorHealthDamage.a / 3, self.flashTimer/flashLength)
- );
- -- HEALTH REMAINED CONSTANT WHILE DAMAGE OR PICKUP WAS BUFFERED, INCREMENT TIMER
- if (player.health == oldHealth) and ((healthPickup ~= 0) or (healthDamage ~= 0)) then
- self.healthTimer = math.min(healthAlarm, self.healthTimer + deltaTime);
- end
- -- HEALTH DAMAGE, RESET TIMER, ADJUST BUFFERS
- if player.health < oldHealth then
- local d = (oldHealth - player.health);
- healthDamage = healthDamage + d;
- if d > 1 then
- drainHealthDamage = false;
- drainHealthPickup = false;
- self.healthTimer = 0;
- end
- -- IF PICKUP BUFFERED, DECREASE PICKUP FIRST, KEEP TRACK OF PICKUP LOST THIS WAY
- if healthPickup > 0 then
- if healthPickup >= d then
- lostHealthPickup = lostHealthPickup + d;
- healthPickup = healthPickup - d;
- elseif healthPickup < d then
- lostHealthPickup = lostHealthPickup + healthPickup;
- healthPickup = 0;
- end
- end
- oldHealth = player.health;
- -- HEALTH PICKUP, RESET TIMER, ADJUST BUFFERS
- elseif player.health > oldHealth then
- local p = (player.health - oldHealth);
- healthPickup = healthPickup + p;
- if p > 1 then
- drainHealthDamage = false;
- drainHealthPickup = false;
- self.healthTimer = 0;
- end
- -- IF DAMAGE BUFFERED, DECREASE DAMAGE FIRST, KEEP TRACK OF DAMAGE LOST THIS WAY
- if healthDamage > 0 then
- if healthDamage >= p then
- lostHealthDamage = lostHealthDamage + p;
- healthDamage = healthDamage - p;
- elseif healthDamage < p then
- lostHealthDamage = lostHealthDamage + healthDamage;
- healthDamage = 0;
- end
- end
- oldHealth = player.health;
- end
- -- AT SET TIME, RESET TIMER, BEGIN DRAINING BUFFERS
- if self.healthTimer >= healthAlarm then
- self.healthTimer = 0;
- drainHealthDamage = true;
- drainHealthPickup = true;
- end
- -- DRAIN DAMAGE BUFFERS, CALCULATE HEALTH COLOR
- if drainHealthDamage then
- if (healthDamage > 0) or (lostHealthDamage > 0) then
- healthDamage = math.max(0, healthDamage - (drainSpeed * deltaTime));
- lostHealthDamage = math.max(0, lostHealthDamage - (drainSpeed * deltaTime));
- else
- drainHealthDamage = false;
- end
- colorHealthFinal = Color(
- lerp(colorHealth.r, colorOverHealth.r, ((player.health - (healthPickup - lostHealthDamage) + (healthDamage - lostHealthPickup)) / 200)),
- lerp(colorHealth.g, colorOverHealth.g, ((player.health - (healthPickup - lostHealthDamage) + (healthDamage - lostHealthPickup)) / 200)),
- lerp(colorHealth.b, colorOverHealth.b, ((player.health - (healthPickup - lostHealthDamage) + (healthDamage - lostHealthPickup)) / 200))
- );
- end
- -- DRAIN PICKUP BUFFERS, CALCULATE HEALTH COLOR
- if drainHealthPickup then
- if (healthPickup > 0) or (lostHealthPickup > 0) then
- healthPickup = math.max(0, healthPickup - (drainSpeed * deltaTime));
- lostHealthPickup = math.max(0, lostHealthPickup - (drainSpeed * deltaTime));
- else
- drainHealthPickup = false;
- end
- colorHealthFinal = Color(
- lerp(colorHealth.r, colorOverHealth.r, ((player.health - (healthPickup - lostHealthDamage) + (healthDamage - lostHealthPickup)) / 200)),
- lerp(colorHealth.g, colorOverHealth.g, ((player.health - (healthPickup - lostHealthDamage) + (healthDamage - lostHealthPickup)) / 200)),
- lerp(colorHealth.b, colorOverHealth.b, ((player.health - (healthPickup - lostHealthDamage) + (healthDamage - lostHealthPickup)) / 200))
- );
- end
- -- PREPARE TO DRAW
- local xPos = barHealthOffsetX;
- local yPos = barHealthOffsetY;
- local barDamage = healthDamage * barWidth / 200; -- 200 max health
- local barPickup = healthPickup * barWidth / 200;
- local barFull = player.health * barWidth / 200;
- local barEmpty = barWidth - barFull - barDamage;
- -- DRAW FRAME
- nvgBeginPath();
- nvgRect(xPos, yPos, barWidth + (2 * frameBorder), barHeight + (2 * frameBorder));
- nvgClosePath();
- nvgFillColor(colorFrame);
- nvgFill();
- xPos = xPos + frameBorder;
- yPos = yPos + frameBorder;
- -- DRAW HEALTH
- nvgBeginPath();
- nvgRect(xPos, yPos, barFull, barHeight);
- nvgClosePath();
- nvgFillColor(colorHealthFinal);
- nvgFill();
- xPos = xPos + barFull;
- -- yPos = yPos;
- -- DRAW PICKUP
- xPos = xPos - barPickup;
- if healthPickup > 0 then
- nvgBeginPath();
- nvgRect(xPos, yPos, barPickup, barHeight);
- nvgClosePath();
- nvgFillColor(colorHealthPickup);
- nvgFill();
- end
- xPos = xPos + barPickup;
- -- DRAW DAMAGE
- if healthDamage > 0 then
- yPos = yPos + (barHeight / 16);
- nvgBeginPath();
- nvgRect(xPos, yPos, barDamage, barHeight - (barHeight / 8 ));
- nvgClosePath();
- nvgFillLinearGradient(xPos, yPos, xPos + barDamage, yPos, colorHealthDamageFinal, Color(0, 0, 0, 0));
- nvgFill();
- yPos = yPos - (barHeight / 16);
- end
- -- DRAW DELTA-MARK
- if (healthDamage > 0) or (healthPickup > 0) then
- nvgBeginPath();
- nvgRect(xPos - (barWidth/150), yPos - (barHeight/20), barWidth/75, barHeight + (barHeight/10));
- nvgClosePath();
- nvgFillColor(colorTrim);
- nvgFill();
- end
- xPos = barHealthOffsetX;
- yPos = barHealthOffsetY;
- nvgFillColor(colorTrim);
- nvgFontFace(FONT_HUD);
- nvgFontSize(36);
- nvgTextAlign(NVG_ALIGN_RIGHT, NVG_ALIGN_MIDDLE);
- nvgText(xPos - 6, yPos + (2 * barHeight / 3), player.health);
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement