Files
asteroid-strike.sk
Code
1 260
asteroid-strike.sk
# AsteroidStrike
# Requires: Skript, SkBee, Skript-Particle
# Place this file in plugins/Skript/scripts/
# Reload with: /sk reload asteroid-strike
options:
prefix: &8[&cAsteroidStrike&8]&r
permission: asteroid.admin
# Asteroid appearance and movement
asteroid-block: magma block
flight-height: 35
flight-distance: 30
asteroid-speed: 0.9
asteroid-fall-speed: 0.65
impact-radius: 8
spawn-interval: 10 ticks
particle-radius: 1.8
particle-count: 24
# Asteroid shape
asteroid-piece-count: 4
asteroid-piece-radius: 2
# Loot quantity
loot-minimum: 1
loot-maximum: 3
# Loot weights. Keep the total at 100 for predictable chances.
coal-chance: 35
iron-chance: 25
gold-chance: 18
redstone-chance: 12
emerald-chance: 7
diamond-chance: 3
# Core display rotation
rotation-step: 18
on script load:
set {asteroid.running} to false
set {asteroid.hits} to 0
set {asteroid.spawned} to 0
command /asteroid [<text>] [<number>]:
permission: {@permission}
permission message: "{@prefix} &cYou do not have permission to use this command."
trigger:
if arg-1 is not set:
send "{@prefix} &e/asteroid hit <amount> &7- Run until the specified number of asteroids hit the ground."
send "{@prefix} &e/asteroid start <seconds> &7- Run the event for the specified duration."
send "{@prefix} &e/asteroid stop &7- Stop the current event."
send "{@prefix} &e/asteroid status &7- View the current event status."
stop
if arg-1 is "hit":
if arg-2 is not set:
send "{@prefix} &cUsage: /asteroid hit <amount>"
stop
if sender is not a player:
send "{@prefix} &cThis command must be used by a player."
stop
if {asteroid.running} is true:
send "{@prefix} &cAn asteroid event is already running."
stop
if arg-2 is less than 1:
send "{@prefix} &cThe hit amount must be at least 1."
stop
set {asteroid.center} to location of player
set {asteroid.mode} to "hits"
set {asteroid.limit} to arg-2
set {asteroid.duration} to 0
set {asteroid.hits} to 0
set {asteroid.spawned} to 0
set {asteroid.started} to now
set {asteroid.running} to true
send "{@prefix} &aStarted an asteroid event for &e%arg-2% &aimpacts."
runAsteroidEvent()
stop
if arg-1 is "start":
if arg-2 is not set:
send "{@prefix} &cUsage: /asteroid start <seconds>"
stop
if sender is not a player:
send "{@prefix} &cThis command must be used by a player."
stop
if {asteroid.running} is true:
send "{@prefix} &cAn asteroid event is already running."
stop
if arg-2 is less than 1:
send "{@prefix} &cThe duration must be at least 1 second."
stop
set {asteroid.center} to location of player
set {asteroid.mode} to "time"
set {asteroid.limit} to 0
set {asteroid.duration} to arg-2
set {asteroid.hits} to 0
set {asteroid.spawned} to 0
set {asteroid.started} to now
set {asteroid.running} to true
send "{@prefix} &aStarted an asteroid event for &e%arg-2% &aseconds."
runAsteroidEvent()
stop
if arg-1 is "stop":
if {asteroid.running} is false:
send "{@prefix} &eThere is no asteroid event running."
stop
set {asteroid.running} to false
send "{@prefix} &cAsteroid event stopped. &7Impacts: &e%{asteroid.hits}%"
stop
if arg-1 is "status":
if {asteroid.running} is false:
send "{@prefix} &7No asteroid event is currently running."
stop
if {asteroid.mode} is "hits":
send "{@prefix} &aEvent active. &7Impacts: &e%{asteroid.hits}%&7/&e%{asteroid.limit}%"
else:
send "{@prefix} &aEvent active. &7Impacts: &e%{asteroid.hits}% &7| Duration: &e%{asteroid.duration}% seconds"
stop
send "{@prefix} &cUnknown subcommand. Use &e/asteroid &cfor help."
function runAsteroidEvent():
while {asteroid.running} is true:
if {asteroid.mode} is "hits":
if {asteroid.hits} is greater than or equal to {asteroid.limit}:
set {asteroid.running} to false
stop
if {asteroid.mode} is "time":
if difference between now and {asteroid.started} is greater than or equal to {asteroid.duration} seconds:
set {asteroid.running} to false
stop
spawnAsteroid()
wait {@spawn-interval}
if {asteroid.mode} is "hits":
broadcast "{@prefix} &aAsteroid event complete! &7Total impacts: &e%{asteroid.hits}%"
else:
broadcast "{@prefix} &aAsteroid event complete! &7Total impacts: &e%{asteroid.hits}%"
function spawnAsteroid():
set {_impact} to {asteroid.center}
# Randomize the impact point around the command location.
add random integer between -{@impact-radius} and {@impact-radius} to x-coordinate of {_impact}
add random integer between -{@impact-radius} and {@impact-radius} to z-coordinate of {_impact}
# Asteroids approach from the positive X direction.
set {_current} to {_impact}
add {@flight-distance} to x-coordinate of {_current}
add {@flight-height} to y-coordinate of {_current}
set {_pieces::*} to nothing
# Create the visible asteroid chunks as falling blocks.
loop {@asteroid-piece-count} times:
set {_piece-location} to {_current}
add random integer between -{@asteroid-piece-radius} and {@asteroid-piece-radius} to x-coordinate of {_piece-location}
add random integer between -{@asteroid-piece-radius} and {@asteroid-piece-radius} to y-coordinate of {_piece-location}
add random integer between -{@asteroid-piece-radius} and {@asteroid-piece-radius} to z-coordinate of {_piece-location}
spawn falling block at {_piece-location}
set {_piece} to last spawned entity
set block data of {_piece} to {@asteroid-block}
set gravity of {_piece} to false
add {_piece} to {_pieces::*}
# Create the rotating magma block as a SkBee block display.
spawn a block display at {_current}
set {_core} to last spawned entity
set display block of {_core} to magma block
set display scale of {_core} to vector(1.5, 1.5, 1.5)
set {_rotation} to 0
while y-coordinate of {_current} is greater than y-coordinate of {_impact}:
subtract {@asteroid-speed} from x-coordinate of {_current}
subtract {@asteroid-fall-speed} from y-coordinate of {_current}
loop {_pieces::*}:
set {_piece-location} to location of loop-value