Paste #63720: bot test

Date: 2020/01/07 14:40:23 UTC-08:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


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
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474


#todo
    #change soldier and farmer flag to contain their respective id to enable them to be removed remotely
    #use the break command with farmers after it gets fixed
    #convert npc limit to map of profession/number and track the owned npc objects
    #todo add sensible spawn mechanic
mayor_script:
    type: world
    events:

        #gives mayor spawn item
        on player right clicks stone_bricks with wheat:
        - wait 1t
        - take iteminhand
        - drop mayor_placer <context.location>

        on player right clicks block with mayor_placer:
        #check if the player already has a mayor, if not take the spawn item and spawn the mayor
        - if !<player.has_flag[owned_npcs_mayor]>:
            - determine passively cancelled
            - wait 1t
            - take iteminhand
            - create player mayor <context.location.add[0,2,0]> save:mayor_obj
            - assignment set script:mayor_assignment npc:<entry[mayor_obj].created_npc>
            #set owner so the player can interact with the npc
            - adjust <entry[mayor_obj].created_npc> owner:<player>
            - adjust <entry[mayor_obj].created_npc> lookclose:true
            - flag player owned_npcs:->:<entry[mayor_obj].created_npc>
            - determine cancelled
        - else:
            - narrate "you already have a mayor<&nl>dismiss your mayor to be able to spawn a new one<&nl>or type /resetmayor to remove your mayor"
            - determine cancelled
        #
        #
        #mayor interactions
        #
        #
        #create a soldier npc
        on player clicks mayor_hire_soldier in mayor_menu:
        #check for hiring cost and soldier limit
        #todo make both configurable configurable
        - if  <player.inventory.quantity.material[wheat]> >= 64  && <player.flag[soldier]||0> < 5:
            - take wheat quantity:64
            - narrate "you hired a soldier"
            #summon the sentinel npc
            - create player soldier <player.location.add[0,2,0]> trait:sentinel save:soldier_obj
            #increment the amount of soldiers the players has
            - flag player soldier:++
            - flag player owned_npcs_soldier:->:<entry[soldier_obj].created_npc>
            - assignment set script:soldier_assignment npc:<entry[soldier_obj].created_npc>

            #set ownership so the player can interact with the npc
            - adjust <entry[soldier_obj].created_npc> owner:<player>
            #configure the npc
            - adjust <entry[soldier_obj].created_npc> speed:1.3
            - execute as_op "npc select <entry[soldier_obj].created_npc.id>" silent
            - execute as_op "npc skin --url https://i.imgur.com/nwUVLKc.png" silent
            - execute as_server "sentinel chaserange 15 --id <entry[soldier_obj].created_npc.id>"
            - execute as_server "sentinel addtarget monsters --id <entry[soldier_obj].created_npc.id>"
            - execute as_server "sentinel guard <player.name> --id <entry[soldier_obj].created_npc.id>"
            - execute as_server "sentinel attackrate 1 --id <entry[soldier_obj].created_npc.id>"
            - execute as_server "sentinel realistic --id <entry[soldier_obj].created_npc.id>"
            - execute as_server "sentinel safeshot true --id <entry[soldier_obj].created_npc.id>"
            - execute as_server "sentinel speed 1.5 --id <entry[soldier_obj].created_npc.id>"
            - execute as_server "sentinel respawntime -1 --id <entry[soldier_obj].created_npc.id>"
            #reopen the menu to refresh the total soldier count
            - inventory open d:mayor_menu
            - determine cancelled
        - else:
            - if <player.flag[soldier]> >= 5:
                - narrate "soldier limit reached for mayor(5)"
                - determine cancelled
            - else:
                - narrate "you dont have enough wheat"
                - determine cancelled

        #create a farmer npc
        on player clicks mayor_hire_farmer in mayor_menu:
        #check for hiring cost and farmer limit
        #todo make both configurable
        - if  <player.inventory.quantity.material[iron_ingot]> >= 10  && <player.flag[farmer]||0> < 3:
            - take iron_ingot quantity:10
            - narrate "you hired a farmer"
            - create player farmer <player.location.add[0,2,0]> save:farmer_obj
            #increment the amount of farmers the player has
            - flag player farmer:++
            - flag player owned_npcs_farmer:<entry[farmer_obj].created_npc>
            - assignment set script:farmer_assignment npc:<entry[farmer_obj].created_npc>
            - flag <entry[farmer_obj].created_npc> gather_seeds:true
            - adjust <entry[farmer_obj].created_npc> owner:<player>
            - adjust <entry[farmer_obj].created_npc> speed:<1.3>
            - inventory open d:mayor_menu
            - determine cancelled
        - else:
            - if <player.flag[farmer]> > 3:
                - narrate "farmer limit reached for mayor(3)"
                - determine cancelled
            - else:
                - narrate "you dont have enough iron"
                - determine cancelled

        #remove the npc the player is talking with
        on player clicks mayor_dismiss in mayor_menu:
        - narrate "goodbye"
        - remove <player.flag[last_interaction_id]>
        - flag player owned_npcs_mayor:!
        - inventory close
        - determine cancelled
