Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. const ENMAPLEVEL = require('enmap-level')
  2. const ENMAP = require('enmap');
  3. const SKILLS = new ENMAP({
  4. provider: new ENMAPLEVEL({
  5. name: "Skill Data"
  6. })
  7. })
  8. const SKILL_OBJECTS = {}
  9. const SKILLS_ARRAY = ["Combat", "Farming", "Mining", "Fishing", "Woodcutting"]
  10. const LEVEL_3_DOOR = Game.findBrickByName("level3doorstart");
  11.  
  12.  
  13.  
  14. SKILLS.set("data", SKILL_OBJECTS);
  15.  
  16.  
  17. function find_skill(skill) {
  18. for (let index of SKILLS_ARRAY) {
  19. if (index.toLowerCase().indexOf(skill) == 0) {
  20. return index
  21. }
  22. }
  23. }
  24.  
  25. function notification(msg, player) {
  26. if (!msg) return;
  27. return player.message(`[#0000FF][Skills]: [#FFFFFF]${msg}`);
  28. };
  29.  
  30. Game.on('playerJoin', plr => {
  31. if (SKILLS.has("data", plr.userId)) return;
  32.  
  33. SKILL_OBJECTS[plr.userId] = {
  34. "Combat": {
  35. level: 0,
  36. exp: 0
  37. },
  38. "Farming": {
  39. level: 0,
  40. exp: 0
  41. },
  42. "Mining": {
  43. level: 0,
  44. exp: 0
  45. },
  46. "Fishing": {
  47. level: 0,
  48. exp: 0
  49. },
  50. "Woodcutting": {
  51. level: 0,
  52. exp: 0
  53. },
  54. };
  55.  
  56. return SKILLS.set("data", SKILL_OBJECTS[plr.userId], plr.userId)
  57. });
  58.  
  59. LEVEL_3_DOOR.touching(player => {
  60. const data = SKILLS.get("data", player.userId);
  61. const level_require = 3;
  62. const TELE_BRICK = Game.findBrickByName("brick1541")
  63. if (!data) return Error(`No data found for user ${player.userId}`);
  64. if (data.Combat.level < level_require) return {
  65. NOTI: notification(`Come back when you're level ${level_require}!`, player),
  66. TELE: player.position = TELE_BRICK.position
  67. }
  68. LEVEL_3_DOOR.collision = false;
  69. setTimeout(() => {
  70. LEVEL_3_DOOR.collision = true
  71. }, 2000);
  72. })
  73.  
  74. Game.on("skillsCmd", plr => {
  75. const data = SKILLS.get("data", plr.userId);
  76. if (data) {
  77. for (let index of Object.keys(data)) {
  78. plr.message(`[#00FF00][Skills]: [#FFFFFF]${index}: ${data[index].level} [#00FFFF][EXP]: [#FFFFFF]${data[index].exp}`)
  79. }
  80. }
  81. })
  82.  
  83. Game.on('setCmd', (plr, msg) => {
  84. const messages = msg.split(" ")
  85. if (!messages[0], !messages[1]) return;
  86. if (isNaN(messages[1])) return;
  87. const skill = find_skill(messages[0]);
  88. if (skill) {
  89. return {
  90. SET_DATA: SKILLS.set("data", Number(messages[1]), `${plr.userId}.${skill}.level`),
  91. NOTI: notification(`You set ${skill} to level ${Number(messages[1])}`, plr)
  92. }
  93. }
  94. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement