discofloors.sk

Created by PatoFrango

Other available versions. Ordered by newest to oldest versions:

Just so you know, we don't know the file format for every file. If it's just a bunch of random characters, it's probably a .zip or .jar.

#----- DiscoFloors, a script by PatoFrango -----#

options:
	prefix: &e[DF]
	permission: discofloors

on leftclick:
	{discoFloors::%player%::creating} is set
	player's tool is air
	cancel event
	set {discoFloors::%player%::pos::1} to location at clicked block
	send "{@prefix} &fFirst position set to (%x-pos of clicked block%, %y-pos of clicked block%, %z-pos of clicked block%)"

on rightclick:
	{discoFloors::%player%::creating} is set
	player's tool is air
	cancel event
	set {discoFloors::%player%::pos::2} to location at clicked block
	send "{@prefix} &fSecond position set to (%x-pos of clicked block%, %y-pos of clicked block%, %z-pos of clicked block%)"

command /discofloor <text> [<text>] [<text>] [<text>]:
	aliases: /df
	permission: {@permission}
	trigger:
		if arg-1 is "create":
			send "{@prefix} &fDisco floor creation mode: &aON"
			set {discoFloors::%player%::creating} to true
		else if arg-1 is "off" or "exit" or "false":
			send "{@prefix} &fDisco floor creation mode: &cOFF"
			delete {discoFloors::%player%::*}
		else if arg-1 is "list":
			discoFloorList(player)
		else if arg-1 is "stopall":
			send "{@prefix} &fStopped all disco floors."
			loop {discoFloorIDs::*}:
				discoFloorStop(loop-value)
		else if arg-1 is "startall":
			send "{@prefix} &fStarted all disco floors."
			loop {discoFloorIDs::*}:
				discoFloorStart(loop-value)
		else if arg-1 is "set":
			if {discoFloors::%player%::creating} is not set:
				send "{@prefix} &cDo &e/df create &cto enter the disco floor editor!"
				stop
			arg-2, arg-3, arg-4 are set
			set {_speed} to arg-3 parsed as number
			{_speed} is a number # to make sure there wasn't a parsing error
			if discoFloorExists(arg-2) is false:
				set {_blocks::*} to discoFloorChangeBlocksFromString(arg-4)
				discoFloorCreate(arg-2, {discoFloors::%player%::pos::1}, {discoFloors::%player%::pos::2}, {_speed}, {_blocks::*})
				delete {discoFloors::%player%::creating} and {discoFloors::%player%::pos::*}
				send "{@prefix} &fSuccessfully created disco floor &a%arg-2%&f!"
			else:
				send "{@prefix} &cThe disco floor &e%arg-2% &calready exists."
		else if arg-2 is not set:
			send "{@prefix} &cPlease specify the name of the disco floor."
		else if discoFloorExists(arg-2) is false:
			send "{@prefix} &cThe disco floor &e%arg-2% &cdoesn't exist."
		else if arg-1 is "remove" or "delete":
			send "{@prefix} &fDeleted disco floor &e%arg-2%"
			discoFloorDelete(arg-2)
		else if arg-1 is "start":
			if discoFloorIsPlaying(arg-2) is false:
				send "{@prefix} &fStarted disco floor &e%arg-2%"
				discoFloorStart(arg-2)
			else:
				send "{@prefix} &cThe disco floor &e%arg-2% &cis already playing."
		else if arg-1 is "stop":
			if discoFloorIsPlaying(arg-2) is true:
				send "{@prefix} &fStopped disco floor &e%arg-2%"
				discoFloorStop(arg-2)
			else:
				send "{@prefix} &cThe disco floor &e%arg-2% &cis not playing."
		else if arg-1 is "changeblocks":
			set {_blocks::*} to discoFloorChangeBlocksFromString(arg-3)
			send "{@prefix} &fChanged disco floor blocks of &e%arg-2% &fto &a%{_blocks::*}%"
			discoFloorChangeBlocks(arg-2, {_blocks::*})
		else:
			send "{@prefix} &cUnknown arguments."
	
function discoFloorList(p: player):
	loop {discoFloorIDs::*}:
		set {_size} to size of {discoFloorsDB::%loop-value%::locs::*}
		set {_pos1} to {discoFloorsDB::%loop-value%::pos1}
		set {_pos2} to {discoFloorsDB::%loop-value%::pos2}
		add "<tooltip:&eLocation: &7(%x-pos of {_pos1}%, %y-pos of {_pos1}%, %z-pos of {_pos1}% / %x-pos of {_pos2}%, %y-pos of {_pos2}%, %z-pos of {_pos2}%) in %world of {_pos1}%>&e%loop-value%&f" to {_floors::*}
	send "{@prefix} &fList of created disco floors (hover over names for details): %{_floors::*}%" to {_p}

