shop with refreshing items

mail@pastecode.io avatar
unknown
plain_text
3 years ago
6.9 kB
2
Indexable
on rightclick on player:
	if name of event-entity is "shop":
		openShop(player,"shop")

command /shop:
	trigger:
		openShop(player,"shop")

command /add.toshop.list <text> <number> <number> [<number>]:
	permission:op
	trigger:
		set {_item} to tool of player
		add "{value:%arg-2%}" to nbt of {_item}
		add "{price:%arg-3%}" to nbt of {_item}
		if arg-4 is set:
			add "{damage:%arg-4%}" to nbt of {_item}
		add {_item} to {shop.items.%arg-1%::*}

on tab complete of "/add.toshop.list":
	set tab completions for position 1 to "shovel", "fishing", "weapon", "armor" and "block", "refresh"
	set tab completions for position 2 to "value"
	set tab completions for position 3 to "price"
	set tab completions for position 4 to "damage"

on inventory click:
	set {_item} to clicked item
	if event-inventory is {shop}:
		cancel event
		if clicked item is iron shovel:
			open {shop.shovel} for player
		else if clicked item is fishing rod:
			open {shop.fishing} for player
		else if clicked item is stone bricks:
			open {shop.block} for player
		else if clicked item is wooden sword:
			open {shop.weapon} for player
		else if clicked item is netherite chestplate:
			open {shop.armor} for player
		if "stoptimer" tag of nbt of clicked item is set:
			set {_item} to clicked item
			set {_lore::*} to lore of {_item}
			loop 3 times:
				remove last element of {_lore::*} from {_lore::*}
			set lore of {_item} to {_lore::*}
			set {_item} to removeNBT({_item},"stoptimer",false)
			set {_price} to "price" tag of nbt of {_item}
			if {coins::%uuid of player%} >= {_price}:
				set {_slot} to index of clicked slot - 11
				set metadata value "shop" of player to chest inventory with 5 rows named "&0&lShop"
				set {_items::*} to items in {shop}
				loop {_items::*}:
					add 1 to {_loopnumber}
					set slot {_loopnumber}-1 of metadata value "shop" of player to loop-value
				set metadata value "slot%{_slot}%" of player to index of clicked slot
				add player to {buylist::*}
				openShop(player,"shop")
			else:
				cancel event
				stop
			buyItem(player,{_price},{_item})
			while {shop} is set:
				if {buylist::*} does not contain player:
					exit 1 loop
				loop 3 times:
					delete {_item%loop-number%}
				set {_item} to slot 12 of {shop}
				set {_timer} to "stoptimer" tag of nbt of {_item} - 1
				set {_minutes} to floor({_timer}/60)
				set {_seconds} to {_timer} - {_minutes}*60
				if {_seconds} < 10:
					set {_line} to "<##FFD57E>&nRefreshes in <##FCA652>&n%{_minutes}%:0%{_seconds}%"
				else:
					set {_line} to "<##FFD57E>&nRefreshes in <##FCA652>&n%{_minutes}%:%{_seconds}%"
				loop 3 times:
					if metadata value "slot%loop-number%" of player is not set:
						set {_item%loop-number%} to slot 11 + loop-number of {shop}
						set {_timer} to "stoptimer" tag of nbt of {_item%loop-number%} - 1
						add "{stoptimer:%{_timer}%}" to nbt of {_item%loop-number%}
						if {_seconds} < 10:
							set line {_line%loop-number%} of lore of {_item%loop-number%} to "<##FFD57E>&nRefreshes in <##FCA652>&n%{_minutes}%:0%{_seconds}%"
						else:
							set line {_line%loop-number%} of lore of {_item%loop-number%} to "<##FFD57E>&nRefreshes in <##FCA652>&n%{_minutes}%:%{_seconds}%"
						set slot 11 + loop-number of metadata value "shop" of player to {_item%loop-number%}
				set {_item} to barrier named "&cOut of stock"
				add "" to lore of {_item}
				add {_line} to lore of {_item}
				loop 3 times:
					set slot metadata value "slot%loop-number%" of player of metadata value "shop" of player to {_item}
				wait 1 second
	else if event-inventory = metadata value "shop" of player:
		cancel event
		if clicked item is iron shovel:
			open {shop.shovel} for player
		else if clicked item is fishing rod:
			open {shop.fishing} for player
		else if clicked item is stone bricks:
			open {shop.block} for player
		else if clicked item is wooden sword:
			open {shop.weapon} for player
		else if clicked item is netherite chestplate:
			open {shop.armor} for player
		if "stoptimer" tag of nbt of clicked item is set:
			set {_item} to clicked item
			set {_lore::*} to lore of {_item}
			loop 3 times:
				remove last element of {_lore::*} from {_lore::*}
			set lore of {_item} to {_lore::*}
			set {_item} to removeNBT({_item},"stoptimer",false)
			set {_price} to "price" tag of nbt of {_item}
			if {coins::%uuid of player%} >= {_price}:
				set {_slot} to index of clicked slot - 11
				metadata value "slot%{_slot}%" of player is not set
				set metadata value "slot%{_slot}%" of player to index of clicked slot
				set slot index of clicked slot of metadata value "shop" of player to barrier named "&cOut of stock"
			buyItem(player,{_price},{_item})
	if event-inventory is {shop.shovel}:
		cancel event
		set {_price} to "price" tag of nbt of {_item}
		buyItem(player,{_price},{_item})
	else if event-inventory is {shop.fishing}:
		cancel event
		set {_price} to "price" tag of nbt of {_item}
		set {_power} to "damage" tag of nbt of {_item}
		send {_power}
		buyItem(player,{_price},{_item})
	else if event-inventory is {shop.block}:
		set {_price} to "price" tag of nbt of {_item}
		buyItem(player,{_price},{_item})
		cancel event
	else if event-inventory is {shop.weapon}:
		set {_price} to "price" tag of nbt of {_item}
		buyItem(player,{_price},{_item})
		cancel event
	else if event-inventory is {shop.armor}:
		set {_price} to "price" tag of nbt of {_item}
		buyItem(player,{_price},{_item})
		cancel event

