-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
test.sk
415 lines (355 loc) · 13.9 KB
/
test.sk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
#
# An example of opening a chest inventory with an item.
# Players will be able to take the item out.
#
command /simple chest:
permission: skript.example.chest
trigger:
set {_chest} to a new chest inventory named "Simple Chest"
set slot 0 of {_chest} to apple # Slots are numbered 0, 1, 2...
#
# An example of listening for click events in a chest inventory.
# This can be used to create fancy button-style interfaces for users.
#
command /chest menu:
permission: skript.example.menu
trigger:
set {_menu} to a new chest inventory with 1 row named "Simple Menu"
set slot 4 of {_chest} to stone named "Button" # Slots are numbered 0, 1, 2...
on inventory click: # Listen for players clicking in an inventory.
name of event-inventory is "Simple Menu" # Make sure it's our menu.
cancel event
if index of event-slot is 4: # The button slot.
send "You clicked the button."
else:
send "You didn't click the button."
#
# An example of making and filling a fancy inventory with a function.
# This demonstrates another way you can use chest inventories.
#
# If you wanted to test this example, you could open the result of `makeMenu` to a player.
#
aliases:
menu items = TNT, lava bucket, string, coal, oak planks
function makeMenu(name: text, rows: number) :: inventory:
set {_gui} to a new chest inventory with {_rows} rows with name {_name}
add {_name} to {inventory names::*}
loop {_rows} * 9 times: # Fill the inventory with random items.
set slot loop-number - 1 of {_gui} to random item out of menu items
return {_gui}
on inventory click: # Listen for players clicking in an inventory.
if {inventory names::*} contains name of event-inventory: # Make sure it's our menu.
cancel event
send "You clicked!"
on inventory close:
remove name of event-inventory from {inventory names::*}
#
#
# A very simple `broadcast` command for broadcasting the text argument.
# This is accessible only to users with the `skript.example.broadcast` permission.
#
command /broadcast <text>:
permission: skript.example.broadcast
description: Broadcasts a message to everybody.
trigger:
broadcast arg-text
#
# A simple /home command that allows players to set, remove and travel to homes.
# This command is executable only by players, and has a `correct usage` message.
# The first argument is required, whereas the second is optional.
#
command /home <text> [<text>]:
description: Set, delete or travel to your home.
usage: /home set/remove <name>, /home <name>
permission: skript.example.home
executable by: players
trigger:
if arg-1 is "set":
if arg-2 is set:
set {homes::%uuid of player%::%arg-2%} to player's location
send "Set your home <green>%arg-1%<reset> to <grey>%location of player%<reset>" to player
else:
send "You must specify a name for this home." to player
else if arg-1 is "remove":
if arg-2 is set:
delete {homes::%uuid of player%::%arg-2%}
send "Deleted your home <green>%arg-1%<reset>" to player
else:
send "You must specify the name of this home." to player
else if {homes::%uuid of player%::%arg-1%} is set:
teleport player to {homes::%uuid of player%::%arg-1%}
else:
send "You have home named <green>%arg-1%<reset>." to player
#
# An /item command that accepts Skript item aliases.
# E.g. `/item birch plank, 5 red wool and 17 iron ore`
# This command has aliases - alternative versions of the command that can be used.
#
aliases:
# Creates an alias `blacklisted` for this list of items.
blacklisted = TNT, bedrock, obsidian, mob spawner, lava, lava bucket
command /item <items>:
description: Give yourself some items.
usage: /item <items...>
aliases: /i
executable by: players
permission: skript.example.item
cooldown: 30 seconds
cooldown message: You need to wait %remaining time% to use this command again.
cooldown bypass: skript.example.cooldown
trigger:
if player has permission "skript.example.item.all":
give arguments to player
else:
loop arguments:
if loop-item is not blacklisted:
give loop-item to player
else:
send "<red>%loop-item%<reset> is blacklisted and cannot be spawned." to player
#
#
# This example listens for players joining and leaving.
# Alters the default message when they do.
#
on join:
set the join message to "Oh look, %player% joined! :)"
on quit:
set the quit message to "Oh no, %player% left! :("
#
# This example cancels damage for players if they have a specific permission.
# If they don't, tell them how much damage they took.
#
on damage:
victim is a player
if the victim has permission "skript.example.damage":
cancel the event # Stops the default behaviour - the victim taking damage.
else:
send "Ouch! You took %damage% damage." to the victim
add damage to {damage::%uuid of victim%::taken}
if the attacker is a player:
add damage to {damage::%uuid of victim%::dealt}
#
# This example allows players to wear specified blocks as hats.
# Listens for the clicking in the head slot and, if the player has permission, puts the item on their head.
#
aliases: # An alias for our allowed hat items.
custom helmets = iron block, gold block, diamond block
on inventory click:
event-slot is the helmet slot of player # Check that player clicked their head slot.
inventory action is place all or nothing
player has permission "skript.example.helmet"
cursor slot of player is custom helmets # Check if the item is in our custom alias.
cancel the event
set {_old helmet} to the helmet of player
set the helmet of player to the cursor slot of player
set the cursor slot of player to {_old helmet}
#
#
# A simple broadcasting function example.
# This demonstrates how to declare and run a simple function.
#
function sayMessage(message: text):
broadcast {_message} # our message argument is available in `{_message}`.
on first join:
wait 1 second
sayMessage("Welcome, %player%!") # Runs the `sayMessage` function.
#
# An example of a function with multiple parameters and a return type.
# This demonstrates how to return a value and use it.
#
function giveApple(name: text, amount: number) :: item:
set {_item} to an apple
set the name of {_item} to {_name}
set the item amount of {_item} to {_amount}
return {_item} # Gives this value to the code that called the function.
command /apple example:
permission: skript.example.apple
trigger:
send "Giving you an apple!"
set {_item} to giveApple("Banana", 4)
give player {_item}
#
# An example of a recursive (self-calling) function that is used to repeat a complex task.
# Please note that self-calling functions can loop infinitely, so use with caution.
#
function destroyOre(source: block) :: blocks:
add {_source} to {_found::*}
loop blocks in radius 1 of {_source}:
loop-block is any ore
break loop-block naturally using an iron pickaxe
if {_found::*} does not contain loop-block:
add destroyOre(loop-block) to {_found::*}
return {_found::*}
command /ore example:
permission: skript.example.ore
trigger:
send "Destroying all connected ore."
set {_found::*} to destroyOre(player's target block)
send "Destroyed %size of {_found::*}% connected ores!"
#
#
# Examples for two basic loops: one will run a set number of times, the other will run for all elements in a list.
# Multi-value expressions like `all players` can also be looped.
#
command /loop example:
permission: skript.example.loop
trigger:
set {_number} to 5
loop {_number} times: # Runs `{_number}` times.
send "The number is %loop-number%."
set {_list::*} to "apple", "banana" and "orange"
loop {_list::*}: # Runs for each value in the list.
send "The word is: %loop-value%"
#
# Examples for while-loops, which run as long as the condition is true.
# A while-loop can run indefinitely and freeze the server, so make sure to add a delay or an exit condition.
#
command /while example:
permission: skript.example.while
trigger:
set {_number} to 5
while {_number} is greater than 0:
send "The number is %{_number}%"
remove a random number between 0 and 2 from {_number}
send "Finished counting down."
while true is true: # this will run forever
add "banana" to {_list::*}
if size of {_list::*} is 10:
exit loop
send "The list has %size of {_list::*}% bananas."
#
# Examples for looping collections of specific types, such as players, blocks and items.
# This shows how loops can be used to simplify more complex actions.
#
command /another loop example:
permission: skript.example.loop
trigger:
send "Listing all players:"
loop all players: # Remember - player is the command sender, loop-player is the loop value.
send " - %loop-player%"
if loop-player has permission "skript.example.apple":
give loop-player an apple named "Potato"
set {_items::*} to stone, oak planks and an apple
loop {_items::*}:
send "%loop-index%. %loop-value%"
give loop-value to player
loop blocks in radius 2 of player:
loop-block is a chest
loop items of types ore and log: # Loop-block comes from the first loop, loop-item from the second.
inventory of loop-block contains loop-item
remove loop-item from the inventory of loop-block
send "Destroyed a %loop-item%!"
exit loop # Exits the item loop.
#
#
# A simple example of using an option to make a common value accessible through the file.
#
options:
my server name: Server Name
condition: player is alive
nice message: "You're alive!"
on join:
send "Welcome to {@my server name}"
# Options don't need `%...%` since they are raw inputs.
if {@condition}: # The raw `player is alive` is copied here during parsing.
send {@nice message}
#
# An example of custom aliases for groups of items.
# This can be used as a shorthand in code.
#
aliases:
pretty items = iron ingot, gold ingot, diamond
on join:
player has permission "skript.example.aliases"
give player random item out of pretty items # A random item from our alias.
#
# An example showing how default variables can be used.
# These are seen the first time they are loaded, but not overwritten if you change the file copy.
# They act like default variable values.
#
variables:
score::%player% = 100
some variable = "Hello"
command /variable test:
permission: skript.example.variables
trigger:
add 1 to {score::%player%}
send {some variable}
##
# This example schedules a repeating action to be run at a time in the *minecraft* world.
# Every minecraft day at 6 PM, the time is reset to 7 AM, making it always day.
#
at 18:00:
set the time to 7:00
#
# This example schedules a repeating action. Each time the delay elapses, the trigger will be run.
# The delay is in real-world time.
#
every 5 minutes:
broadcast "Did you know that five minutes have passed?"
loop all players:
if loop-player has permission "skript.example.apple":
give loop-player an apple
#
# This example shows how the `wait` effect can be used to delay code being run.
#
command /wait example:
permission: skript.example.wait
trigger:
send "Waiting for two seconds..."
wait 2 seconds
send "Finished waiting!"
send "Counting to five."
set {_count} to 0
while {_count} is less than 5:
wait 3 ticks # Minecraft game ticks: 20 ticks = 1 second.
add 0.5 to {_count}
send "Finished counting!"
#
#
# This example stores a time-stamp in the global `{timer}` variable.
# This variable is accessible everywhere, and will be saved when the server stops.
#
# The `{_difference}` variable is local and is different for each use of the command.
#
command /timer:
permission: skript.example.timer
trigger:
if {timer} is set:
set {_difference} to difference between {timer} and now
send "This command was last run %{_difference}% ago."
else:
send "This command has never been run."
set {timer} to now
#
# This example stores two items in a global list variable `{items::%uuid of player%::*}`.
# These items can then be recalled with the example `/outfit` command, which then clears the list.
#
on join:
set {items::%uuid of player%::helmet} to player's helmet
set {items::%uuid of player%::boots} to player's boots
send "Stored your helmet and boots."
command /outfit:
executable by: players
permission: skript.example.outfit
trigger:
give player {items::%uuid of player%::*} # gives the contents of the list
clear {items::%uuid of player%::*} # clears this list
send "Gave you the helmet and boots you joined with."
#
# An example of adding, looping and removing the contents of a list variable.
# This list variable is local, and so will not be kept between uses of the command.
#
command /shopping list:
permission: skript.example.list
trigger:
add "bacon" to {_shopping list::*}
add "eggs" to {_shopping list::*}
add "oats" and "sugar" to {_shopping list::*}
send "You have %size of {_shopping list::*}% things in your shopping list:"
loop {_shopping list::*}:
send "%loop-index%. %loop-value%"
send "You bought some %{_shopping list::1}%!"
remove "bacon" from {_shopping list::*}
send "Removing bacon from your list."
send "You now have %size of {_shopping list::*}% things in your shopping list."