Ir para conteúdo

[Talkaction] Sistema De Shop Para Players


Saymon14

Posts Recomendados

 

Nome: Advanced Auction House v1.0


Autor: josejunior23
Server testado: Real Server 8.60



Como funciona?


A ideia é do WoW(World of Warcraft), o Auction-House,
que você poe lá items, e espera que outro jogador o compre
caso ninguém compre, ele será removido apos X dias.



Comandos:


 

!auction-sell itemname, ammount, price - para adicionar um item a lista de ofertas.


!auction-buy OfferID - para comprar item pelo OfferID
!auction-find itemname - para procurar ofertas pelo nome do item
!auction-del OfferID - para apagar uma oferta feita por você
!auction-info OfferID - para mostrar info sobre uma oferta pelo OfferID
!auction-list - mostrar uma lista completa com os items.
!auction-list PLAYER_NAME - mostra uma lista com os items de PLAYER_NAME
!auction-cmd - mostra uma lista com todos os comandos.
!auction-clean - apagara todas as ofertas com a mesma data de quem usar o comando.(access 3+)
!auction-clean 01/01/11 - apagara todas as ofertas com a data 01/01/11 que você pode mudar(access 3+)
!auction-balance - ver a quantidade de dinheiro que tem em sua Auction-house
!auction-withdraw - para pegar seu dinheiro

 



Informações:
- Os items são guardado em um ficheiro .txt e não em uma database.
- os items ficam guardados assim:
01/01/11 3031 2000 10 2
data, item, preço, quantidade, guid do player

1º - cria um ficheiro XML na pasta mods chamado ADVANCED-AUCTION-HOUSE, e poe isso dentro:

 

<?xml version="1.0" encoding="UTF-8"?><mod name="ADVANCED AUCTION HOUSE" version="1.0" author="josejunior23" contact="x1zy@hotmail.com" enabled="yes"><talkaction words="!auction-sell;!auction-buy;!auction-list;!auction-info;!auction-del;!auction-cmd;!auction;!auction-find;!auction-clean;!auction-withdraw;!auction-balance" case-sensitive="yes" event="script" value="AAH.lua"/><globalevent name="aution_check" time="00:01" event="script" value="AAH.lua"/></mod>

 



2º - crie um ficheiro .LUA na pasta mods/scripts chamado AAH e poe isso dentro:

 