soldier_script:
    type: world
    events:
        #
        #
        #soldier interactions
        #
        #
        on player clicks soldier_equip in soldier_menu:
        #check if theyre not already equiping or setting a path for this npc
        - if <player.flag[equiping]> != <player.flag[last_interaction_id]> && <player.flag[pathing]> != <player.flag[last_interaction_id]>:
        #enter equipment editor
            - execute as_op "npc select <player.flag[last_interaction_id].id>" silent
            - execute as_op "npc equip"
            - narrate "<yellow>Shift left click <green>with an empty hand to exit"
            - flag player equiping:<player.flag[last_interaction_id]>
            - inventory close
            - determine cancelled
        - else:
            - if <player.flag[equiping]> == <player.flag[last_interaction_id]>:
                - narrate "already equiping this soldier, shift left click to cancel"
                - inventory close
                - determine cancelled
            - else:
                - narrate "already setting a path for this soldier, shift left click to cancel"
                - inventory close
                - determine cancelled

        on player clicks soldier_path in soldier_menu:
        - if <player.flag[equiping]> != <player.flag[last_interaction_id]> && <player.flag[pathing]> != <player.flag[last_interaction_id]>:
        #enter path editor
            - execute as_op "npc select <player.flag[last_interaction_id].id>" silent
            - execute as_op "npc path"
            - flag player pathing:!|:<player.flag[last_interaction_id]>
            - inventory close
            - determine cancelled
        - else:
            - if <player.flag[equiping]> == <player.flag[last_interaction_id]>:
                - narrate "already equiping this soldier, shift left click to cancel"
                - inventory close
                - determine cancelled
            - else:
                - narrate "already setting a path for this soldier, shift left click to cancel"
                - inventory close
                - determine cancelled


        on player clicks soldier_guard in soldier_menu:
        - execute as_op "sentinel guard <player.name> --id <player.flag[last_interaction_id].id>"
        - narrate "soldier is now guarding you"
        - determine cancelled

        #remove the npc the player is interacting with
        on player clicks soldier_dismiss in soldier_menu:
        - narrate "goodbye"
        - drop <player.flag[last_interaction_id].inventory.list_contents>
        - remove <player.flag[last_interaction_id]>
        - flag player soldier:--
        - inventory close
        - determine cancelled