on server stop:
	delete {buylist::*}

on script load:
	delete {shop}
	wait 2 second
	set {shop} to chest inventory with 5 rows named "&0&lShop"
	set slot (integers between 0 and 53) of {shop} to gray stained glass pane named "&7"
	set slot (12,13,14) of {shop} to barrier named "<##FCA652>Item"
	set slot 29 of {shop} to iron shovel named "<##FCA652>Shovels" with all flags hidden
	set slot 30 of {shop} to fishing rod named "<##FCA652>Fishing Rods" with all flags hidden
	set slot 31 of {shop} to stone bricks named "<##FCA652>Blocks" with all flags hidden
	set slot 32 of {shop} to wooden sword named "<##FCA652>Weapons" with all flags hidden
	set slot 33 of {shop} to netherite chestplate named "<##FCA652>Armor" with all flags hidden
	refreshShop("shop","",500,3)
	set {_list::*} to "shovel", "fishing", "block", "weapon" and "armor"
	
	loop {_list::*}:
		delete {_loopnumber}
		set {_s} to capitalizeFirst(loop-value)
		if size of {shop.items.%loop-value%::*} < 6:
			set {shop.%loop-value%} to hopper inventory named "&0&l%{_s}% Shop"
		else:
			set {shop.%loop-value%} to chest inventory with 1 rows named "&0&l%{_s}% Shop"
		set slot (integers between 0 and 53) of {shop.%loop-value%} to gray stained glass pane named "&7"
		loop {shop.items.%loop-value%::*}:
			add 1 to {_loopnumber}
			set {_item} to loop-value-2
			set {_item} to setItemLore({_item},true,true)
			set slot {_loopnumber} - 1 of {shop.%loop-value-1%} to {_item}