item loottables

mail@pastecode.io avatar
unknown
plain_text
2 years ago
7.9 kB
2
Indexable
Never
#-------------------------Item Lists Calculate--------------------

function getItems(y:number, mined:boolean = false) :: objects:
	if {_mined} is true:
		if {tempitems::%{_y}%::*} exists:
			return {tempitems::%{_y}%::*}
	loop {items::%{_y}%::*}:
		set {_item} to loop-value
		add loop-value to {_list::*}
	loop 1001 times:
		{_y}+loop-number-1 - 501 is not {_y}
		loop {items::%{_y}+loop-number-1 - 501%::*}:
			set {_spreadamount} to "spreadamount" tag of nbt of loop-value-2
			set {_y2} to {_y}+loop-number-1 - 501
			set {_dif} to difference between {_y} and {_y2}
			if {_dif} <= {_spreadamount}:
				set {_item} to loop-value-2
				set {_chance} to "chance" tag of nbt of {_item}
				set {_amount} to {_chance}/({_spreadamount}+1)
				remove {_dif}*{_amount} from {_chance}
				add "{chance:%{_chance}%}" to nbt of {_item}
				add {_item} to {_list::*}
	tempList({_list::*},{_y})
	return {_list::*}

function tempList(list:objects,y:number):
	set {tempitems::%{_y}%::*} to {_list::*}
	wait 3 minutes
	delete {tempitems::%{_y}%::*}

on skript stop:
	loop 500 times:
		delete {tempitems::%loop-number - 85%::*}

#----------------------Item value changing in GUI-------------------

on inventory click:
	loop 5 times:
		if event-inventory = (metadata tag "checkitems%loop-number%" of player):
			cancel event
			if click action is not left mouse button:
				click action is not right mouse button with shift
				set metadata value "item" of player to clicked item
				close player's inventory
			if click action is left mouse button:
				set {_item} to clicked item
				set {_y} to "y" tag of nbt of clicked item
				loop {items::%{_y}%::*}:
					if checkSameItem({_item},loop-value-2) is true:
						give player loop-value-2
			else if click action is right mouse button with shift:
				set {_item} to clicked item
				set {_y} to "y" tag of nbt of {_item}
				delete lore of {_item}
				remove {_item} from {items::%{_y}%::*}
				give {_item} to player
				set {_y2} to metadata value "currentY.checkitems" of player
				close player's inventory
				wait 1 tick
				itemgui(player,{_y2})
			else if click action is right mouse button:
				set metadata value "chat" of player to "chance"
			else if click action is middle mouse button:
				set metadata value "chat" of player to "spreadamount"
			else if click action is number key:
				set metadata value "chat" of player to "y"
			else if click action is drop key:
				set metadata value "chat" of player to "value"
			else if click action is drop key with control:
				set metadata value "chat" of player to "damage"

on chat:
	if metadata value "chat" of player is set:
		set {_newvalue} to message parsed as a number
		if {_newvalue} >= 0:
			set {_changedvalue} to metadata value "chat" of player
			set {_item} to metadata value "item" of player
			delete lore of {_item}
			set {_y} to "y" tag of nbt of {_item}
			loop {items::%{_y}%::*}:
				if checkSameItem({_item},loop-value) is true:
					remove {_item} from {items::%{_y}%::*}
					add "{%{_changedvalue}%:%{_newvalue}%}" to nbt of loop-value
					if {_changedvalue} is "y":
						set {_y} to {_newvalue}
					add loop-value to {items::%{_y}%::*}
					delete metadata value "chat" of player
					delete metadata value "item" of player
					itemgui(player,{_y})
					cancel event
					stop

function checkSameItem(item1:item,item2:item) :: boolean:
	if "%{_item1}%" = "%{_item2}%":
		if "damage" tag of nbt of {_item1} is set:
			"damage" tag of nbt of {_item1} != "damage" tag of nbt of {_item2}
			return false
		if "value" tag of nbt of {_item1} is set:
			"value" tag of nbt of {_item1} != "value" tag of nbt of {_item2}
			return false
		return true
	return false
#-----------------------Adding Items-----------------------------

function addItem(item:item,chance:number,y:number,spreadamount:number,damage:number):
	add "{chance:%{_chance}%}" to nbt of {_item}
	add "{y:%{_y}%}" to nbt of {_item}
	add "{spreadamount:%{_spreadamount}%}" to nbt of {_item}
	if {_damage} is set:
		add "{damage:%{_damage}%}" to nbt of {_item}
	add {_item} to {items::%{_y}%::*}