farmer_script:
    type: world
    events:

        #farmer interactions
        on player clicks farmer_area in farmer_menu:
        - narrate "right click corners with an empty hand to mark the area"
        - narrate "shift click with an empty hand to cancel"
        #flag the npc id the player is interacting with for referencing the npc
        - flag player editing:<player.flag[last_interaction_id]>
        #set the flag to enable area editing
        - flag player edit_farm_area:1
        - inventory close
        - determine cancelled

        on player clicks farmer_inventory in farmer_menu:
        - determine passively cancelled
        - inventory close
        #open the inventory of the npc the player is currently interacting with
        - inventory open d:<player.flag[last_interaction_id].as_npc.inventory>

        on player clicks farmer_seeds in farmer_menu:
        #toggles whether the npc should collect seeds
        - flag <player.flag[last_interaction_id]> gather_seeds:<player.flag[last_interaction_id].as_npc.flag[gather_seeds].as_boolean.not>
        #reopens the inventory to update the value
        - inventory open d:farmer_menu
        - determine cancelled

        on player clicks farmer_dismiss in farmer_menu:
        - narrate "goodbye"
        - if !<server.flag[cuboids].map_get[<player.flag[last_interaction_id]>]||null> == null:
            #remove the npcs farm area from the area being checked for crop growth
            - note <cuboid[farmcube].remove_member[<server.flag[cuboids].map_get[<player.flag[last_interaction_id]>]>]> as:farmcube
            #remove the farm area itself
            - note remove as:<server.flag[cuboids].map_get[<player.flag[last_interaction_id]>]>
            #remove the owner npc id/area from the server flag
            - flag server cuboids: <server.flag[cuboids].exclude[<server.flag[cuboids].map_get[<player.flag[last_interaction_id]>]>]>
            - flag server cuboids: <server.flag[cuboids].exclude[<player.flag[last_interaction_id]>]>
        - flag player farmer:--
        - inventory close
        - drop <player.flag[last_interaction_id].as_npc.inventory.list_contents>
        - remove <player.flag[last_interaction_id]>
        - determine cancelled
        #defining farm area and add to the area being checked for crop growth
        on player right clicks block with air:
        - if <player.flag[edit_farm_area]> == 1:
            - narrate "corner set at <context.location.xyz.replace[,].with[ ]>"
            - flag player corner1:<context.location>
            - flag player edit_farm_area:++
            - determine cancelled
        - else:
            - if <player.flag[edit_farm_area]> == 2:
                - define new_area:<cuboid[<player.flag[corner1]>|<context.location>]>
                - define area_name:<server.flag[cuboids].map_get[<player.flag[editing]>]||null>
                - define area_index:<server.flag[cuboids].map_get[<player.flag[editing]>].replace[farm_area_]||null>
                #check if the player is overwriting a previous region(if null .length returns 4)
                - if <[area_name].length> > 4:
                    #removes the old cuboid so it does not intersect with the current area
                    - note <cuboid[farmcube].remove_member[<[area_index]>]> as:farmcube
                    #if the new area does not overlap another area replace the old area and add the new one to the area being checked for crop growth
                    - if !<cuboid[farmcube].intersects[<[new_area]>]>:
                        - note <[new_area]> as:farm_area_<[area_index]>
                        - note <cuboid[farmcube].add_member[<[new_area]>].at[<[area_index]>]> as:farmcube
                        #path the npc to the area
                        - ~adjust <player.flag[editing]> add_waypoint:<player.flag[corner1].as_location.add[0,1,0]>
                        - wait 10t
                        - adjust <player.flag[editing]> clear_waypoints:
                        - narrate "replaced old area with new area"
                        - flag player edit_farm_area:!
                        - determine cancelled
                        #if it overlaps restore the previous area to the farm cube and return an error
                    - else:
                        - narrate "Error: this area overlaps another farm area <&nl> Restoring previous area <&nl> right click to select a new are <&nl> shift left click to cancel"
                        #restore the original farm area
                        - note <cuboid[farmcube].add_member[<[area_name]>].at[<[area_index]>]> as:farmcube
                        #restarts the new area creation
                        - flag player edit_farm_area:1
                        - determine cancelled
                #when there is no old area create a new one with the next available index
                - else:
                    - if !<cuboid[farmcube].intersects[<[new_area]>]>:
                        #create the farm area and add it to the area being checked for crop growth
                        - note <[new_area]> as:farm_area_<server.flag[cuboids_next_index]>
                        - note <cuboid[farmcube].add_member[<[new_area]>]> as:farmcube
                        #list the npc that owns the area and its name, advance the index by 1
                        - flag server cuboids:->:<player.flag[editing]>/farm_area_<server.flag[cuboids_next_index]>
                        #path to the area
                        - ~adjust <player.flag[editing]> add_waypoint:<player.flag[corner1].as_location.add[0,1,0]>
                        - wait 10t
                        - adjust <player.flag[editing]> clear_waypoints:
                        - flag server cuboids_next_index:++
                        - narrate "farm area created"
                        - flag player edit_farm_area:!
                        - determine cancelled
                    - else:
                        - narrate "Error: this area overlaps another farm area <&nl> Restoring previous area <&nl> right click to select a new are <&nl> shift left click to cancel"
                        #restore the original farm area and restart area creation
                        - note <cuboid[farmcube].add_member[<cuboid[<area_name>]>]> as:farmcube
                        - flag player edit_farm_area:1
                        - determine cancelled

