Advertisement
Guest User

Untitled

a guest
May 24th, 2016
1,194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.35 KB | None | 0 0
  1. function Player:sendAddonWindow(outfits)
  2. local function buttonCallback(button, choice)
  3. local outfitName = string.lower(outfits[choice.id].name) -- Converts the outfit name to lowercase
  4. -- Modal window functionallity
  5. if button.text == "Confirm" then
  6. -- Start Checks
  7. -- Check if player has addon doll in backpack.
  8. if self:getItemCount(outfits.dollID) == 0 then
  9. self:sendAddonWindow_noDoll(outfits)
  10. return false
  11. end
  12.  
  13. -- If choiceID equals 0 return false and close window (If player alread has all addons choiceID will be 0).
  14. if choice.id == 0 then
  15. return false
  16. end
  17.  
  18. -- Check if player already has the outfit if true send error message and reopen window
  19. if self:hasOutfit(outfits[choice.id].male, 3) or self:hasOutfit(outfits[choice.id].female, 3) == true then
  20. self:sendAddonWindow_owned(outfits)
  21. return false
  22. end
  23.  
  24. -- Check player sex and grant addon based on it.
  25. if self:getSex() == 0 then
  26. self:addOutfitAddon(outfits[choice.id].female, 3)
  27. else
  28. self:addOutfitAddon(outfits[choice.id].male, 3)
  29. end
  30. end
  31. -- End Checks
  32.  
  33. -- Remove addon doll, send confirmation message and send super special sparkles.
  34. self:removeItem(outfits.dollID, 1)
  35. self:getPosition():sendMagicEffect(CONST_ME_FIREWORK_YELLOW)
  36. self:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You can now wear the " ..outfitName.. " outfit and addons!")
  37. end
  38.  
  39. -- Modal window design
  40. local window = ModalWindow {
  41. title = outfits.mainTitle, -- Title of the modal window
  42. message = outfits.mainMsg, -- The message to be displayed on the modal window
  43. }
  44.  
  45. -- Add buttons to the window (Note: if you change the names of these you must change the functions in the modal window functionallity!)
  46. window:addButton("Confirm", buttonCallback)
  47. window:addButton("Cancel")
  48.  
  49. -- Set what button is pressed when the player presses enter or escape
  50. window:setDefaultEnterButton("Confirm")
  51. window:setDefaultEscapeButton("Cancel")
  52.  
  53. -- Add choices from the action script
  54. for i = 1, #outfits do
  55. local o = outfits[i].name
  56.  
  57. -- Checks what outfits player has/doesnt
  58. if not self:hasOutfit(outfits[i].male, 3) and not self:hasOutfit(outfits[i].female, 3) then
  59.  
  60. -- Add Nobleman or Noblewoman
  61. if o == "Noble" or o == "Norse" then
  62. if self:getSex() == 0 then
  63. o = o .. "woman"
  64. else
  65. o = o .. "man"
  66. end
  67. end
  68.  
  69. -- Add choice if player does not have outfit
  70. local choice = window:addChoice(o)
  71. else
  72. -- Add "[Owned]" to the choice if player already has it.
  73. local choice = window:addChoice(o.." [Owned]")
  74. end
  75. end
  76.  
  77. -- Send the window to player
  78. window:sendToPlayer(self)
  79. end
  80.  
  81.  
  82. --- The modal window that is played if player already has the addon.
  83. function Player:sendAddonWindow_owned(outfits)
  84. local function buttonCallback(button, choice)
  85.  
  86. if button.text == "Back" then
  87. self:sendAddonWindow(outfits)
  88. end
  89. end
  90. -- Modal window design
  91. local window = ModalWindow {
  92. title = outfits.ownedTitle, -- Title of the modal window
  93. message = outfits.ownedMsg, -- The message to be displayed on the modal window
  94. }
  95.  
  96. -- Add buttons to the window (Note: if you change the names of these you must change the functions in the modal window functionallity!)
  97. window:addButton("Back", buttonCallback)
  98.  
  99. -- Set what button is pressed when the player presses enter or escape
  100. window:setDefaultEnterButton("Back")
  101. window:setDefaultEscapeButton("Back")
  102.  
  103. -- Send the window to player
  104. window:sendToPlayer(self)
  105. end
  106.  
  107. --- The modal window that is displayed if the player doesnt have the doll in his BP
  108. function Player:sendAddonWindow_noDoll(outfits)
  109. local function buttonCallback(button, choice)
  110.  
  111. if button.text == "Back" then
  112. self:sendAddonWindow(outfits)
  113. end
  114.  
  115. end
  116. -- Modal window design
  117. local window = ModalWindow {
  118. title = outfits.dollTitle, -- Title of the modal window
  119. message = outfits.dollMsg, -- The message to be displayed on the modal window
  120. }
  121.  
  122. -- Add buttons to the window (Note: if you change the names of these you must change the functions in the modal window functionallity!)
  123. window:addButton("Back", buttonCallback)
  124.  
  125. -- Set what button is pressed when the player presses enter or escape
  126. window:setDefaultEnterButton("Back")
  127. window:setDefaultEscapeButton("Back")
  128.  
  129. -- Send the window to player
  130. window:sendToPlayer(self)
  131. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement