Guest User

Untitled

a guest
May 24th, 2016
410
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.67 KB | None | 0 0
  1. function Player:sendMountWindow(mounts)
  2. local function buttonCallback(button, choice)
  3. local mountName = string.lower(mounts[choice.id].name) -- Converts the mount name to lowercase
  4. -- Modal window functionallity
  5. if button.text == "Confirm" then
  6. -- Start Checks
  7. -- Check if player already has the mount if true send error message and reopen window
  8. if self:hasMount(mounts[choice.id].ID) == true then
  9. self:sendMountWindow_owned(mounts)
  10. return false
  11. end
  12.  
  13. -- Check if player has mount doll in backpack.
  14. if self:getItemCount(mounts.dollID) == 0 then
  15. self:sendMountWindow_noDoll(mounts)
  16. return false
  17. end
  18. end
  19. -- End Checks
  20.  
  21. -- Add mount to play, remove mount doll, send confirmation message and send super special sparkles.
  22. self:addMount(mounts[choice.id].ID)
  23. self:removeItem(mounts.dollID, 1)
  24. self:getPosition():sendMagicEffect(CONST_ME_FIREWORK_YELLOW)
  25. self:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You can now use the " ..mountName.. " mount!")
  26. end
  27.  
  28. -- Modal window design
  29. local window = ModalWindow {
  30. title = mounts.mainTitle, -- Title of the modal window
  31. message = mounts.mainMsg, -- The message to be displayed on the modal window
  32. }
  33.  
  34. -- Add buttons to the window (Note: if you change the names of these you must change the functions in the modal window functionallity!)
  35. window:addButton("Confirm", buttonCallback)
  36. window:addButton("Cancel")
  37.  
  38. -- Set what button is pressed when the player presses enter or escape
  39. window:setDefaultEnterButton("Confirm")
  40. window:setDefaultEscapeButton("Cancel")
  41.  
  42. -- Add choices from the action script
  43. for i = 1, #mounts do
  44. local o = mounts[i].name
  45.  
  46. -- Checks what mounts player has/doesnt
  47. if not self:hasMount(mounts[i].ID) then
  48. -- Add choice if player does not have mount
  49. window:addChoice(o)
  50. else
  51. -- Add "[Owned]" to the choice if player already has it.
  52. window:addChoice(o.." [Owned]")
  53. end
  54. end
  55.  
  56. -- Send the window to player
  57. window:sendToPlayer(self)
  58. end
  59.  
  60.  
  61. --- The modal window that is played if player already has the addon.
  62. function Player:sendMountWindow_owned(mounts)
  63. local function buttonCallback(button, choice)
  64.  
  65. if button.text == "Back" then
  66. self:sendMountWindow(mounts)
  67. end
  68. end
  69. -- Modal window design
  70. local window = ModalWindow {
  71. title = mounts.ownedTitle, -- Title of the modal window
  72. message = mounts.ownedMsg, -- The message to be displayed on the modal window
  73. }
  74.  
  75. -- Add buttons to the window (Note: if you change the names of these you must change the functions in the modal window functionallity!)
  76. window:addButton("Back", buttonCallback)
  77.  
  78. -- Set what button is pressed when the player presses enter or escape
  79. window:setDefaultEnterButton("Back")
  80. window:setDefaultEscapeButton("Back")
  81.  
  82. -- Send the window to player
  83. window:sendToPlayer(self)
  84. end
  85.  
  86. --- The modal window that is displayed if the player doesnt have the doll in his BP
  87. function Player:sendMountWindow_noDoll(mounts)
  88. local function buttonCallback(button, choice)
  89.  
  90. if button.text == "Back" then
  91. self:sendMountWindow(mounts)
  92. end
  93. end
  94. -- Modal window design
  95. local window = ModalWindow {
  96. title = mounts.dollTitle, -- Title of the modal window
  97. message = mounts.dollMsg, -- The message to be displayed on the modal window
  98. }
  99.  
  100. -- Add buttons to the window (Note: if you change the names of these you must change the functions in the modal window functionallity!)
  101. window:addButton("Back", buttonCallback)
  102.  
  103. -- Set what button is pressed when the player presses enter or escape
  104. window:setDefaultEnterButton("Back")
  105. window:setDefaultEscapeButton("Back")
  106.  
  107. -- Send the window to player
  108. window:sendToPlayer(self)
  109. end
Add Comment
Please, Sign In to add comment