world_script:
    type: world
    debug: false
    events:
        #world events

        #create area/owner list, index of next available spot in the list and the area that is checked for crop growth, if they dont exist
        on world loads:
        - if <server.flag[cuboids_next_index]|| null> == null:
            - flag server cuboids:server/farmcube
        - if <server.flag[cuboids_next_index]|| null> == null:
            - flag server cuboids_next_index:2
        - if <farmcube||null> == null:
            - note <cuboid[0,0,0,world|0,0,0,world]> as:farmcube
        #set the amount of npcs to 0 so the menu shows it properly
        on player joins:
        - if !<player.flag[new]||false>:
            - flag player new:true
            - flag player farmer:0
            - flag player soldier:0
        #if wheat grows to its last stage in the farmcube area(containing all the farm areas)
        on wheat grows in:farmcube:
        #check in which area the wheat has grown(returns farmcube,farm_area)
        - define npc_tag:<server.flag[cuboids].map_find_key[<context.location.cuboids.get[2].notable_name>]>
        - if <[npc_tag].inventory.can_fit[wheat] && [npc_tag].inventory.can_fit[wheat_seeds].quantity[3]>:
            #flag all grown wheat for breaking
            - waitfor <[npc_tag].has_flag[targets]>
            - flag <[npc_tag]> targets:->:<context.location.cuboids.get[2].blocks[wheat].filter[material.age.is[==].to[7]].exclude[<[npc_tag].flag[targets]>]>
            - foreach <[npc_tag].flag[targets].get[1]>:
                #path the npc to the wheat
                - adjust <[npc_tag]> add_waypoint:<[value].add[0,1,0]>
                - wait 1t
                - adjust <[npc_tag]> clear_waypoints:
                - wait 20t
                #remove the current target
                - flag <[npc_tag]> targets[1]:<-
                #simmulate the wheat drops and replant if seeds are available
                - give wheat to:<[npc_tag].inventory>
                - if <[npc_tag].flag[gather_seeds]>:
                    - give wheat_seeds quantity:<util.random.int[0].to[3]> to:<[npc_tag].inventory>
                - else:
                    - give wheat_seeds to:<[npc_tag].inventory>
                - if <[npc_tag].inventory.quantity.material[seeds]> > 0:
                    - wait 1t
                    - modifyblock <[value]> wheat
                    - take wheat_seeds from:<[npc_tag].inventory>
                - else:
                    - wait 1t
                    - modifyblock <[value]> air
        #on npc death:
        #todo FIX
        #- flag <npc.owner> <npc.flag[profession]>:


        #cancelling editing modes
        on player left clicks with air:
        - if <player.has_flag[equiping]> && <player.is_sneaking>:
            - execute as_op "npc equip"
            - flag player equiping:!
            - determine cancelled
        - if <player.has_flag[pathing]> && <player.is_sneaking>:
            - execute as_op "npc path"
            - execute as_op "sentinel guard"
            - narrate "the soldier will now guard this area"
            - flag player pathing:!
            - determine cancelled
        - if <player.has_flag[edit_farm_area]> && <player.is_sneaking>:
            - flag player edit_farm_area:!
            - narrate "cancelled area creation"
            - determine cancelled