on quit:
	delete {discoFloors::%player%::*}

on skript start:
	loop {discoFloorIDs::*}:
		{discoFloorsDB::%loop-value%::playing} is set
		delete {discoFloorsDB::%loop-value%::playing}
		discoFloorStart(loop-value)
		
on skript stop:
	delete {discoFloors::*}
	
#----- API -----#
	
function discoGetArea(pos1: location, pos2: location) :: locations:
	loop integers between floor(y-pos of {_pos1}) and floor(y-pos of {_pos2}):
		loop integers between floor(z-pos of {_pos1}) and floor(z-pos of {_pos2}):
			loop integers between floor(x-pos of {_pos1}) and floor(x-pos of {_pos2}):
				set {_loc} to location at loop-value-3, loop-value-1, loop-value-2 in world of {_pos1}
				add {_loc} to {_locs::*}
	return {_locs::*}
	
function discoFloorCreate(id: text, pos1: location, pos2: location, speed: number, blocks: objects):
	add {_id} to {discoFloorIDs::*}
	set {discoFloorsDB::%{_id}%::locs::*} to discoGetArea({_pos1}, {_pos2})
	discoFloorChangeBlocks({_id}, {_blocks::*})
	set {discoFloorsDB::%{_id}%::speed} to {_speed}
	set {discoFloorsDB::%{_id}%::pos1} to {_pos1}
	set {discoFloorsDB::%{_id}%::pos2} to {_pos2}
	discoFloorStart({_id})

function discoFloorStart(id: text):
	discoFloorIsPlaying({_id}) is false
	set {discoFloorsDB::%{_id}%::playing} to true
	while {discoFloorsDB::%{_id}%::playing} is set:
		set {_times} to {discoFloorsDB::%{_id}%::speed} / 0.1
		loop {discoFloorsDB::%{_id}%::locs::*}:
			set {_blocks::*} to {discoFloorsDB::%{_id}%::blocks::*}
			set {_block} to random element out of {_blocks::*}
			make all players where [world of input is world of loop-value] see block at loop-value as {_block}
		loop {_times} times:
			if {discoFloorsDB::%{_id}%::playing} is not set:
				stop loop
			wait 0.1 second

function discoFloorStop(id: text):
	loop {discoFloorsDB::%{_id}%::locs::*}:
		make all players where [world of input is world of loop-value] see block at loop-value-1 as block at loop-value-1
	delete {discoFloorsDB::%{_id}%::playing}

function discoFloorExists(id: text) :: boolean:
	if {discoFloorsDB::%{_id}%::*} is set:
		return true
	return false
	
function discoFloorIsPlaying(id: text) :: boolean:
	if {discoFloorsDB::%{_id}%::playing} is set:
		return true
	return false

function discoFloorDelete(id: text):
	discoFloorStop({_id})
	remove {_id} from {discoFloorIDs::*}
	delete {discoFloorsDB::%{_id}%::*}

function discoFloorChangeBlocksFromString(string: text) :: items:
	set {_blocks::*} to {_string} split at ","
	set {_blocks::*} to discoFloorPreset({_blocks::*})
	loop {_blocks::*}:
		set {_blocks::%loop-index%} to {_blocks::%loop-index%} parsed as item
	return {_blocks::*}

function discoFloorPreset(blocks: objects) :: objects:
	if {_blocks::1} is "rainbow":
		return light green glass block, orange glass block, red glass block, light blue glass block, yellow glass block, white glass block and pink glass block
	return {_blocks::*}
	
function discoFloorChangeBlocks(id: text, blocks: objects):
	{discoFloorsDB::%{_id}%::*} is set
	set {_blocks::*} to discoFloorPreset({_blocks::*})
	set {discoFloorsDB::%{_id}%::blocks::*} to {_blocks::*}
	
function discoFloorChangeWorld(id: text, world: world):
	loop {discoFloorsDB::%{_id}%::locs::*}:
		set world of {discoFloorsDB::%{_id}%::locs::%loop-index%} to {_world}
		
function discoFloorChangeSpeed(id: text, speed: number):
	set {discoFloorsDB::%{_id}%::speed} to {_speed}