on inventory click:
	if metadata value "addingitems" of player is set:
		if event-inventory = inventory of player:
			if click action is left mouse button:
				cancel event
				addItemToLayer(clicked item,player)
			else if click action is left mouse button with shift:
				cancel event
				addItemToLayer(clicked item,player)

function addItemToLayer(item:item,p:player):
	set {_chance} to "chance" tag of nbt of {_item}
	set {_spread} to "spreadamount" tag of nbt of {_item}
	set {_y} to metadata value "currentY.checkitems" of {_p}
	set {_damage} to "damage" tag of nbt of {_item}
	if {_chance} is not set:
		stop
	if {_spread} is not set:
		set {_spread} to 20
	addItem({_item},{_chance},{_y},{_spread},{_damage})
	close {_p}'s inventory
	wait 1 tick
	itemgui({_p},{_y})
	

on inventory close:
	if metadata value "addingitems" of player is set:
		delete metadata value "addingitems" of player

#---------------------------Items GUI-----------------------------

function itemgui(p:player,yvalue:number):
	set {_now} to now
	set {_n} to 1
	loop 5 times:
		set metadata tag "checkitems%loop-number%" of {_p} to chest inventory with 6 rows named "&0&lItems on Y:%{_yvalue}%        &0Page %loop-number%"
		set slot 53 of metadata tag "checkitems%loop-number%" of {_p} to lime stained glass pane named "&aNext Page"
		set slot 45 of metadata tag "checkitems%loop-number%" of {_p} to red stained glass pane named "&cPrevious Page"
	set metadata value "currentY.checkitems" of {_p} to {_yvalue}
	set metadata value "addingitems" of {_p} to true
	set {_list::*} to getItems({_yvalue})
	loop 5 times:
		loop {_list::*}:
			set {_item} to loop-value-2
			remove {_item} from {_list::*}
			set {_item} to addGuiLore({_item})
			set slot 0+{_loopnumber} of metadata tag "checkitems%loop-number-1%" of {_p} to {_item}
			add 1 to {_loopnumber}
			if {_loopnumber} >= 45:
				delete {_loopnumber}
				add 1 to {_n}
				exit 1 loop
	open (metadata tag "checkitems1" of {_p}) to {_p}
	send difference between now and {_now} to {_p}

on inventory click:
	loop 5 times:
		if event-inventory is (metadata tag "checkitems%loop-number%" of player):
			if clicked item is lime stained glass pane:
				cancel event
				close player's inventory
				wait 1 tick
				open (metadata tag "checkitems%loop-number + 1%" of player) to player
				set metadata value "addingitems" of player to true
			else if clicked item is red stained glass pane:
				cancel event
				close player's inventory
				wait 1 tick
				open (metadata tag "checkitems%loop-number - 1%" of player) to player
				set metadata value "addingitems" of player to true
			
function addGuiLore(item:item) :: item:
	set {_chance} to "chance" tag of nbt of {_item}
	set {_y} to "y" tag of nbt of {_item}
	set {_spread} to "spreadamount" tag of nbt of {_item}
	set {_value} to "value" tag of nbt of {_item}
	set {_damage} to "damage" tag of nbt of {_item}
	set {_armor} to "armor" tag of nbt of {_item}
	if {_damage} is not set:
		set {_damage} to 0
	if {_armor} is not set:
		set {_armor} to 0
	add " " to lore of {_item}
	add "&6Value: &7%{_value}%" to lore of {_item}
	add "&cDamage/Power/Armor/Luck: &7%{_damage}%" to lore of {_item}
	add " " to lore of {_item}
	add "&aChance: &7%{_chance}%%%" to lore of {_item}
	add "&bBase Y Level: &7%{_y}%" to lore of {_item}
	add "&6Layer Spread: &7%{_spread}%" to lore of {_item}
	add " " to lore of {_item}
	add "&aLMB: &7Get item" to lore of {_item}
	add "&6RMB: &7Change chances" to lore of {_item}
	add "&9MMB: &7Change layer spread" to lore of {_item}
	add "&cShift + RMB: &7Remove item" to lore of {_item}
	add "&fDrop Key: &7Change Value" to lore of {_item}
	add "&2Number Key: &7Change Base Y" to lore of {_item}
	add "&5Drop Key with Control: &7Change Damage/Power" to lore of {_item}
	return {_item}