Guest User

Untitled

a guest
Jun 2nd, 2016
953
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.41 KB | None | 0 0
  1. -- Main Crafting Window -- This is the modal window that is displayed first
  2. function Player:sendMainCraftWindow(config)
  3. local function buttonCallback(button, choice)
  4.  
  5. -- Modal Window Functionallity
  6. if button.text == "Select" then
  7. self:sendVocCraftWindow(config, choice.id)
  8. end
  9. end
  10.  
  11. -- Modal window design
  12. local window = ModalWindow {
  13. title = config.mainTitleMsg, -- Title of the main craft modal window
  14. message = config.mainMsg.."\n\n" -- Message of the main craft modal window
  15. }
  16.  
  17. -- Add buttons to the window (Note: if you change the names of these you must change the functions in the modal window functionallity!)
  18. window:addButton("Select", buttonCallback)
  19. window:addButton("Exit", buttonCallback)
  20.  
  21. -- Add choices from the action script
  22. for i = 1, #config.system do
  23. window:addChoice(config.system[i].vocation)
  24. end
  25.  
  26. -- Set what button is pressed when the player presses enter or escape.
  27. window:setDefaultEnterButton("Select")
  28. window:setDefaultEscapeButton("Exit")
  29.  
  30. -- Send the window to player
  31. window:sendToPlayer(self)
  32. end
  33. -- End of the first modal window
  34.  
  35.  
  36.  
  37. -- This is the modal window that displays all avalible items for the chosen vocation.
  38. function Player:sendVocCraftWindow(config, lastChoice)
  39. local function buttonCallback(button, choice)
  40.  
  41. -- Modal Window Functionallity
  42. -- If the user presses the back button they will be redirected to the main window.
  43. if button.text == "Back" then
  44. self:sendMainCraftWindow(config)
  45. end
  46. -- If the user presses the details button they will be redirected to a text window with information about the item they want to craft.
  47. if button.text == "Details" then
  48. local item = config.system[lastChoice].items[choice.id].item
  49. local details = "In order to craft "..item.." you must collect the following items.\n\nRequired Items:"
  50.  
  51. for i = 1, #config.system[lastChoice].items[choice.id].reqItems do
  52. local reqItems = config.system[lastChoice].items[choice.id].reqItems[i].item
  53. local reqItemsCount = config.system[lastChoice].items[choice.id].reqItems[i].count
  54. local reqItemsOnPlayer = self:getItemCount(config.system[lastChoice].items[choice.id].reqItems[i].item)
  55. details = details.."\n- "..capAll(getItemName(reqItems).." ["..reqItemsOnPlayer.."/"..reqItemsCount.."]")
  56. end
  57.  
  58. self:showTextDialog(item, details)
  59. self:sendVocCraftWindow(config, lastChoice)
  60. end
  61.  
  62. -- if the player presses the craft button then begin checks.
  63. if button.text == "Craft" then
  64.  
  65. -- Check if player has required items to craft the item. If they dont send needItems message.
  66. for i = 1, #config.system[lastChoice].items[choice.id].reqItems do
  67. if self:getItemCount(config.system[lastChoice].items[choice.id].reqItems[i].item) < config.system[lastChoice].items[choice.id].reqItems[i].count then
  68. self:say(config.needItems..config.system[lastChoice].items[choice.id].item, TALKTYPE_MONSTER_SAY)
  69. return false
  70. end
  71. end
  72. -- Remove the required items and there count from the player.
  73. for i = 1, #config.system[lastChoice].items[choice.id].reqItems do
  74. self:removeItem(config.system[lastChoice].items[choice.id].reqItems[i].item, config.system[lastChoice].items[choice.id].reqItems[i].count)
  75. end
  76. -- Send effect and give player item.
  77. self:addItem(config.system[lastChoice].items[choice.id].itemID)
  78. self:getPosition():sendMagicEffect(CONST_ME_FIREATTACK)
  79. end
  80. end
  81.  
  82. -- Modal window design
  83. local window = ModalWindow {
  84. title = config.craftTitle..config.system[lastChoice].vocation, -- The title of the vocation specific window
  85. message = config.craftMsg..config.system[lastChoice].vocation..".\n\n", -- The message of the vocation specific window
  86. }
  87.  
  88. -- Add buttons to the window (Note: if you change the names of these you must change the functions in the modal window functionallity!)
  89. window:addButton("Back", buttonCallback)
  90. window:addButton("Exit")
  91. window:addButton("Details", buttonCallback)
  92. window:addButton("Craft", buttonCallback)
  93.  
  94. -- Set what button is pressed when the player presses enter or escape
  95. window:setDefaultEnterButton("Craft")
  96. window:setDefaultEscapeButton("Exit")
  97.  
  98. -- Add choices from the action script
  99. for i = 1, #config.system[lastChoice].items do
  100. window:addChoice(config.system[lastChoice].items[i].item)
  101. end
  102.  
  103. -- Send the window to player
  104. window:sendToPlayer(self)
  105. end
Add Comment
Please, Sign In to add comment