Files
weapons.sk
Code
1 309
weapons.sk
# Kodari custom weapons
# Requires modern Skript with the built-in loot generate event; no addon is required.
# Install as plugins/Skript/scripts/weapons.sk, then run /sk reload weapons.
options:
weapon-prefix: &6[Weapons]&r
# The fixed hidden lore marker distinguishes these items from ordinary items.
# Each generated weapon also receives a random lore ID to prevent normal stacking.
# Lore markers are not cryptographic: item-copying plugins, NBT editors, or commands
# that copy all lore can still duplicate a weapon.
function makeBaseballBat(uses: integer) :: item:
set {_id} to random integer between 100000000 and 999999999
set {_weapon} to blaze rod
enchant {_weapon} with knockback 10
set name of {_weapon} to "&6Baseball Bat"
set lore of {_weapon} to "&7Hit a player or mob to send them flying." and "&7Uses remaining: &f%{_uses}%" and "&0Kodari item ID: %{_id}%" and "&0KODARI_WEAPON_BASEBALLBAT_V1"
return {_weapon}
function isBaseballBat(item: item) :: boolean:
if {_item} is a blaze rod:
if lore of {_item} contains "&0KODARI_WEAPON_BASEBALLBAT_V1":
return true
return false
function makeHeartStaff() :: item:
set {_id} to random integer between 100000000 and 999999999
set {_weapon} to lightning rod
set name of {_weapon} to "&dHeart Staff"
set lore of {_weapon} to "&7Hold in your offhand for 20 absorption health." and "&7Granted absorption is removed when unequipped." and "&0Kodari item ID: %{_id}%" and "&0KODARI_WEAPON_HEARTSTAFF_V1"
return {_weapon}
function isHeartStaff(item: item) :: boolean:
if {_item} is a lightning rod:
if lore of {_item} contains "&0KODARI_WEAPON_HEARTSTAFF_V1":
return true
return false
function makeTntBow() :: item:
set {_id} to random integer between 100000000 and 999999999
set {_weapon} to bow
set name of {_weapon} to "&cTNT Bow"
set lore of {_weapon} to "&7Every fifth shot launches primed TNT." and "&73% chance from End City treasure." and "&0Kodari item ID: %{_id}%" and "&0KODARI_WEAPON_TNTBOW_V1"
return {_weapon}
function isTntBow(item: item) :: boolean:
if {_item} is a bow:
if lore of {_item} contains "&0KODARI_WEAPON_TNTBOW_V1":
return true
return false
function makePogoStick(uses: integer) :: item:
set {_id} to random integer between 100000000 and 999999999
set {_weapon} to breeze rod
enchant {_weapon} with knockback 1
set name of {_weapon} to "&aPogo Stick"
set lore of {_weapon} to "&7Right-click to launch about 70 blocks upward." and "&7Uses remaining: &f%{_uses}%" and "&7Fall damage is prevented for that launch only." and "&0Kodari item ID: %{_id}%" and "&0KODARI_WEAPON_POGOSTICK_V1"
return {_weapon}
function isPogoStick(item: item) :: boolean:
if {_item} is a breeze rod:
if lore of {_item} contains "&0KODARI_WEAPON_POGOSTICK_V1":
return true
return false
# Absorption amount uses Minecraft health points: 20 points equals 10 hearts.
# Track the baseline and only remove the remaining amount attributable to this staff.
function removeHeartStaffBonus(p: player):
set {_id} to "%uuid of {_p}%"
if {heartstaff::active::%{_id}%} is set:
set {_current} to absorption amount of {_p}
if {_current} > {heartstaff::last::%{_id}%}:
set {_delta} to {_current} - {heartstaff::last::%{_id}%}
add {_delta} to {heartstaff::base::%{_id}%}
set {_available} to {_current} - {heartstaff::base::%{_id}%}
if {_available} < 0:
set {_available} to 0
if {_available} > {heartstaff::grant::%{_id}%}:
set {_available} to {heartstaff::grant::%{_id}%}
set {_remaining} to {_current} - {_available}
set absorption hearts of {_p} to {_remaining}
delete {heartstaff::active::%{_id}%}
delete {heartstaff::base::%{_id}%}
delete {heartstaff::grant::%{_id}%}
delete {heartstaff::last::%{_id}%}
function reconcileHeartStaff(p: player):
set {_id} to "%uuid of {_p}%"
if {_p} is alive:
if isHeartStaff(offhand tool of {_p}) is true:
if {heartstaff::active::%{_id}%} is not set:
set {heartstaff::base::%{_id}%} to absorption amount of {_p}
set {heartstaff::grant::%{_id}%} to 20
set {_new} to absorption amount of {_p} + 20
set absorption amount of {_p} to {_new}
set {heartstaff::last::%{_id}%} to {_new}
set {heartstaff::active::%{_id}%} to true
else:
set {_current} to absorption amount of {_p}
if {_current} > {heartstaff::last::%{_id}%}:
set {_delta} to {_current} - {heartstaff::last::%{_id}%}
add {_delta} to {heartstaff::base::%{_id}%}
set {_available} to {_current} - {heartstaff::base::%{_id}%}
if {_available} < 0:
set {_available} to 0
if {_available} < {heartstaff::grant::%{_id}%}:
set {heartstaff::grant::%{_id}%} to {_available}
set {heartstaff::last::%{_id}%} to {_current}
else:
removeHeartStaffBonus({_p})
else:
removeHeartStaffBonus({_p})
on script load:
# A pogo launch cannot safely survive a reload or server restart.
delete {pogo::launch::*}
delete {pogo::launch-world::*}
delete {pogo::cooldown::*}
loop all players:
reconcileHeartStaff(loop-player)
on join:
wait 1 tick
reconcileHeartStaff(player)
# Reconciliation every tick catches offhand swaps, inventory movement, and drops.
every 1 tick:
loop all players:
reconcileHeartStaff(loop-player)
# Vault reward tables are added to when the server emits LootGenerateEvent for them.
# Some server versions resolve per-player vault rewards internally without this event;
# on those versions the vault additions are best-effort. End City treasure uses its loot table.
on loot generate:
set {_table} to "%event-loot-table%"
if {_table} contains "trial_chambers/reward_ominous":
chance of 5%:
set {_weapon} to makeBaseballBat(5)
add {_weapon} to event-loot
else if {_table} contains "trial_chambers/reward":
chance of 5%:
set {_weapon} to makePogoStick(3)
add {_weapon} to event-loot
else if {_table} contains "end_city_treasure":
chance of 3%:
set {_weapon} to makeTntBow()
add {_weapon} to event-loot
on death of warden:
if killer is a player:
set {_killer} to killer
set {_weapon} to makeHeartStaff()
add {_weapon} to drops
broadcast "%name of {_killer}% has obtained the legendary Heart Staff!"
# Cancel the actual placement event so the staff cannot become a lightning rod block.
on place:
if isHeartStaff(event-item) is true:
cancel event
send "{@weapon-prefix} &cThe Heart Staff cannot be placed." to player
on damage of living entity:
if attacker is a player:
if damage cause is attack:
if damage > 0:
if event is not cancelled:
if isBaseballBat(tool of attacker) is true:
# Other plugins running later may still cancel this damage event.
push victim away from attacker at speed 3.4
if line 2 of lore of tool of attacker is "&7Uses remaining: &f5":
set line 2 of lore of tool of attacker to "&7Uses remaining: &f4"
else if line 2 of lore of tool of attacker is "&7Uses remaining: &f4":
set line 2 of lore of tool of attacker to "&7Uses remaining: &f3"
else if line 2 of lore of tool of attacker is "&7Uses remaining: &f3":
set line 2 of lore of tool of attacker to "&7Uses remaining: &f2"
else if line 2 of lore of tool of attacker is "&7Uses remaining: &f2":
set line 2 of lore of tool of attacker to "&7Uses remaining: &f1"
else if line 2 of lore of tool of attacker is "&7Uses remaining: &f1":
set tool of attacker to air
send "{@weapon-prefix} &6Your Baseball Bat broke." to attacker
on right click:
if isPogoStick(player's tool) is true:
set {_id} to "%uuid of player%"
if {pogo::cooldown::%{_id}%} is set:
stop
set {pogo::cooldown::%{_id}%} to 2
if line 2 of lore of player's tool is "&7Uses remaining: &f3":
set line 2 of lore of player's tool to "&7Uses remaining: &f2"
else if line 2 of lore of player's tool is "&7Uses remaining: &f2":
set line 2 of lore of player's tool to "&7Uses remaining: &f1"
else if line 2 of lore of player's tool is "&7Uses remaining: &f1":
set player's tool to air
send "{@weapon-prefix} &aYour Pogo Stick broke." to player
else:
send "{@weapon-prefix} &cThis Pogo Stick has no valid uses remaining." to player
stop
set {pogo::launch::%{_id}%} to 30
set {pogo::launch-world::%{_id}%} to name of world of player