mayor_assignment:
    type: assignment
    actions:
        on assignment:
        - trigger name:click state:true
    interact scripts:
    - mayor_interact
soldier_assignment:
    type: assignment
    actions:
        on assignment:
        - trigger name:click state:true
    interact scripts:
    - soldier_interact
farmer_assignment:
    type: assignment
    actions:
        on assignment:
        - trigger name:click state:true
    interact scripts:
    - farmer_interact
mayor_interact:
    type: interact
    steps:
        1:
            click trigger:
                script:
                #open the menu and flag the npc as the one being interacted with if the player is the owner
                - if <player> == <npc.owner>:
                    - flag player last_interaction_id:<npc>
                    - inventory open d:mayor_menu
                - else:
                    - narrate "this mayor does not obey you"
soldier_interact:
    type: interact
    steps:
        1:
            click trigger:
                script:
                #open the menu and flag the npc as the one being interacted with if the player is the owner
                - if <player> == <npc.owner>:
                    - flag player last_interaction_id:<npc>
                    - inventory open d:soldier_menu
                - else:
                    - narrate "this soldier does not obey you"

farmer_interact:
    type: interact
    steps:
        1:
            click trigger:
                script:
                #open the menu and flag the npc as the one being interacted with if the player is the owner
                - if <player> == <npc.owner>:
                    - flag player last_interaction_id:<npc>
                    - inventory open d:farmer_menu
                - else:
                    - narrate "this farmer does not obey you"
mayor_menu:
    type: inventory
    title: Mayor
    size: 9
    slots:
    - "[mayor_dismiss] [] [] [] [mayor_hire_farmer] [mayor_hire_soldier] [] [] []"
soldier_menu:
    type: inventory
    title: Soldier
    size: 9
    slots:
    - "[soldier_dismiss] [] [] [] [soldier_equip] [soldier_path] [soldier_guard] [] []"
farmer_menu:
    type: inventory
    title: Farmer
    size: 9
    slots:
    - "[farmer_dismiss] [] [] [] [farmer_seeds] [farmer_area] [farmer_inventory] [] []"
mayor_placer:
    type: item
    material: bat_spawn_egg
    display name: Mayor spawner

mayor_hire_soldier:
    type: item
    material: stone_sword
    display name: Hire a soldier for 64 Wheat  (<player.flag[soldier]>/5)
mayor_hire_farmer:
    type: item
    material: stone_hoe
    display name: Hire a farmer for 10 iron ingots (<player.flag[farmer]>/3)
mayor_dismiss:
    type: item
    material: barrier
    display name: Dismiss the mayor
soldier_path:
    type: item
    material: arrow
    display name: set the patrol path
soldier_guard:
    type: item
    material: shield
    display name: guard the player
soldier_equip:
    type: item
    material: iron_chestplate
    display name: equip your soldier
soldier_dismiss:
    type: item
    material: barrier
    display name: Dismiss this soldier
farmer_area:
    type: item
    material: iron_hoe
    display name: set farming area
farmer_seeds:
    type: item
    material: wheat_seeds
    display name: toggle seed collection (currently <player.flag[last_interaction_id].as_npc.flag[gather_seeds]>)
farmer_inventory:
    type: item
    material: chest
    display name: farmer inventory
farmer_deposit:
    type: item
    material: leather_boots
    display name: Change deposit location
farmer_interval:
    type: item
    material: clock
    display name: Change deposit interval
farmer_dismiss:
    type: item
    material: barrier
    display name: dismiss farmer

reset_command: