Files
HeartSteal.sk
Code
1 89
HeartSteal.sk
# HeartSteal.sk
# When killed by another player, the victim loses 1 heart and the killer gains 1 heart.
# Dying to other causes (mobs, fall damage, etc.) has no effect on hearts.
options:
# Default max health in half-hearts (20.0 = 10 hearts)
default_health: 20.0
# Minimum possible health (6.0 = 3 hearts)
min_health: 6.0
# Maximum possible health (40.0 = 20 hearts)
max_health: 40.0
# Initialize heart data on first join
on join:
if {hearts::%uuid of player%} is not set:
set {hearts::%uuid of player%} to {@default_health}
set max health of player to {hearts::%uuid of player%}
# Handle heart transfer on player kill
on death:
attacker is a player
victim is a player
set {_vic} to {hearts::%uuid of victim%}
set {_att} to {hearts::%uuid of attacker%}
if {_vic} is not set:
set {_vic} to {@default_health}
if {_att} is not set:
set {_att} to {@default_health}
# Don't steal if victim is already at minimum hearts
if {_vic} <= {@min_health}:
send "&7You were at minimum hearts — nothing was stolen." to attacker
stop
# Transfer 1 heart (2 health points)
remove 2.0 from {_vic}
add 2.0 to {_att}
# Clamp within allowed range
if {_vic} < {@min_health}:
set {_vic} to {@min_health}
if {_att} > {@max_health}:
set {_att} to {@max_health}
set {hearts::%uuid of victim%} to {_vic}
set {hearts::%uuid of attacker%} to {_att}
set max health of victim to {_vic}
set max health of attacker to {_att}
# Cap current health if it exceeds new max
if health of victim > {_vic}:
set health of victim to {_vic}
if health of attacker > {_att}:
set health of attacker to {_att}
send "&c&l☠ &7You lost a heart! &8(&c%{_vic} / 2%❤&8)" to victim
send "&a&l⚔ &7You stole a heart! &8(&a%{_att} / 2%❤&8)" to attacker
# Command to check your own or another player's hearts
command /hearts [<offline player>]:
aliases: /heart, /hp
trigger:
if arg-1 is not set:
set {_h} to {hearts::%uuid of player%}
if {_h} is not set:
set {_h} to {@default_health}
send "&6❤ &eYour hearts: &f%{_h} / 2% &8(&7%{_h}% HP&8)" to player
else:
if arg-1 has played before:
set {_h} to {hearts::%uuid of arg-1%}
if {_h} is not set:
set {_h} to {@default_health}
send "&6❤ &e%arg-1%'s hearts: &f%{_h} / 2% &8(&7%{_h}% HP&8)" to player
else:
send "&cPlayer not found." to player
# Admin command to reset or set hearts
command /sethearts <player> <number>:
permission: heartsteal.admin
trigger:
set {hearts::%uuid of arg-1%} to arg-2
set max health of arg-1 to arg-2
if health of arg-1 > arg-2:
set health of arg-1 to arg-2
send "&aSet %arg-1%'s hearts to %arg-2 / 2%." to player
send "&eYour hearts were set to %arg-2 / 2% &eby an admin." to arg-1