Jump to content

[TFS 1.2] Modal Addon e Mount Dolls.


Sirarcken
 Share

Recommended Posts

Visto que agora e aonda do tfs 1.2 vou trazer umas paradas do forum gringo.
E como não vi no forum, acho que e bizu.
Addon doll e Mount Doll por Modal Window... é fácil e simples.

 

Brick_Window.gifPrimeiro vamos precisar instalar o modal window.Brick_Window.gif
va em data/lib/lib.lua e adiciona:

dofile('data/lib/modalwindow.lua')

Depois na pasta data/Lib crie um arquivo chamado modalwindow e adiciona esse code.

Spoiler
if not modalWindows then        modalWindows = {                modalWindowConstructor = ModalWindow,                nextFreeId = 500,                 windows = {}        }end local MT = {}MT.__index = MT function ModalWindow(...)        local args = {...}        if type(args[1]) == 'table' then                local self = setmetatable(args[1], MT)                local id = modalWindows.nextFreeId                             self.id = id                self.buttons = {}                self.choices = {}                self.players = {}                self.created = false                 modalWindows.nextFreeId = id + 1                table.insert(modalWindows.windows, self)                return self        end         return modalWindows.modalWindowConstructor(...)end function MT:setDefaultCallback(callback)        self.defaultCallback = callbackend function MT:addButton(text, callback)        local button = {text = tostring(text), callback = callback}        table.insert(self.buttons, button)        return buttonend function MT:addButtons(...)        for _, text in ipairs({...}) do                table.insert(self.buttons, {text = tostring(text)})        endend function MT:addChoice(text)        local choice = {text = tostring(text)}        table.insert(self.choices, choice)        return choiceend function MT:addChoices(...)        for _, text in ipairs({...}) do                table.insert(self.choices, {text = tostring(text)})        endend function MT:setDefaultEnterButton(text)        self.defaultEnterButton = textend function MT:setDefaultEscapeButton(text)        self.defaultEscapeButton = textend function MT:setTitle(title)        self.title = tostring(title)end function MT:setMessage(message)        self.message = tostring(message)end local buttonOrder = {        [4] = {3, 4, 2, 1},        [3] = {2, 3, 1},        [2] = {1, 2},        [1] = {1}}function MT:create()        local modalWindow = modalWindows.modalWindowConstructor(self.id, self.title, self.message)        local order = buttonOrder[math.min(#self.buttons, 4)]         if order then                for _, i in ipairs(order) do                        local button = self.buttons[i]                        modalWindow:addButton(i, button.text)                        button.id = i                         if button.text == self.defaultEnterButton then                                modalWindow:setDefaultEnterButton(i)                        elseif button.text == self.defaultEscapeButton then                                modalWindow:setDefaultEscapeButton(i)                        end                end        end         for _, choice in ipairs(self.choices) do                modalWindow:addChoice(_, choice.text)                choice.id = _        end         self.modalWindow = modalWindowend function MT:sendToPlayer(player)        if not self.modalWindow then                self:create()        end         player:registerEvent('ModalWindowHelper')        self.players[player:getId()] = true        return self.modalWindow:sendToPlayer(player)end

 

Agora em data/creaturescripts/creaturescripts.xml

Add a tag.

<event type="modalwindow" name="ModalWindowHelper" script="modalwindowhelper.lua" />

Agora crie um arquivo chamado modalwindowhelper. e add o code nele.

Spoiler
function onModalWindow(player, modalWindowId, buttonId, choiceId)        local modalWindow        for _, window in ipairs(modalWindows.windows) do                if window.id == modalWindowId then                        modalWindow = window                        break                end        end         if not modalWindow then                return true        end         local playerId = player:getId()        if not modalWindow.players[playerId] then                return true        end        modalWindow.players[playerId] = nil         local choice = modalWindow.choices[choiceId]         for _, button in ipairs(modalWindow.buttons) do                if button.id == buttonId then                        local callback = button.callback or modalWindow.defaultCallback                        if callback then                                callback(button, choice)                                break                        end                end        end         return trueend

 

 

 

 

Assassin_Doll.gifPronto a parte da janela esta feita, agora vamos ao  Addon Assassin_Doll.gif

 

 

 

 

em actions.xml add.

 <action itemid="ITEMID" script="addon_doll.lua"/>

em item id coloque o id que desejar, depois disso crie um arquivo chamado de addon_doll.lua e add.

Spoiler
local outfits = { -- Config    dollID = 8982, -- Change this to your dolls or items, item ID     -- Main Window Messages (The first window the player sees)    mainTitle = "Choose an outfit",    mainMsg = "You will recieve both addons aswell as the outfit you choose.",       -- Already Owned Window (The window that appears when the player already owns the addon)    ownedTitle = "Whoops!",    ownedMsg = "You already have this addon. Please choose another.",       -- No Doll in Backpack (The window that appears when the player doesnt have the doll in their backpack)    dollTitle = "Whoops!",    dollMsg = "The addon doll must be in your backpack.",-- End Config    -- Outfit Table    [1] = {name = "Citizen", male = 128, female = 136},    [2] = {name = "Hunter", male = 129, female = 137},    [3] = {name = "Mage", male = 130, female = 138},    [4] = {name = "Knight", male = 131, female = 139},    [5] = {name = "Noble", male = 132, female = 140},    [6] = {name = "Summoner", male = 133, female = 141},    [7] = {name = "Warrior", male = 134, female = 142},    [8] = {name = "Barbarian", male = 143, female = 147},    [9] = {name = "Druid", male = 144, female = 148},    [10] = {name = "Wizard", male = 145, female = 149},    [11] = {name = "Oriental", male = 146, female = 150},    [12] = {name = "Pirate", male = 151, female = 155},    [13] = {name = "Assassin", male = 152, female = 156},    [14] = {name = "Beggar", male = 153, female = 157},    [15] = {name = "Shaman", male = 154, female = 158},    [16] = {name = "Norse", male = 251, female = 252},    [17] = {name = "Nightmare", male = 268, female = 269},    [18] = {name = "Jester", male = 273, female = 270},    [19] = {name = "Brotherhood", male = 278, female = 279},    [20] = {name = "Demonhunter", male = 289, female = 288},    [21] = {name = "Yalaharian", male = 325, female = 324},    [22] = {name = "Warmaster", male = 335, female = 336},    [23] = {name = "Wayfarer", male = 367, female = 366},    [24] = {name = "Afflicted", male = 430, female = 431},    [25] = {name = "Elementalist", male = 432, female = 433},    [26] = {name = "Deepling", male = 463, female = 464},    [27] = {name = "Insectoid", male = 465, female = 466},    [28] = {name = "Entrepreneur", male = 472, female = 471},    [29] = {name = "Crystal Warlord", male = 512, female = 513},    [30] = {name = "Soil Guardian", male = 516, female = 514},    [31] = {name = "Demon", male = 541, female = 542},    [32] = {name = "Cave Explorer", male = 574, female = 575},    [33] = {name = "Dream Warden", male = 577, female = 578},    [34] = {name = "Champion", male = 633, female = 632},    [35] = {name = "Conjurer", male = 634, female = 635},    [36] = {name = "Beastmaster", male = 637, female = 636},    [37] = {name = "Chaos Acolyte", male = 665, female = 664},    [38] = {name = "Death Herald", male = 667, female = 666},    [39] = {name = "Ranger", male = 684, female = 683},    [40] = {name = "Ceremonial Garb", male = 695, female = 694},    [41] = {name = "Puppeteer", male = 697, female = 696},    [42] = {name = "Spirit Caller", male = 699, female = 698},    [43] = {name = "Evoker", male = 725, female = 724},    [44] = {name = "Seaweaver", male = 733, female = 732},    [45] = {name = "Recruiter", male = 746, female = 745},    [46] = {name = "Sea Dog", male = 750, female = 749},    [47] = {name = "Halloween", male = 760, female = 759},} function onUse(player, item, fromPosition, itemEx, toPosition, isHotkey)    player:sendAddonWindow(outfits)    return trueend

 

 

em global.lua add

dofile('data/lib/addon_doll.lua')

para finalizar cria um arquivo em /data/lib/ com o nome de addon_doll.lua e add o code.

Spoiler
function Player:sendAddonWindow(outfits)    local function buttonCallback(button, choice)        local outfitName = string.lower(outfits[choice.id].name) -- Converts the outfit name to lowercase    -- Modal window functionallity        if button.text == "Confirm" then        -- Start Checks            -- Check if player has addon doll in backpack.            if self:getItemCount(outfits.dollID) == 0 then                self:sendAddonWindow_noDoll(outfits)                return false            end                       -- If choiceID equals 0 return false and close window (If player alread has all addons choiceID will be 0).            if choice.id == 0 then                return false            end                       -- Check if player already has the outfit if true send error message and reopen window            if self:hasOutfit(outfits[choice.id].male, 3) or self:hasOutfit(outfits[choice.id].female, 3) == true then                self:sendAddonWindow_owned(outfits)                return false            end                       -- Check player sex and grant addon based on it.            if self:getSex() == 0 then                self:addOutfitAddon(outfits[choice.id].female, 3)            else                self:addOutfitAddon(outfits[choice.id].male, 3)            end        end        -- End Checks                   -- Remove addon doll, send confirmation message and send super special sparkles.        self:removeItem(outfits.dollID, 1)        self:getPosition():sendMagicEffect(CONST_ME_FIREWORK_YELLOW)        self:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You can now wear the " ..outfitName.. " outfit and addons!")    end   -- Modal window design    local window = ModalWindow {        title = outfits.mainTitle, -- Title of the modal window        message = outfits.mainMsg, -- The message to be displayed on the modal window    }     -- Add buttons to the window (Note: if you change the names of these you must change the functions in the modal window functionallity!)    window:addButton("Confirm", buttonCallback)    window:addButton("Cancel")     -- Set what button is pressed when the player presses enter or escape    window:setDefaultEnterButton("Confirm")    window:setDefaultEscapeButton("Cancel")     -- Add choices from the action script    for i = 1, #outfits do    local o = outfits[i].name           -- Checks what outfits player has/doesnt        if not self:hasOutfit(outfits[i].male, 3) and not self:hasOutfit(outfits[i].female, 3) then                   -- Add Nobleman or Noblewoman            if o == "Noble" or o == "Norse" then                if self:getSex() == 0 then                    o = o .. "woman"                else                    o = o .. "man"                end            end                       -- Add choice if player does not have outfit            local choice = window:addChoice(o)        else            -- Add "[Owned]" to the choice if player already has it.            local choice = window:addChoice(o.." [Owned]")        end    end     -- Send the window to player    window:sendToPlayer(self)end  --- The modal window that is played if player already has the addon.function Player:sendAddonWindow_owned(outfits)    local function buttonCallback(button, choice)           if button.text == "Back" then            self:sendAddonWindow(outfits)        end    end-- Modal window design    local window = ModalWindow {        title = outfits.ownedTitle, -- Title of the modal window        message = outfits.ownedMsg, -- The message to be displayed on the modal window    }     -- Add buttons to the window (Note: if you change the names of these you must change the functions in the modal window functionallity!)    window:addButton("Back", buttonCallback)     -- Set what button is pressed when the player presses enter or escape    window:setDefaultEnterButton("Back")    window:setDefaultEscapeButton("Back")     -- Send the window to player    window:sendToPlayer(self)end --- The modal window that is displayed if the player doesnt have the doll in his BPfunction Player:sendAddonWindow_noDoll(outfits)    local function buttonCallback(button, choice)         if button.text == "Back" then            self:sendAddonWindow(outfits)        end           end-- Modal window design    local window = ModalWindow {        title = outfits.dollTitle, -- Title of the modal window        message = outfits.dollMsg, -- The message to be displayed on the modal window    }     -- Add buttons to the window (Note: if you change the names of these you must change the functions in the modal window functionallity!)    window:addButton("Back", buttonCallback)     -- Set what button is pressed when the player presses enter or escape    window:setDefaultEnterButton("Back")    window:setDefaultEscapeButton("Back")     -- Send the window to player    window:sendToPlayer(self)end

 

 

Midnight_Panther_Doll.gifPronto Addon Doll Finalizado vamos ao Mount....Midnight_Panther_Doll.gif

 

 

 

 

No arquivo /data/actions/actions.xml add.

<action itemid="ITEMID" script="mount_doll.lua"/>

Agora em /data/actions/scripts crie um arquivo com o nome mount_doll.lua e add.

Spoiler
local mounts = {-- Config    dollID = 9019, -- Change this to your dolls or items, item ID     -- Main Window Messages (The first window the player sees)    mainTitle = "Choose a Mount!",    mainMsg = "Choose a mount to unlock.",       -- Already Owned Window (The window that appears when the player already owns the addon)    ownedTitle = "Whoops!",    ownedMsg = "You already have this mount. Please choose another.",       -- No Doll in Backpack (The window that appears when the player doesnt have the doll in their backpack)    dollTitle = "Whoops!",    dollMsg = "The mount doll must be in your backpack.",-- End Config         [1] = {name = "Widow Queen", ID = 1},        [2] = {name = "Racing Bird", ID = 2},        [3] = {name = "War Bear", ID = 3},        [4] = {name = "Black Sheep", ID = 4},        [5] = {name = "Midnight Panther", ID = 5},        [6] = {name = "Draptor", ID = 6},        [7] = {name = "Titanica", ID = 7},        [8] = {name = "Tin Lizard", ID = 8},        [9] = {name = "Blazebringer", ID = 9},        [10] = {name = "Rapid Boar", ID = 10},        [11] = {name = "Stampor", ID = 11},        [12] = {name = "Undead Cavebear", ID = 12},        [13] = {name = "Donkey", ID = 13},        [14] = {name = "Tiger Slug", ID = 14},        [15] = {name = "Uniwheel", ID = 15},        [16] = {name = "Crystal Wolf", ID = 16},        [17] = {name = "War horse", ID = 17},        [18] = {name = "Kingly Deer", ID = 18},        [19] = {name = "Tamed Panda", ID = 19},        [20] = {name = "Dromedary", ID = 20},        [21] = {name = "King Scorpion", ID =21},        [22] = {name = "Rented Horse", ID = 22},        [23] = {name = "Armoured War Horse", ID = 23},        [24] = {name = "Shadow Draptor", ID =24},        [25] = {name = "Rented Horse", ID = 25},        [26] = {name = "Rented Horse", ID = 26},        [27] = {name = "Ladybug", ID = 27},        [28] = {name = "Manta Ray", ID = 28},        [29] = {name = "Ironblight", ID =29},        [30] = {name = "Magma Crawler", ID = 30},        [31] = {name = "Dragonling", ID = 31},        [32] = {name = "Gnarlhound", ID = 32},        [33] = {name = "Crimson Ray", ID = 33},        [34] = {name = "Steelbeak", ID = 34},        [35] = {name = "Water Buffalo", ID = 35},        [36] = {name = "Tombstinger", ID = 36},        [37] = {name = "Platesaurian", ID = 37},        [38] = {name = "Ursagrodon", ID = 38},        [39] = {name = "The Hellgrip", ID = 39},        [40] = {name = "Noble Lion", ID = 40},        [41] = {name = "Desert King", ID = 41},        [42] = {name = "Shock Head", ID = 42},        [43] = {name = "Walker", ID = 43},        [44] = {name = "Azudocus", ID = 44},        [45] = {name = "Carpacosaurus", ID = 45},        [46] = {name = "Death Crawler", ID = 46},        [47] = {name = "Flamesteed", ID = 47},        [48] = {name = "Jade Lion", ID = 48},        [49] = {name = "Jade Pincer", ID = 49},        [50] = {name = "Nethersteed", ID = 50},        [51] = {name = "Tempest", ID = 51},        [52] = {name = "Winter King", ID = 52},        [53] = {name = "Doombringer", ID = 53},        [54] = {name = "Woodland Prince", ID = 54},        [55] = {name = "Hailtorm Fury", ID = 55},        [56] = {name = "Siegebreaker", ID = 56},        [57] = {name = "Poisonbane", ID = 57},        [58] = {name = "Blackpelt", ID = 58},        [59] = {name = "Golden Dragonfly", ID = 59},        [60] = {name = "Steel Bee", ID = 60},        [61] = {name = "Copper Fly", ID = 61},        [62] = {name = "Tundra Rambler", ID = 62},        [63] = {name = "Highland Yak", ID = 63},        [64] = {name = "Glacier Vagabond", ID = 64},        [65] = {name = "Glooth Glider", ID = 65},        [66] = {name = "Shadow Hart", ID = 66},        [67] = {name = "Black Stag", ID = 67},        [68] = {name = "Emperor Deer", ID = 68},        [69] = {name = "Flying Divan", ID = 69},        [70] = {name = "Magic Carpet", ID = 70},        [71] = {name = "Floating Kashmir", ID = 71},        [72] = {name = "Ringtail Wazzoon", ID = 72},        [73] = {name = "Night Wazzoon", ID = 73},        [74] = {name = "Emerald Waccoon", ID = 74},        [75] = {name = "Flitterkatzen", ID = 75},        [76] = {name = "Venompaw", ID = 76},        [77] = {name = "Batcat", ID = 77},        [78] = {name = "Sea Devil", ID = 78},        [79] = {name = "Coralripper", ID = 79},        [80] = {name = "Plumfish", ID = 80},        [81] = {name = "Gorongra", ID = 81},        [82] = {name = "Noctungra", ID = 82},        [83] = {name = "Silverneck", ID = 83},        [84] = {name = "Kimera", ID = 84},        [85] = {name = "Kimera Devil", ID = 85},        [86] = {name = "Shadow Beast", ID = 86},           }   function onUse(player, item, fromPosition, itemEx, toPosition, isHotkey)    player:sendMountWindow(mounts)end

 

Agora no arquivo data/global.xml add.

dofile('data/lib/mount_doll.lua')

agora em /data/lib/ crie um arquivo com o nome "mount_doll.lua" e add.

Spoiler
function Player:sendMountWindow(mounts)    local function buttonCallback(button, choice)        local mountName = string.lower(mounts[choice.id].name) -- Converts the mount name to lowercase    -- Modal window functionallity        if button.text == "Confirm" then        -- Start Checks            -- Check if player already has the mount if true send error message and reopen window            if self:hasMount(mounts[choice.id].ID) == true then                self:sendMountWindow_owned(mounts)                return false            end                       -- Check if player has mount doll in backpack.            if self:getItemCount(mounts.dollID) == 0 then                self:sendMountWindow_noDoll(mounts)                return false            end        end        -- End Checks                   -- Add mount to play, remove mount doll, send confirmation message and send super special sparkles.        self:addMount(mounts[choice.id].ID)        self:removeItem(mounts.dollID, 1)        self:getPosition():sendMagicEffect(CONST_ME_FIREWORK_YELLOW)        self:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You can now use the " ..mountName.. " mount!")    end   -- Modal window design    local window = ModalWindow {        title = mounts.mainTitle, -- Title of the modal window        message = mounts.mainMsg, -- The message to be displayed on the modal window    }     -- Add buttons to the window (Note: if you change the names of these you must change the functions in the modal window functionallity!)    window:addButton("Confirm", buttonCallback)    window:addButton("Cancel")     -- Set what button is pressed when the player presses enter or escape    window:setDefaultEnterButton("Confirm")    window:setDefaultEscapeButton("Cancel")     -- Add choices from the action script    for i = 1, #mounts do    local o = mounts[i].name           -- Checks what mounts player has/doesnt        if not self:hasMount(mounts[i].ID) then            -- Add choice if player does not have mount            window:addChoice(o)        else            -- Add "[Owned]" to the choice if player already has it.            window:addChoice(o.." [Owned]")        end    end     -- Send the window to player    window:sendToPlayer(self)end  --- The modal window that is played if player already has the addon.function Player:sendMountWindow_owned(mounts)    local function buttonCallback(button, choice)           if button.text == "Back" then            self:sendMountWindow(mounts)        end    end-- Modal window design    local window = ModalWindow {        title = mounts.ownedTitle, -- Title of the modal window        message = mounts.ownedMsg, -- The message to be displayed on the modal window    }     -- Add buttons to the window (Note: if you change the names of these you must change the functions in the modal window functionallity!)    window:addButton("Back", buttonCallback)     -- Set what button is pressed when the player presses enter or escape    window:setDefaultEnterButton("Back")    window:setDefaultEscapeButton("Back")     -- Send the window to player    window:sendToPlayer(self)end --- The modal window that is displayed if the player doesnt have the doll in his BPfunction Player:sendMountWindow_noDoll(mounts)    local function buttonCallback(button, choice)         if button.text == "Back" then            self:sendMountWindow(mounts)        end    end-- Modal window design    local window = ModalWindow {        title = mounts.dollTitle, -- Title of the modal window        message = mounts.dollMsg, -- The message to be displayed on the modal window    }     -- Add buttons to the window (Note: if you change the names of these you must change the functions in the modal window functionallity!)    window:addButton("Back", buttonCallback)     -- Set what button is pressed when the player presses enter or escape    window:setDefaultEnterButton("Back")    window:setDefaultEscapeButton("Back")     -- Send the window to player    window:sendToPlayer(self)end

 

 

 

 

Pronto codigo finalizado.

Espero que seja útil, lembrando não foi eu quem fiz, mais qualquer duvida e so falar que tento ajudar.

foi o membro Strutz de um fórum gringo.

Créditos todo dele.

Edited by Sirarcken
Link to comment
Share on other sites

 Share

×
×
  • Create New...