--######################################### ABOUT #################-- Advanced Auction House ####-- code by josejunior23 ####-- the function add_depot_item(guid, item, count) as made by magus from ###### ####-- any other code in this file as made by me. ####-- ... and thanks to the TFS, they make it more easy "" ####--######################################### CONFIG ################################################## ##############local max_days, bad_items, able_items, max_offer, max_items, main_file, item_show, access_need =-- # J #2, -- 1º - - when player add an offer, his offer will stay for X days, in this case 2. # O #{"gold coin", "crystal coin", "platinum coin", "worm"}, -- 2º - - put here all items that you dont want players put for sale. # S #{able_runes = false, able_potions = true}, -- 3º - - choose if you want to player sell runes/pots # E #40000000, -- 4º - - max offer that players may ask for his item's, in this case 40 000 000 golds (40kk). # J #5, -- 5º - - max items that each player can put for sale, in this case 5. # R #'houseItems.txt', -- 6º - <###MAIN FILE###> - this is the name of the MAIN FILE, where the script save the offers.. # 2 #2160, -- 7º - - this show a crystal coin (itemid: 2160) when player say ex: !auction-list [param # 3 #3 -- 8º - - this is the access You need to use command !auction-clean ####--################################################## ################################################## ######################-- ########## LIB FUNCTIONS ###########function load_table(file)local t = { }for m in io.lines(file) dolocal d, i, c, a, s = m:match '(%S+)%s+(%S+)%s+(%S+)%s+(%S+)%s+(%S+)'table.insert(t, {date = d, item = i, cost = c, ammount = a, seller = s })endreturn tendfunction save_table(file, text)local f = io.open(file,"w")f:write(text)f:close()endfunction add_new_line(file, arr)local tab = load_table(file)table.insert(tab, {date = arr.d, item = arr.i, cost = arr.c, ammount = arr.a, seller = arr.s })save_table(file, covert_table(tab))endfunction del_line_by_id(file, id)local tab = load_table(file)table.remove (tab, id)save_table(file, covert_table(tab))endfunction covert_table(tab)local t = ""for i in pairs(tab) dot = t .. "" .. tab[i].date .. " " .. tab[i].item .. " " .. tab[i].cost .. " " .. tab[i].ammount .. " " .. tab[i].seller .. "\n"endreturn tendfunction get_ramdom_thing(tab)return tab[math.random(1, #tab)]endfunction list_items(tab, str)local i = 0if(str == nil) then str = "" endfor id in pairs(tab) doi = i + 1if(tab[id].x) then i = tab[id].x endstr = str .. "\n " .. i .. "# " .. tab[id].ammount .. "x " .. getItemNameById(tab[id].item) .. " " .. tab[id].cost .. " " .. getPlayerNameByGUID(tab[id].seller)endlocal txt = { "`!auction-buy id´\n-> to buy an item.", "`!auction-sell item, ammount, price´\n-> to sell an item.", "`!auction-info id´\n-> to see more information about id offer.", "`!auction-list´\n-> to see a complete list with offers.", "`!auction-find name´\n-> to find offers by name.", "`!auction-withdraw´\n-> to get your money from our house.", "`!auction-del id´\n-> to delete an offer made by You."}return str .. "\n\nTip: " .. get_ramdom_thing(txt)endfunction get_info(file, id) -- id == linelocal tab, list = load_table(file), nilfor i = 1, #tab doif(i == id)then list = {date = tab[i].date, item = tab[i].item, cost = tab[i].cost, ammount = tab[i].ammount, seller = tab[i].seller} break endendreturn listendfunction add_depot_item(guid, item, count)-- by Maguslocal item,count = type(item)=="table" and item or {item},type(count)=="table" and count or {(count or 1)}for k,v in ipairs(item) dolocal ls = db.getResult("SELECT `sid` FROM `player_depotitems` WHERE `player_id` = "..guid.." ORDER BY `sid` DESC LIMIT 1")return db.executeQuery("INSERT INTO `player_depotitems` (`player_id`, `sid`, `pid`, `itemtype`, `count`, `attributes`) VALUES ("..guid..", "..(ls:getDataInt("sid")+1)..", 101, "..v..", "..count[k]..", '"..(count[k] > 1 and string.format("%x",count[k]) or '').."')") or falseendendfunction add_day (days)local d, m, y = tonumber(os.date("%d")) + days, tonumber(os.date("%m")), tonumber(os.date("%y"))while d > 30 do d = 01 m = m + 1 end while m > 12 do d = 01 m = 01 y = y + 1 endreturn m .. "/" .. d .. "/" .. yendfunction clean_offers(file, m)local l, t = 0, os.date("%m/%d/%y")if m then t = m endfor e in io.lines(file) dol = l + 1local d, i, c, a, s = e:match '(%S+)%s+(%S+)%s+(%S+)%s+(%S+)%s+(%S+)'if(d == t) thendel_line_by_id(file, l)l = l - 1local p = getPlayerByName(getPlayerNameByGUID(s))if(isCreature(p)) thendoPlayerAddItem(p, i, a)doPlayerSendTextMessage(p, MESSAGE_STATUS_CONSOLE_ORANGE, '[AUCTION-HOUSE]: we could not sell Your ' .. a .. 'x of `' .. getItemNameById(i) .. '´ in our house, take it back.')elselocal s, i, a = tonumber(s),tonumber(i),tonumber(a)add_depot_item(s, i, a)endendendendfunction get_player_offers(g, file)-- g = player guidlocal o, x = {}, 0for l in io.lines(file) dox = x + 1local d, i, c, a, s = l:match '(%S+)%s+(%S+)%s+(%S+)%s+(%S+)%s+(%S+)'if(tonumber(s) == g) thentable.insert(o, {date = d, item = i, cost = c, ammount = a, seller = s , x = x})endendreturn oendfunction find_offers_by_name(name, file) -- this funciton find offers with item namelocal o, x = {}, 0for l in io.lines(file) dox = x + 1local d, i, c, a, s = l:match '(%S+)%s+(%S+)%s+(%S+)%s+(%S+)%s+(%S+)'if(getItemNameById(tonumber(i)) == name) thentable.insert(o, {date = d, item = i, cost = c, ammount = a, seller = s , x = x})endendreturn oend-- ########## LIB FUNCTIONS ############-- ########## onSay FUNCTION ###########function onSay(cid, words, param, channel)if(words == "!auction-sell") thenlocal t = string.explode(param, ",")if not t[2] or not t[3] or not param or (isNumber(t[1])) or not(isNumber(t[2])) or not (isNumber(t[3])) or (tonumber(t[2]) <= 0) or (tonumber(t[2]) > 100) or (tonumber(t[3]) <= 0) or (tonumber(t[2]) > 1) and not (isItemStackable(getItemIdByName(t[1]))) thendoPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, '[AUCTION-HOUSE]: type the name of an item with ammount and offer: `!auction-sell carrion worm fang, 100, 3650´.\n Tip: `!auction-sell´ is the command, `carrion worm fang´ is the item, `100´ is the ammount, `3650´ is the price you want for it.')return trueendif(isItemContainer(getItemIdByName(t[1]))) or not (isItemMovable(getItemIdByName(t[1]))) or (isInArray(bad_items, t[1])) or (isItemFluidContainer(getItemIdByName(t[1]))) and (able_items.able_potions == false) or (isItemRune(getItemIdByName(t[1]))) and (able_items.able_runes == false) thendoPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, '[AUCTION-HOUSE]: we do not accept those kind of items.')return trueendif(max_items ~= 0) and (#get_player_offers(getPlayerGUID(cid), main_file) >= max_items) thendoPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, '[AUCTION-HOUSE]: You already have too many items in our house. You have a total of `' .. #get_player_offers(getPlayerGUID(cid), main_file) .. '´ items in our house and still can put more `' .. max_items - #get_player_offers(getPlayerGUID(cid), main_file) .. '´ items.')return trueendif(tonumber(t[3]) > max_offer) thendoPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, '[AUCTION-HOUSE]: sorry, this price is too much. the limit is: `' .. max_offer .. '´ golds.')return trueendif(doPlayerRemoveItem(cid, getItemIdByName(t[1]), t[2])) thendoPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, '[AUCTION-HOUSE]: we have added your ' .. t[2] .. 'x `' .. t[1] .. '´ as offer to our house.\n say `!auction-info ' .. #load_table(main_file) + 1 .. '´ to see more information about your offer.\nYou have a total of `' .. #get_player_offers(getPlayerGUID(cid), main_file)+1 .. '´ items in our house and still can put more `' .. (max_items == 0 and "NO LIMIT" or max_items - #get_player_offers(getPlayerGUID(cid), main_file) - 1) .. '´ items.')add_new_line(main_file, {d = add_day (max_days), i = getItemIdByName(t[1]), c = tonumber(t[3]), a = tonumber(t[2]), s = getPlayerGUID(cid)})elsedoPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, '[AUCTION-HOUSE]: could not find item `' .. t[1] .. '´ in your backpacks/slots.')endelseif(words == "!auction-buy") thenif not (isNumber(param)) thendoPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, '[AUCTION-HOUSE]: ID. Offer should be a number.')return trueendlocal f = get_info(main_file, tonumber(param))if not f thendoPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, '[AUCTION-HOUSE]: could not find results for ID. `' .. tonumber(param) .. '´.')return trueendif(doPlayerRemoveMoney(cid, f.cost) == true) thendel_line_by_id(main_file, tonumber(param))doPlayerAddItem(cid, f.item, f.ammount, false)doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, '[AUCTION-HOUSE]: You brought ' .. f.ammount .. 'x of `' .. getItemNameById(f.item) .. '´ for `' .. f.cost .. '´ golds from our house.')local pid = getPlayerByName(getPlayerNameByGUID(f.seller))if not (isCreature(pid)) thendb.executeQuery("UPDATE `players` SET `balance` = `balance` + '" .. f.cost .. "' WHERE `name` = '" .. getPlayerNameByGUID(f.seller) .. "';")return trueenddoPlayerAddMoney(pid, f.cost)doPlayerSendTextMessage(pid, MESSAGE_STATUS_CONSOLE_ORANGE, '[AUCTION-HOUSE]: we sold Your ' .. f.ammount .. 'x of `' .. getItemNameById(f.item) .. '´ in our house, heres Yours `' .. f.cost .. '´ golds.')endelseif(words == "!auction-list") thenif(param == '') thenlocal tab = load_table(main_file)if(#tab > 20) thendoShowTextDialog(cid, item_show, list_items(tab, " #-> ADVANCED AUCTION HOUSE <-#\n\n Total of `" .. #tab .. "´ items in our stock.\n\n ID. Item Gold Seller"))elsedoPlayerPopupFYI(cid, list_items(tab, " #-> ADVANCED AUCTION HOUSE <-#\n\n Total of `" .. #tab .. "´ items in our stock.\n\n ID. Item Gold Seller"))endelseif(isNumber(param)) or not (isPlayer(getPlayerByName(param))) thendoPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, '[AUCTION-HOUSE]: could not find a player online with name: `' .. param .. '´. \n Tip: remember, You can only look for offers from a player that is online. but You still can see their offers from `!auction-list´.')return trueendlocal offers = get_player_offers(getPlayerGUID(getPlayerByName(pa ram)), main_file)doShowTextDialog(cid, item_show, list_items(offers, " #-> ADVANCED AUCTION HOUSE <-#\n\n " .. string.upper(param) .. ", \n as a total of `" .. #offers .. "´ items in our stock.\n\n ID. Item Gold Seller"))endelseif(words == "!auction-info") thenif not (isNumber(param)) thendoPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, '[AUCTION-HOUSE]: ID. Offer should be a number.')return trueendlocal f = get_info(main_file, tonumber(param))if not f thendoPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, '[AUCTION-HOUSE]: could not find results for ID. `' .. tonumber(param) .. '´.')return trueendlocal txt = " #-> ADVANCED AUCTION HOUSE <-#\n Showing Offer ID. " .. tonumber(param) .."#\n\n - Expire Date: " .. f.date .. "\n - Item: x" .. f.ammount .. " " .. getItemNameById(f.item) .."\n - Cost: " .. f.cost .. " golds\n - Seller: " .. getPlayerNameByGUID(f.seller) .. ""doShowTextDialog(cid, f.item, txt)elseif(words == "!auction-del") thenif not (isNumber(param)) thendoPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, '[AUCTION-HOUSE]: ID. Offer should be a number.')return trueendlocal f = get_info(main_file, tonumber(param))if not f thendoPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, '[AUCTION-HOUSE]: could not find results for ID. `' .. tonumber(param) .. '´.')return trueendif(tonumber(f.seller) == getPlayerGUID(cid)) thendel_line_by_id(main_file, tonumber(param))doPlayerAddItem(cid, f.item, f.ammount, false)doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, '[AUCTION-HOUSE]: we removed your offer from our house, take back x' .. f.ammount .. ' of `' .. getItemNameById(f.item) .. '´.')elsedoPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, '[AUCTION-HOUSE]: You may not remove offer ID. `' .. tonumber(param) .. '´. reason: it does not belongs to You.')endelseif(words == "!auction-find") thenif(isNumber(param)) thendoPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, '[AUCTION-HOUSE]: could not find results for item `' .. tonumber(param) .. '´, make sure the name is right.')return trueendlocal tab = find_offers_by_name(param, main_file)if(#tab == 0) thendoPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, '[AUCTION-HOUSE]: could not find results for item `' .. param .. '´.')return trueenddoShowTextDialog(cid, getItemIdByName(param), list_items(tab, " #-> ADVANCED AUCTION HOUSE <-#\n\n Total of `" .. #tab .. "´ `" .. param .. "´ in our stock.\n\n ID. Item Gold Seller"))elseif(words == "!auction-cmd") or(words == "!auction") thenlocal stuff = {{"`!auction-buy id´", "to buy an item by offer id\n\n"}, {"`!auction-sell itemname, ammount, price´", "to sell an item\n\n"}, {"`!auction-info id´", "to see more information about offer id\n\n"}, {"`!auction-list´", "to see a complete list with offers\n\n"}, {"`!auction-del id´", "to delete an offer made by you\n\n"}, {"`!auction-find name´", "to find offers by name\n\n"}, {"`!auction-withdraw´", "to get your money from our house\n\n"}, {"`!auction-balance´", "to see your current balance in our house\n\n"}}local txt = " > ADVANCED AUCTION HOUSE <\n\n"for i = 1, #stuff do txt = txt .. " " .. i .. ". - " .. stuff[i][1] .. "\n > " .. stuff[i][2] end-- ^ dont ask why, I just made in this way =)doPlayerPopupFYI(cid, txt .. "\n >Code by josejunior23<")-- ^ Do not remove s2elseif(words == "!auction-withdraw") thenlocal total_money = getPlayerBalance(cid)if(total_money <= 0) thendoPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, '[AUCTION-HOUSE]: Your balance is `0´. ')return trueenddoPlayerAddMoney(cid, total_money)doPlayerSetBalance(cid, 0)doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, '[AUCTION-HOUSE]: You withdraw `' .. total_money .. '´ golds from our house. Your balance is now `0´.')elseif(words == "!auction-balance") thenlocal total_money = getPlayerBalance(cid)if(total_money <= 0) thendoPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, '[AUCTION-HOUSE]: Your balance is `0´. ')return trueenddoPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, '[AUCTION-HOUSE]: Your balance is `' .. total_money .. '´golds, You can withdraw that money at anytime, type `!aution-withdraw´ to get all Your money from our house.')elseif(words == "!auction-clean") thenif not (getPlayerAccess(cid) >= access_need) thendoPlayerSendCancel(cid, 'not a valid command>')return falseendif not (param) thenclean_offers(main_file)doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, '[AUCTION-HOUSE]: all offers with date: ' .. os.date("%m/%d/%y") .. ' as been reseted.\n Remember, the scripts ignore offers with less/more days.')return trueendif(isNumber(param)) thendoPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, '[AUCTION-HOUSE]: this is not a valid date, date format should be like in this example: ' .. os.date("%m/%d/%y") .. ' (month/day/year) . ')return trueendclean_offers(main_file, param)doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, '[AUCTION-HOUSE]: all offers with date: ' .. param .. ' as been reseted.\n Remember, the scripts ignore offers with less/more days.')endreturn trueend-- ########## onSay FUNCTION ###########-- ########## onTimer FUNCTION ##########function onTimer(cid, interval, lastExecution)clean_offers(main_file)return trueend-- ########## onTimer FUNCTION ##########

 



