Postado Outubro 9, 2017 7 anos Eu gostaria do comando que funcionasse assim: !buyitem / !buyvocation Ao ser usado o comando, ele te tira umas moedas (configuravel) e te da um item. @Dwarfer @antharaz
Postado Outubro 9, 2017 7 anos Solução Os comandos !buyitem e !buyvocation são separados, ok? Fiz umas modificações em uns que eu tinha feito anteriomente. Ambos são simples. 1. /shop Em talkactions/scripts crie um arquivo: easyshop.lua Spoiler local t = { minlevel = 10, -- level mínimo para usar o shop goldID = 6527, -- id da moeda shop = { ["white mushroom"] = {count = 100, price = 20}, -- count = quantidade do item, price = preço ["iron ore"] = {count = 100, price = 50}, ["dwarven shield"] = {count = 5, price = 10}, ["pick"] = {count = 2, price = 1} }} function getShopItems() local text = "~~[Easy Shop]~~\n\nAccepting: "..Fupper(getItemNameById(t.goldID)).."\n\n" local index = 0 for i, v in pairs(t.shop) do index = index + 1 text = text.. index.. ". ".. Fupper(i).." - Count: "..v.count.." | Price: " .. v.price .. "\n" end return text end function Fupper(str) -- by dwarfer return (str:gsub("^%l", string.upper)) end function onSay(cid, words, param) local p = getPlayerPosition(cid) if getPlayerLevel(cid) < t.minlevel then doPlayerSendCancel(cid, "You need at least level " .. t.minlevel .. " to buy at the shop.") doSendMagicEffect(p, CONST_ME_POFF) return true end local param = param:lower() if param == "" then doPlayerPopupFYI(cid, getShopItems()) return true end local shop = t.shop[param] if (not shop) then doPlayerSendCancel(cid, "The shop is not offering this item. See the offers with /shop.") doSendMagicEffect(p, CONST_ME_POFF) return true end if getPlayerItemCount(cid, t.goldID) < shop.price then doPlayerSendCancel(cid, "You need " .. shop.price .. " " .. getItemNameById(t.goldID).." to buy "..shop.count.." " .. param .. ".") doSendMagicEffect(p, CONST_ME_POFF) return true end doPlayerRemoveItem(cid, t.goldID, shop.price) local itemid = getItemIdByName(param) if (not isItemStackable(itemid)) then for i = 1, shop.count do doPlayerAddItem(cid, itemid, i) end else doPlayerAddItem(cid, itemid, shop.count) end doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have bought " .. shop.count.. " " .. param .. ".") doSendMagicEffect(p, CONST_ME_STUN) return true end Em talkactions.xml, adicione a tag: <talkaction words="/shop" event="script" value="easyshop.lua"/> Exemplos de uso: /shop -- mostra as informações do shop /shop dwarven shield - compra o dwarven shield 2. /buyvocation Em talkactions/scripts, crie um arquivo: buyvocation.lua Spoiler local voc_seller = { [1] = {buy = {2,5,6}}, -- vocação de id [1] = compra = {id 2, id 5, id, 6} [2] = {buy = {1,5,6}}, [3] = {buy = {1,5,6}} } local config = { goldID = 6527, -- id da moeda price = 100, -- preço onlyOnce = true, -- comprar somente uma vez? true ou false stor = 78340 -- modifique somente se necessário } function getInfoVocSeller() local text = "[Vocations Seller]\n\n" for i, v in pairs(voc_seller) do local vocs = "" for k = 1, #v.buy do vocs = vocs .. getVocationInfo(v.buy[k]).name .. (k ~= #v.buy and ", " or "") end text = text .. getVocationInfo(i).name .. "s can buy: " .. vocs .. "\n" end return text end function onSay(cid, words, param) local p = getPlayerPosition(cid) local t = voc_seller[getPlayerVocation(cid)] if not t then doPlayerSendCancel(cid, "Your vocation are not allowed to buy vocations.") doSendMagicEffect(p, CONST_ME_POFF) return true end if config.onlyOnce and getPlayerStorageValue(cid, config.stor) ~= -1 then doPlayerSendCancel(cid, "You have already bought a vocation.") doSendMagicEffect(p, CONST_ME_POFF) return true end if param == "" then doPlayerPopupFYI(cid, getInfoVocSeller()) return true end local param = param:lower() local newvoc = getVocationIdByName(param) local currentvoc = getPlayerVocation(cid) if not newvoc then doPlayerSendCancel(cid, "This vocation does not exist.") doSendMagicEffect(p, CONST_ME_POFF) return true end if newvoc == currentvoc then doPlayerSendCancel(cid, "You are already a " .. getVocationInfo(currentvoc).name .. ".") doSendMagicEffect(p, CONST_ME_POFF) return true end if (not isInArray(t.buy, newvoc)) then doPlayerSendCancel(cid, "You are not allowed to buy this vocation.") doSendMagicEffect(p, CONST_ME_POFF) return true end if (not doPlayerRemoveItem(cid, config.goldID, config.price)) then doPlayerSendCancel(cid, "You need " .. config.price .. " " .. getItemNameById(config.goldID).." to buy a vocation.") doSendMagicEffect(p, CONST_ME_POFF) return true end doPlayerSetVocation(cid, newvoc) doCreatureSay(cid, "You have bought a vocation!", TALKTYPE_ORANGE_1) doSendMagicEffect(p, CONST_ME_HOLYAREA) if config.onlyOnce then setPlayerStorageValue(cid, config.stor, 1) end return true end function getVocationIdByName(name) --by dwarfer local file = "data/xml/vocations.xml" -- your vocations xml path local openFile = io.open(file, "r") local v_name, getName, getID = 0,0,0 local vocid = nil if openFile ~= nil then for line in io.lines(file) do if line:find('name=".*".*') then getName = string.match(line, 'name=".*".*') if getName then v_name = string.sub(getName, string.find(getName, '="') + 2, (string.find(getName, '" ') or string.find(getName, '"f') or 1) - 1) end if v_name:lower() == name:lower() then getID = string.match(line,'id=".*".*') vocid = tonumber(string.sub(getID, string.find(getID, '="') + 2, (string.find(getID, '" ') or string.find(getID, '"f') or 1) - 1)) end end end openFile:close() end return vocid end Em talkactions.xml, adicione a tag: <talkaction words="/buyvocation" event="script" value="buyvocation.lua"/> Exemplos de uso: /buyvocation -- informações sobre as vocações que podem ser compradas /buyvocation sorcerer -- o player compra a vocação sorcerer Essa última é pra ser bem simples, então não vou fazer modificações como mudar skills, hp, entre outros, já existem sistemas assim no fórum. Valeu. Contato: Email: [email protected] Discord: Dwarfer#2715
Participe da conversa
Você pode postar agora e se cadastrar mais tarde. Se você tem uma conta, faça o login para postar com sua conta.