- D1 Meta Docs - Denizen Script -
Home Page / Pi to one million places / Contact mcmonkey / Donate / Paste Scripts / Denizen Help /
You are browsing as a guest.
Login | Register


Click here to create your own public paste ~ ~ click to duplicate and edit this paste


TitleUntitled Paste
TypeDenizen Script
Date2016/01/29 06:54:29 UTC-08:00
ByPanteLegacy
Other
Paste
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
21000
################################################
# File containing the core scripts for dTitles #
################################################
# Written by PanteLegacy and Fortifier42 #
##########################################

###########################################################
# World script for managing the I/O of the dTitles plugin #
###########################################################
dTitles_Manager:
  type: world
  events:
    on server start:
    - if <server.has_flag[dTitlesDisable]> {
      - queue clear
      }
      else {
      
      - if <server.has_file[../dTitles/titles.yml].not> {
        - yaml create id:titles
        - yaml savefile:../dTitles/titles.yml id:titles
        }
        else {
        - yaml load:../dTitles/titles.yml id:titles
        }
        
        
      - if <server.has_file[../dTitles/players.yml].not> {
        - yaml create id:players
        - yaml savefile:../dTitles/players.yml id:players
        }
        else {
        - yaml load: ../dTitles/players.yml id:players
        }
        
      }
    on world save:
    - if <server.has_flag[dTitlesDisable]> {
      - queue clear
      }
      else {
      
      - if <yaml.list.contains[titles]> {
        - yaml savefile:../dTitles/titles.yml id:titles
        }
        else {
        - flag server dTitlesDisable:"Error: dTitles/titles.yml was not registered."
        }
        
        
      - if <yaml.list.contains[players]> {
        - yaml savefile:../dTitles/players.yml id:players
        }
        else {
        - flag server dTitlesDisable:"Error: dTitles/players.yml was not registered."
        }
        
      }
    on player joins:
    - if <yaml[players].contains[Players.<player.uuid>].not> {
      - yaml id:players set Players.<player.uuid>:
      
      - yaml savefile:../dTitles/players.yml id:players
      - yaml load:../dTitles/players.yml id:players
      }
      
      else {
      - queue clear
      }
 
####################################################################
# World script for handling players clicking items in an inventory #
####################################################################
dTitles_Inventory_Manager:
  type: world
  events:
    on player clicks in inventory:
    - if <context.inventory.title.contains["Titles"].not> {
      - queue clear
      }
      
      else if "<context.inventory.title.contains[Titles - Categories]>" {
      - determine passively cancelled
      - define selectedCategory <context.item.lore.first>
      - run Open_Owned_Titles_Menu def:<def[selectedCategory]>|<player>
      }
      
      else if "<context.inventory.title.contains[Titles - Shop]>" {
      - determine passively cancelled
      }
      
      else if "<context.inventory.title.contains[Titles -]>" && "<context.inventory.title.contains[Categories].not>" && "<context.inventory.title.contains[Shop].not>" {
      - determine passively cancelled
      - define Category <context.item.lore.get[1]>
      - define TitleID <context.item.lore.get[2]>
      - run Set_Title def:<def[Category]>|<def[TitleID]>|<player>
      }
      
    on player drags in inventory:
    - if <context.inventory.title.contains["Titles"].not> {
      - queue clear
      }
      
      else {
      - determine cancelled
      }
      
##############################################
# Generates the items in the categories menu #
##############################################
Generate_Category_Item:
  type: procedure
  definitions: Category
  script:
  - define Path Categories.<def[Category]>
  
  - adjust <yaml[titles].read[<def[Path]>.Item].as_item||i@Stone> display_name:<&r><yaml[titles].read[<def[Path]>.Display].parse_color> save:GeneratedItem
  - adjust <entry[GeneratedItem].result> "Lore:Category<&co> <def[Category]>" save:CategoryItem
  
  - determine <entry[CategoryItem].result>
  
#####################################################
# Opens the categories menu and fills it with items #
#####################################################
Open_Category_Menu:
  type: task
  script:
  - define Items li@
  - foreach <yaml[titles].list_keys[Categories]> {
    - define Item <proc[Generate_Category_Item].context[<def[value]>]>
    - define Items <def[Items].include[<def[Item]>]>
    }
  - inventory open "d:in@generic[size=<def[Items].size.div[9].round_up.mul[9]>;contents=<def[Items]>;title=Titles - Categories]"
  
###########################################
# Generates the items in the titles owned #
###########################################
Generate_Title_Item:
  type: procedure
  definitions: Category|ID
  script:
  - define Path Categories.<def[Category]>.Titles.<def[ID]>
  - if <yaml[titles].contains[<def[Path]>].not> {
    - determine "i@stone[display_name=Invalid Title]"
    }
  - define Item <yaml[titles].read[<def[Path]>.Item].as_item||i@stone>
  - adjust <def[Item]> display_name:<yaml[titles].read[<def[Path]>.Display].parse_color> save:item
  - adjust <entry[item].result> "lore:<&r>Category: <yaml[titles].read[Categories.<def[Category]>].parse_color>|<&0>ID<&co> %id%" save:generatedItem
  
  - determine <entry[generatedItem].result>
  
#######################################################
# Opens the owned titles menu and fills it with items #
#######################################################
Open_Owned_Titles_Menu:
  type: task
  definitions: Category|targetedPlayer
  script:
  - define Items li@
  - foreach <yaml[players].list_keys[Players.<def[targetedPlayer].uuid>.titles.<def[Category]>]> {
    - define Item <proc[Generate_Title_Item].context[<def[Category]>|<def[targetedPlayer]>]>
    - define Items <def[Items].include[<entry[generatedItem].result>]>
    }
  - inventory open "d:in@generic[size=<def[Items].size.div[9].round_up.mul[9]>;contents=<def[Items]>;title=Titles - <def[Category]>]"
  
###############################
# Sets the prefix of a player #
###############################
Set_Title:
  type: task
  definitions: Category|titleID|targetedPlayer
  script:
  - define Title <yaml[titles].read[Categories.<def[Category]>.titles.<def[titleID]>.display]>
  - team add:<def[targetedPlayer]> prefix:<def[Title].parse_color>

##############################################
# Task script for adding a title to a player #
##############################################
Titles_Player_Add:
  type: task
  definitions: category|titleID|targetedPlayer
  script:
  - define path Players.<def[targetedPlayer].uuid>.Categories.titles.<def[category]>.<def[titleID]>
  - if <yaml[players].contains[Path].not> {
    - yaml id:players set Players.<def[targetedPlayer].uuid>.Categories.titles.<def[category]>:->:<def[titleID]>
    - yaml savefile:../dTitles/players.yml id:players
    - yaml load:../dTitles/players.yml id:players
    }
    else {
    - determine passively cancelled
    - flag <player> error:Player bought a title that he already owns... Idiot.
    }
##################################################
# Task script for removing a title from a player #
##################################################
Titles_Player_Remove:
  type: task
  definitions: category|titleID|targetedPlayer
  script: 
  - define path Players.<def[targetedPlayer].uuid>.Categories.titles.<def[category]>.<def[titleID]>
  - if <yaml[players].contains[Path].not> {
    - yaml id:players set Players.<def[targetedPlayer]>.Categories.titles.<def[category]>:<-:<def[titleID]>
    
    - yaml savefile:../dTitles/players.yml id:players
    - yaml load:../dTitles/players.yml id:players
    }
    else {
    - determine cancelled
    }



RawRaw



Pastes made: 76867