3º - cria um ficheiro .txt na pasta do seu server(onde fica o .exe), chamado houseItems, que ficara -> houseItems.txt

Algumas imagens do sistema:


info1vs.pnginfo2r.png
listp.pnglistyo.png
selll.png



Anexos Download:
Anexos.zip

Anexos.zip

Editado por Bennyyw
Link para o comentário
Compartilhar em outros sites

Opa Saymon, posso implantar no Tibia Sun, na próxima versão provavelmente terá este sistema no servidor. Gostei bastante, obrigado por compartilhar;

Abraços.

Link para o comentário
Compartilhar em outros sites

PAULGRANDE

 

a seção é exclusiva do outro forum nao daqui, saiba separar as coisas, e no post dele nao contia nada sobre restriçoes em postar em outro forum

 

entao fica de boa ai

Link para o comentário
Compartilhar em outros sites

Bom, como o Saymon postou os devidos créditos, acho que não haverá maiores problemas, caso o autor do script queira este tópico removido, ele que envie uma MP à qualquer moderador, por enquanto, o tópico permanecerá aberto.

 

Té.

Link para o comentário
Compartilhar em outros sites

@Luan

Recebi o report, vamos esperar o que ele vai falar, eu sei que ele nao é o josejunior é outro user la do outro forum, que eu saiba pra fechar o topic o propio criadordo script vai ter que vim falar que nao pode postar.



 

 

Se todo topico fosse fechado por ser de outro forum e sem autorização, metade dessa seção ia abaixo

Link para o comentário
Compartilhar em outros sites

Deixa ver se intendi,

É como se fosse um sistema de leilão em que o player poderia vender seus itens e comprar itens de outro player sem o sistema tradicional de 'TRADE' , tipo, o player nem precisaria ver a cara do outro pra vender o item.

 

Se for pelo que eu entendi, muito bom, valeu por compartilhar, já vou colocar em meu server.

REP+.

 

Abrass

Link para o comentário
Compartilhar em outros sites

  • 3 months later...
  • 1 month later...
×
×
  • Criar Novo...