#GUI Open/Close issue
1 messages · Page 1 of 1 (latest)
The written skript is not mine, simply trying to debug it and fix it to work properly.
function spawnershop(p: player):
set {_spawner::1} to "ooooooooo"
set {_spawner::2} to "o1234567o"
set {_spawner::3} to "o89bcde-o"
set {_spawner::4} to "o-------o"
set {_spawner::5} to "ooooooooo"
create a gui with id "spawnershop" with virtual chest with 5 rows named " &c&lSpawner &f&lShop" and shape {_spawner::*}:
make gui "o" with white stained glass pane named " "
set {_zombie} to skull of "MHF_Zombie" parsed as an offline player
make gui "1" with {_zombie} named "&c&lZombie Spawner" with lore "%nl% &7&lPrice: &f{@ZombiePrice}&a $ %nl% &7&lAmount: &f{@ZombieAmount}":
execute player command "/zombiespawner"
open gui "spawnershop" to {_p}
command /spawnershop:
trigger:
spawnershop(player)
```
Original Skript
https://www.spigotmc.org/resources/spawner-shop-skript.114535/
I think it is because it is a function, try to put it in the command and it will be fixed.
I was thinking the same, that's what I was noticing
That shouldn’t be the problem
I believe it’s because he’s creating another gui with the same id
I could be wrong though
ohh yes it could be that, I didn't realize it
Ahh, yeah I didnt think about that
every time the commands ran, it creates a new one
Would I on script load: the gui creation, and then simply show the gui
open gui with id "myGlobalGUI" to player
Working with skript makes me glad I learned LUA while back, syntax isn't that far off
I'm gonna give it a go
I don't use skript-gui but you could do something like open gui with id "gui:%player%" to player
I got it fixed 😄
Time to dm the creator and tell him the fix lol
@foggy ocean I fixed it 😄
damn
@hazy gorge
This, the commands and other information are essentiallly all the same, just name and var name changes
I could make something like this in LUA in about 20 lines ish
??
the ping
I left a review on the page and he said to dm him on discord, but he's not accepting friend requests or messages, so I pinged him here.
god
what the hell
number one
functions exist
number two
use loops
I know, but working with what someone else did sometimes just doesn't end well without completely starting over
I feel like you're sitting there rewriting the entire thing xD
function shop_getGUI(shop: string) :: gui inventory:
create gui blah blah:
set {_shopGUI} to (last created gui)
loop (indexes of {-shop::spawners::items::*}):
set {_varPath} to "%{_shop}%::items::%loop-value%"
set {_item} to {-shop::%{_varPath}%::item}
set {_slot} to {-shop::%{_varPath}%::slot}
set {_buyAmount} to {-shop::%{_varPath}%::buyAmount}
make gui {_slot} with {_item}:
shop_buyItem(player, {_item}, {_buyAmount})
return {_shopGUI}
function shop_buyItem(player: player, item: number, buyAmount: number):
if {-data::%{_player}'s uuid%::money} < {_buyAmount}:
send "Not enough money" to {_player}
stop
if {_player} doens't have enough space for {_item}:
send "Not enough space for item" to {_player}
stop
remove {_buyAmount} from {-data::%{_player}'s uuid%::money}
give player {_item}
command shop:
trigger:
open (shop_getGUI("spawners")) for {_player}
You were lol
now all you need is a way to set the variables
i would personally use skript-yaml for a yaml config
and cache all the values inside of the yaml config into the ram variables
I'm gonna look into that
for example:
shop-id: "spawners"
items:
cow:
shop-item:
item: whatever the spawner itemtype is
name: "&dCow Spawner"
lore:
- "&dCow Spawner"
slot: 30
buy-amount: 69420
creeper:
shop-item:
item: whatever the spawner itemtype is
name: "&dCreeper Spawner"
lore:
- "&dCreeper Spawner"
slot: 31
buy-amount: 69420```
#CACHING
on load:
shop_reload()
function shop_reload():
delete {-shop::*}
set {_yamlPath} to "path/to/yaml-file"
loop files_getFilesInFolder({_yamlPath}):
set {_file} to loop-value
set {_yaml} to "shop-%{_file}%"
load yaml "%{_yamlPath}%/%{_file}%" as {_yaml}
set {_shopID} to (yaml value "shop-id" from {_yaml})
loop (yaml node keys "items" from {_yaml}):
set {_itemID} to loop-value
set {_varPath} to "%{_shop}%::items::%{_itemID}%"
set {-shop::%{_varPath}%::item} to yaml_getItemFromPath({_yaml}, "items.%{_itemID}%.shop-item")
set {-shop::%{_varPath}%::slot} to (yaml value "items.{_itemID}.slot" from {_yaml})
set {-shop::%{_varPath}%::buyAmount} to (yaml value "items.{_itemID}.buy-amount" from {_yaml})
unload yaml {_yaml}```
You're a real one man lol
Yup already grabbed it and was reading documentation
aswell, add these to a utils file
import:
java.io.File
function getFolderFiles(folder: string) :: strings:
set {_folder} to new File({_folder})
set {_filesInFolder} to {_folder}.listFiles()
loop (...{_filesInFolder}):
set {_value} to loop-value
if ({_value}.isFile()) = true:
add {_value}.getName() to {_files::*}
return {_files::*}
function yaml_getItemFromPath(yaml: string, path: string) :: item:
set {_item} to (yaml_getValue({_yaml}, "%{_path}%.item") parsed as item)
set ({_item}'s custom model data) to yaml_getValue({_yaml}, "%{_path}%.custom-model-data")
set (name of {_item}) to formatted yaml_getValue({_yaml}, "%{_path}%.name")
set (lore of {_item}) to formatted yaml_getList({_yaml}, "%{_path}%.lore")
loop yaml_getNodes({_yaml}, "%{_path}%.nbt"):
set {_node} to loop-value
set {_yamlPath} to "%{_path}%.nbt.%{_node}%"
set {_tag} to yaml_getValue({_yaml}, "%{_yamlPath}%.tag")
set {_tagType} to (yaml_getValue({_yaml}, "%{_yamlPath}%.tag-type") parsed as nbt type)
set {_tagValue} to yaml_getValue({_yaml}, "%{_yamlPath}%.tag-value")
set ({_tagType} {_tag} of nbt compound of {_item}) to {_tagValue}
return {_item}```
You just did it far faster than I would lol
does utils file need any specific name or folder structure?
no
Or just a .sk
just a .sk
Alrighty ❤️ Appreciate you man
you can make a utils folder and create a utils.sk
which is what i would do
but it really doesnt matter
Alrighty, I will do that, and this is good knowledge to know, I appreciate you taking the time to do that
yeah no problem
@hazy gorgethis made me chuckle a bit buy-amount: 69420
lmao
I'm assuming this goes in the main .sk file?
the second bit, not the first
the yaml config goes into a yaml file, the function goes into wherever you have this skript
@hazy gorge
https://i.imgur.com/S3Lqsnn.png
I thought I renamed everything properly, but guess not?
read the errors
I am down to 3 now
The loop value one I think is the one I don't understand the most.
This specifically erroring set {_itemID} to loop-value
when you are in multiple loops, skript doesnt know what value you are talking about
loop-value = x```
```loop 69 times:
loop 420 times:
loop-value is unknown and you need to replace it with either loop-value-1 or loop-value-2```
in this case we need to access the value from the second loop
So skript is unable to realize that the second loop-value is meant to be what is pulled from "items"?
Instead of loop getFolderFiles({_yamlPath}):
Okay, now Im down to just no player in function event errors
Well, no errors now, but unsure why GUI isn't opening lel
@hazy gorgeSorry to continually bother you, but somehow I broke it lol
All of a sudden its now yelling about the Skript-yaml functions not existing?
that's not even skript-yaml syntax, that's skript-reflect
if you have Skript 2.8+, you need reflect 2.4
Oh, that I didn't know
sorry didn’t see this, did you fix it?