Advertisement
FrostedWeFall

Extra Enchants

Jan 1st, 2018
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.38 KB | None | 0 0
  1. options:
  2. ENCHANT_NAME: "Efficiency", "Fortune", "Laser", "Speed", "Haste", "Wisdom", "Night Vision", and "Jump"
  3.  
  4. function reloadConfig():
  5. unload yaml "config"
  6. load yml "plugins/Skript/scripts/special tools/config.yml"
  7. set {_exists} to skript-yml value "Rarities" from "config"
  8. if {_exists} isn't set:
  9. set file contents of "plugins/Skript/scripts/special tools/config.yml" to file contents of "plugins/Skript/scripts/special tools/DO NOT EDIT.txt"
  10. unload yaml "config"
  11. load yml "plugins/Skript/scripts/special tools/config.yml"
  12.  
  13. function loadConfig() :: objects:
  14. return all yml nodes of "config"
  15.  
  16. function loadRarities() :: objects:
  17. set {_data} to yaml value "Rarities" from "config"
  18. set {_names::*} to split "%{_data}%" at "{"
  19. loop {_names::*}:
  20. set {_names2::*} to split loop-value at "}, "
  21. loop {_names2::*}:
  22. set {_name} to subtext of loop-value-2 from characters 1 to (length of (loop-value-2) - 1)
  23. if yaml value "Rarities.%{_name}%" from "config" is set:
  24. add {_name} to {_ret::*}
  25. return {_ret::*}
  26.  
  27. on load:
  28. reloadConfig()
  29.  
  30. function pickRarity() :: text:
  31. set {_rarities::*} to loadRarities()
  32. set {_total} to 0
  33. loop {_rarities::*}:
  34. set {_val} to yaml value "Rarities.%loop-value%.chance" from "config"
  35. set {_total} to {_total} + {_val}
  36. set {_random} to random number between 0 and {_total}
  37. loop {_rarities::*}:
  38. set {_val} to yaml value "Rarities.%loop-value%.chance" from "config"
  39. subtract {_val} from {_random}
  40. if {_random} <= 0:
  41. return loop-value
  42.  
  43. function isSpecialTool(item: item) :: boolean:
  44. set {_tag} to tag "specialTool_Level" of nbt of {_item}
  45. if {_tag} is set:
  46. return true
  47. return false
  48.  
  49. function getEnchantId(name: text) :: integer:
  50. # Fortune: Vanilla enchant
  51. if {_name} is "fortune":
  52. return 35
  53. # Efficiency: Vanilla enchant
  54. if {_name} is "efficiency":
  55. return 32
  56. # Laser: Shoots eggs out of tool when right clicked. Breaks blocks.
  57. if {_name} is "laser":
  58. return 80
  59. # Explosive: Creates an explosion when a block is mined.
  60. #if {_name} is "explosive":
  61. # return 81
  62. # Haste: Gives haste when tool is held.
  63. if {_name} is "haste":
  64. return 82
  65. # Speed: Gives speed when tool is held.
  66. if {_name} is "speed":
  67. return 83
  68. # Jump: Gives jump boost when tool is held.
  69. if {_name} is "jump":
  70. return 84
  71. if {_name} is "wisdom":
  72. return 85
  73. if {_name} is "night vision":
  74. return 86
  75. return 0
  76.  
  77. function addEnchant(item: item, name: text, level: text = "+1") :: item:
  78. set {_id} to getEnchantId({_name})
  79. set {_nbt} to nbt of {_item}
  80. set {_ench} to tag "specialTool_Ench" of {_nbt}
  81. set {_found} to 0
  82. set {_add} to 0
  83. set {_lvl} to {_level} parsed as number
  84. if {_level} starts with "+":
  85. set {_add} to 1
  86. set {_lvl} to (subtext of {_level} from characters 2 to (length of {_level})) parsed as number
  87. set {_loop::*} to contents of {_ench}
  88. loop {_loop::*}:
  89. set {_cont} to {_ench} index (loop-index parsed as number)
  90. set {_curID} to tag "id" of loop-value
  91. if {_curID} = {_id}:
  92. set {_level} to tag "lvl" of loop-value
  93. if {_add} is 1:
  94. add {_lvl} to {_level}
  95. else:
  96. set {_level} to {_lvl}
  97. set tag "lvl" of loop-value to {_level}
  98. set {_found} to 1
  99. if {_found} is 0:
  100. set {_id} to join "%{_id}%" and "s"
  101. set {_lvl} to join "%{_lvl}%" and "s"
  102. set {_text} to subtext of "%{_ench}%" from characters 1 to (length of "%{_ench}%" - 1)
  103. if {_text} is "<none":
  104. set {_text} to "["
  105. else:
  106. set {_text} to "%{_text}%,"
  107. set {_ench} to "%{_text}%{lvl:%{_lvl}%,id:%{_id}%}]"
  108. delete tag "specialTool_Ench" of {_nbt}
  109. set {_nbt} to subtext of "%{_nbt}%" from characters 1 to (length of "%{_nbt}%" - 1)
  110. set {_item} to {_item} with custom nbt "%{_nbt}%,specialTool_Ench:%{_ench}%}"
  111. return {_item}
  112.  
  113. function getEnchantLevel(item: item, name: text) :: number:
  114. set {_id} to getEnchantId({_name})
  115. set {_nbt} to nbt of {_item}
  116. set {_ench} to tag "specialTool_Ench" of {_nbt}
  117. set {_found} to 0
  118. set {_loop::*} to contents of {_ench}
  119. loop {_loop::*}:
  120. set {_cont} to {_ench} index (loop-index parsed as number)
  121. set {_curID} to tag "id" of loop-value
  122. if {_curID} = {_id}:
  123. set {_level} to tag "lvl" of loop-value
  124. return {_level}
  125. return 0
  126.  
  127. function generateSpecialTool(it: item type) :: item:
  128. set {_rarity} to pickRarity()
  129. set {_xpMult} to yaml value "Rarities.%{_rarity}%.xpMult" from "config"
  130. if "%{_it}%" contains "pickaxe":
  131. set {_names} to yaml value "Rarities.%{_rarity}%.pickaxeNames" from "config"
  132. else if "%{_it}%" contains "axe":
  133. set {_names} to yaml value "Rarities.%{_rarity}%.axeNames" from "config"
  134. else:
  135. set {_names} to yaml value "Rarities.%{_rarity}%.shovelNames" from "config"
  136. set {_names} to "%{_names}%"
  137. set {_names::*} to split {_names} at ", "
  138. set {_names::1} to subtext of {_names::1} from characters 2 to (length of {_names::1})
  139. set {_len} to size of {_names::*}
  140. set {_names::%{_len}%} to subtext of {_names::%{_len}%} from characters 1 to (length of {_names::%{_len}%} - 1)
  141. set {_name} to random element out of {_names::*}
  142. set {_item} to 1 of {_it} with custom nbt "{specialTool_Rarity:""%{_rarity}%"",specialTool_Level:1,specialTool_XPToNext:%{_xpMult}%,specialTool_LevelXP:%{_xpMult}%,specialTool_Name:""%colored {_name}%"",HideFlags:5,Unbreakable:1}"
  143. set {_item} to doLore({_item})
  144. set name of {_item} to "%colored {_name}% &7[&e0&7/&e%{_xpMult}% &7XP]"
  145. return {_item}
  146.  
  147. function getEnchantColor(enchant: text) :: text:
  148. set {_name} to {_enchant}
  149. replace all " " in {_name} with " "
  150. set {_name} to {_name} converted to lowercase
  151. set {_val} to yaml value "EnchantNames.%{_name}%" from "config"
  152. return colored "%{_val}%"
  153.  
  154. function getXPBar(item: item, length: number) :: text:
  155. set {_level} to tag "specialTool_Level" of nbt of {_item}
  156. set {_toNext} to tag "specialTool_XPToNext" of nbt of {_item}
  157. set {_currentLevelXP} to tag "specialTool_LevelXP" of nbt of {_item}
  158. set {_toNext} to {_currentLevelXP} - {_toNext}
  159. set {_tempToNext} to {_toNext}
  160. set {_bar} to "[&a"
  161. set {_switch} to true
  162. loop {_length} times:
  163. subtract {_currentLevelXP} / {_length} from {_tempToNext}
  164. if {_tempToNext} < 0:
  165. if {_switch} is true:
  166. set {_switch} to false
  167. set {_bar} to "%{_bar}%&c"
  168. set {_bar} to "%{_bar}%|"
  169. set {_bar} to "%{_bar}%&7]"
  170. return "&7Level &a%{_level}% &8||&7 %{_bar}% &e%{_toNext}%&7/&e%{_currentLevelXP}%&7 XP"
  171.  
  172. function doLore(item: item) :: item:
  173. set {_rarity} to tag "specialTool_Rarity" of nbt of {_item}
  174. set {_rarityName} to yaml value "Rarities.%{_rarity}%.name" from "config"
  175. set {_toNext} to tag "specialTool_XPToNext" of nbt of {_item}
  176. set {_currentLevelXP} to tag "specialTool_LevelXP" of nbt of {_item}
  177. set {_toNext} to {_currentLevelXP} - {_toNext}
  178. set {_name} to tag "specialTool_Name" of nbt of {_item}
  179. clear {_item}'s lore
  180. add "&7Special Tool &8||&7 Rarity: %colored {_rarityName}%" to {_item}'s lore
  181. add getXPBar({_item}, 10) to {_item}'s lore
  182. set {_enchs::*} to {@ENCHANT_NAME}
  183. if getEnchantLevel({_item}, "efficiency") > 0:
  184. set {_level} to getEnchantLevel({_item}, "efficiency")
  185. enchant {_item} with "efficiency %{_level}%" parsed as enchantment type
  186. if getEnchantLevel({_item}, "fortune") > 0:
  187. set {_level} to getEnchantLevel({_item}, "fortune")
  188. enchant {_item} with "fortune %{_level}%" parsed as enchantment type
  189. loop {_enchs::*}:
  190. if getEnchantLevel({_item}, loop-value) > 0:
  191. add "%getEnchantColor(loop-value)% %getEnchantLevel({_item}, loop-value)%" to {_item}'s lore
  192. set name of {_item} to "%{_name}% &7[&e%{_toNext}%&7/&e%{_currentLevelXP}%&7 XP]"
  193. return {_item}
  194.  
  195. function levelUpSpecialTool(item: item, player: player, count: number) :: item:
  196. set {_rarity} to tag "specialTool_Rarity" of nbt of {_item}
  197. set {_xpMult} to yaml value "Rarities.%{_rarity}%.xpMult" from "config"
  198. set {_xpCap} to yaml value "Rarities.%{_rarity}%.xpCap" from "config"
  199. set {_enchChance} to yaml value "Rarities.%{_rarity}%.enchChance" from "config"
  200. set {_enchChanceCap} to yaml value "Rarities.%{_rarity}%.enchChanceCap" from "config"
  201. set {_level} to tag "specialTool_Level" of nbt of {_item}
  202. set {_toNext} to tag "specialTool_XPToNext" of nbt of {_item}
  203. set {_currentLevelXP} to tag "specialTool_LevelXP" of nbt of {_item}
  204. set {_name} to tag "specialTool_Name" of nbt of {_item}
  205. loop {_count} times:
  206. subtract 1 from {_toNext}
  207. if {_toNext} <= 0:
  208. add 1 to {_level}
  209. set {_toNext} to {_level} * {_xpMult}
  210. if {_toNext} > {_xpCap}:
  211. set {_toNext} to {_xpCap}
  212. set {_currentLevelXP} to {_toNext}
  213. play sound "ENTITY_PLAYER_LEVELUP" to {_player} with volume 0.5 and pitch 1
  214. send "&7-------------------------" to {_player}
  215. send "&aYou leveled up your %{_name}%&a!" to {_player}
  216. send "&7Level &a%{_level}% &8|| &e%{_toNext}% &7XP to level &a%{_level} + 1%&7." to {_player}
  217. set {_ec} to {_enchChance} * {_level}
  218. if {_ec} > {_enchChanceCap}:
  219. set {_ec} to {_enchChanceCap}
  220. chance of {_ec}:
  221. set {_enchs::*} to {@ENCHANT_NAME}
  222. set {_ench} to random element out of {_enchs::*}
  223. set {_path} to "Rarities.%{_rarity}%.maxLevels.%{_ench} converted to lowercase%"
  224. set {_maxLevel} to yaml value {_path} from "config"
  225. if getEnchantLevel({_item}, {_ench}) >= {_maxLevel}:
  226. send "&eMaxed enchantment lost! &8||&7 Enchantment: %getEnchantColor({_ench})% &8|| &7This enchantment didn't upgrade, because it has already been maxed out." to {_player}
  227. else:
  228. set {_item} to addEnchant({_item}, {_ench})
  229. send "&aEnchantment obtained! &8||&7 Enchantment: %getEnchantColor({_ench})% &7[Now level %getEnchantLevel({_item}, {_ench})%]" to {_player}
  230. send "&7-------------------------" to {_player}
  231. set {_nbt} to nbt of {_item}
  232. set tag "specialTool_Level" of {_nbt} to {_level}
  233. set tag "specialTool_XPToNext" of {_nbt} to {_toNext}
  234. set tag "specialTool_LevelXP" of {_nbt} to {_currentLevelXP}
  235. set {_item} to {_item} with custom nbt "%{_nbt}%"
  236. set {_lored} to doLore({_item})
  237. return {_lored}
  238.  
  239. command /specialtools [<text>] [<text>] [<text>]:
  240. permission: specialtools.use
  241. aliases: /st, /specialtool
  242. permission message: &6No Permission &8|| &eYou don't have permission to do this. (&fspecialtools.use&e)
  243. trigger:
  244. if arg 1 is not set:
  245. send "&6/specialtools give <player> <item type> &8||&f Gives <player> a special tool of type <item type>. &8||&e Permission Node: specialtools.give"
  246. send "&6/specialtools reload &8||&f Reload the Special Tools config file. &8||&e Permission Node: specialtools.reload"
  247. send "&6/specialtools ench <enchantment> [level] &8||&f Enchant the special tool you're holding with the enchantment <enchantment> with level [level]. If [level] is omitted, the command will add a level of <enchantment>. &8||&e Permission Node: specialtools.ench"
  248. send "&6/specialtools rarity <rarity> &8||&f Set the rarity of the special tool you are holding to <rarity>. &8||&e Permission Node: specialtools.setrarity"
  249. send "&6/specialtools xp <amount> &8||&f Adds <amount> XP to the tool you're holding. &8||&e Permission Node: specialtools.xp"
  250. else if arg 1 is "give":
  251. if sender has permission "specialtools.give":
  252. if arg 2 is set:
  253. if arg 2 parsed as player is set:
  254. if arg 3 is set:
  255. if arg 3 parsed as item type is set:
  256. give (arg 2 parsed as player) generateSpecialTool(arg 3 parsed as item type)
  257. send "&2Success! &8|| &a%arg 2 parsed as player% has recieved their Special Tool of type %arg 3%!" to sender
  258. send "&2You have recieved a special tool of type %arg 3%." to (arg 2 parsed as player)
  259. else:
  260. send "&4Failure &8|| &cThe item type argument (arg 3) wasn't found. Make sure you typed it correctly, and that you used spaces instead of underscores (diamond pickaxe instead of diamond_pickaxe)."
  261. else:
  262. send "&4Failure &8|| &cThe item type argument (arg 3) wasn't specified. Make sure to specify a type of item (such as diamond pickaxe). Don't forget to use spaces instead of underscores."
  263. else:
  264. send "&4Failure &8|| &cThat player (arg 2) wasn't found online. Make sure you typed the player's name correctly, and that they're online."
  265. else:
  266. send "&4Failure &8|| &cYou didn't specify a player (arg 2)! Make sure to specify an online player to give a special tool to. Capitalization doesn't matter."
  267. else:
  268. send "&6No Permission &8|| &eYou don't have permission to do this. (&fspecialtools.give&e)"
  269. else if arg 1 is "reload":
  270. if sender has permission "specialtools.reload":
  271. reloadConfig()
  272. send "&2Success! &8|| &aConfig reloaded."
  273. else:
  274. send "&6No Permission &8|| &eYou don't have permission to do this. (&fspecialtools.reload&e)"
  275. else if arg 1 is "ench":
  276. if sender has permission "specialtools.ench":
  277. if arg 2 is set:
  278. set {_lvl} to "+1"
  279. if arg 3 is set:
  280. set {_lvl} to arg 3
  281. set player's tool to addEnchant(player's tool, arg 2, {_lvl})
  282. set player's tool to doLore(player's tool)
  283. else:
  284. send "&4Failure &8|| &cYou didn't specify an enchant (arg 2)! Please specify an enchantment, such as efficiency."
  285. else:
  286. send "&6No Permission &8|| &eYou don't have permission to do this. (&fspecialtools.ench&e)"
  287. else if arg 1 is "rarity":
  288. if sender has permission "specialtools.setrarity":
  289. set {_rarities::*} to loadRarities()
  290. if arg 2 is set:
  291. if {_rarities::*} contains arg 2:
  292. set {_nbt} to nbt of player's tool
  293. set tag "specialTool_Rarity" of {_nbt} to arg 2
  294. set player's tool to player's tool with custom nbt "%{_nbt}%"
  295. set player's tool to doLore(player's tool)
  296. send "&2Success! &8|| &aRarity set to %arg 2%."
  297. else:
  298. send "&4Failure &8|| &cThat rarity wasn't found in your config file (arg 2). Make sure you spelled it correctly!"
  299. else:
  300. send "&4Failure &8|| &cYou didn't specify a rarity (arg 2)! Choose a rarity from your config file, and put it as the second argument to the command."
  301. else:
  302. send "&6No Permission &8|| &eYou don't have permission to do this. (&fspecialtools.setrarity&e)"
  303. else if arg 1 is "xp":
  304. if sender has permission "specialtools.xp":
  305. if arg 2 is set:
  306. if arg 2 parsed as number is set:
  307. set player's tool to levelUpSpecialTool(player's tool, player, arg 2 parsed as number)
  308. set player's tool to doLore(player's tool)
  309. else:
  310. send "&4Failure &8|| &cThat's not a valid number! Make sure you didn't put any extra characters in there."
  311. else:
  312. send "&4Failure &8|| &cYou didn't specify an amount of XP (arg 2)! Put an amount of XP as your second argument."
  313. else:
  314. send "&6No Permission &8|| &eYou don't have permission to do this. (&fspecialtools.xp&e)"
  315. else:
  316. send "&4Failure &8|| &cThat subcommand wasn't recognized! Try using /st for all subcommands."
  317.  
  318. on break:
  319. player's tool is a pickaxe or a shovel or an axe:
  320. if isSpecialTool(player's tool) is true:
  321. set {_name} to "%block%" converted to lowercase
  322. replace all " " in {_name} with "_"
  323. set {_exp} to yaml value "ExpPerBlock.%{_name}%" from "config"
  324. if {_exp} isn't set:
  325. set {_exp} to 1
  326. chance of getEnchantLevel(player's tool, "wisdom") * 0.2:
  327. set {_exp} to {_exp} * 2
  328. set player's tool to levelUpSpecialTool(player's tool, player, {_exp})
  329.  
  330. on hotbar switch:
  331. if player's tool is a pickaxe or an axe or an axe:
  332. if isSpecialTool(player's tool) is false:
  333. set player's tool to generateSpecialTool(type of player's tool)
  334.  
  335. # Laser
  336. on right click:
  337. getEnchantLevel(player's tool, "laser") > 0:
  338. shoot an egg from the player with speed 1.25
  339.  
  340. on projectile hit:
  341. projectile is an egg
  342. set {_tag} to tag "ownerName" of nbt of projectile
  343. tag "ownerName" of nbt of projectile is set
  344. wait 1 tick
  345. set {_block} to the block at location 0.1 in front of the projectile
  346. if {_block} is air:
  347. set {_block} to the block at location 0.1 behind the projectile
  348. set {_player} to "%{_tag}%" parsed as player
  349. {_player} can build at location
  350. set {_tag} to tag "ownerName" of nbt of projectile
  351. {_block} isn't bedrock
  352. set {_drops::*} to drops of {_block}
  353. loop {_drops::*}:
  354. set {_drop} to loop-value
  355. drop {_drop} at location of {_block}
  356. set block at location of {_block} to air
  357. if isSpecialTool({_player}'s tool) is true:
  358. set {_name} to "%{_block}%" converted to lowercase
  359. replace all " " in {_name} with "_"
  360. set {_exp} to yaml value "ExpPerBlock.%{_name}%" from "config"
  361. if {_exp} isn't set:
  362. set {_exp} to 1
  363. chance of getEnchantLevel({_player}'s tool, "wisdom") * 0.2:
  364. set {_exp} to {_exp} * 2
  365. set {_player}'s tool to levelUpSpecialTool({_player}'s tool, {_player}, {_exp})
  366. wait 1 tick
  367. if distance between last spawned chicken and event-location is less than 20:
  368. delete the last spawned chicken
  369.  
  370. # Explosive
  371. #on break:
  372. # getEnchantLevel(player's tool, "explosive") > 0:
  373. # set {_h} to health of player
  374. # create an explosion with force getEnchantLevel(player's tool, "explosive") * 3
  375. # set player's health to {_h}
  376.  
  377. # Haste
  378. every second:
  379. loop all players:
  380. if getEnchantLevel(loop-player's tool, "haste") > 0:
  381. apply haste getEnchantLevel(loop-player's tool, "haste") to loop-player for 1 second
  382.  
  383. # Speed
  384. every second:
  385. loop all players:
  386. if getEnchantLevel(loop-player's tool, "speed") > 0:
  387. apply speed getEnchantLevel(loop-player's tool, "speed") to loop-player for 1 second
  388.  
  389. # Jump
  390. every second:
  391. loop all players:
  392. if getEnchantLevel(loop-player's tool, "jump") > 0:
  393. apply jump boost getEnchantLevel(loop-player's tool, "jump") to loop-player for 1 second
  394.  
  395. # NV
  396. every second:
  397. loop all players:
  398. if getEnchantLevel(loop-player's tool, "night vision") > 0:
  399. apply night vision getEnchantLevel(loop-player's tool, "night vision") to loop-player for 10 seconds
  400. else:
  401. remove night vision from loop-player
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement