Ir para conteúdo

Pesquisar na Comunidade

Mostrando resultados para as tags ''lib''.



Mais opções de pesquisa

  • Pesquisar por Tags

    Digite tags separadas por vírgulas
  • Pesquisar por Autor

Tipo de Conteúdo


Fóruns

  • A Cidade OTBR
    • OTServ Brasil
    • Atendimento
    • Taverna
  • Projetos Open Source
    • Canary
    • OTServBR-Global
    • Mehah OTClient
    • MyAAC
  • OpenTibia
    • Notícias e Discussões
    • Suporte - Dúvidas, Bugs, Erros
    • Downloads
    • Tutoriais
    • Show-Off
  • Outros
    • Design

Encontrado 5 registros

  1. [TFS 1.2] Modal Window Helper Lib

    Resumo A maneira atual para implementar Modal Window é um pouco complicada. Atualmente precisamos cria-la em algum lugar, registrar o evento, adicionar os botões em uma ordem específica, definir o ID da janela, dos botões e da escolha. Isso não é o ideal, então esta biblioteca foi criada pelo Non Sequitur para ajudar nisso. E eu estou trazendo para a OtServBrasil. Instalando Adicionar em data/lib/lib.lua dofile('data/lib/modalwindow.lua') Crie o arquivo modalwindow.lua com o seguinte conteúdo em data/lib 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 = callback end function MT:addButton(text, callback) local button = {text = tostring(text), callback = callback} table.insert(self.buttons, button) return button end function MT:addButtons(...) for _, text in ipairs({...}) do table.insert(self.buttons, {text = tostring(text)}) end end function MT:addChoice(text) local choice = {text = tostring(text)} table.insert(self.choices, choice) return choice end function MT:addChoices(...) for _, text in ipairs({...}) do table.insert(self.choices, {text = tostring(text)}) end end function MT:setDefaultEnterButton(text) self.defaultEnterButton = text end function MT:setDefaultEscapeButton(text) self.defaultEscapeButton = text end 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 = modalWindow end 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 Adicionar em data/creaturescripts/craturescripts.xml <event type="modalwindow" name="ModalWindowHelper" script="modalwindowhelper.lua" /> Crie o arquivo modalwindowhelper.lua com o seguinte conteúdo em data/creaturescripts/scripts/ 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 true end Pronto! Espero que gostem, posteriormente irei postar um tutorial de como usar/ aplicar e alguns scripts utilizando a Biblioteca.
  2. Object SQL

    Como funciona? Esta lib funciona como um façade para trabalhar com queries de um jeito mais "programador". A seguinte query, por exemplo: (...) tmp = db.getResult("SELECT `id`, `begin`, `end`, `payment` FROM `guild_wars` WHERE `guild_id` = " .. guild .. " AND `enemy_id` = " .. enemy .. " AND `status` = 0") if(tmp:getID() == -1) then (...) Se transforma no seguinte código: (...) tmp = query:select('id', 'begin', 'end', 'payment'):from('guild_wars'):where('guild_id', guild):where('enemy_id', enemy):where('status', 0):execute() if (tmp.id == -1) then (...) Quem já está acostumado com frameworks e outras facilidades de transformar queries em objetos vai sentir diferença na facilidade para escrever queries. Em outro exemplo, executando um update: db.executeQuery("UPDATE `guilds` SET `balance` = `balance` - " .. tmp:getDataInt("payment") .. " WHERE `id` = " .. guild) Com a lib, se torna: query:update('guilds'):set('balance', dec(tmp.payment)):where('id', guild):execute() Esta é outra facilidade, adicionei os modificadores inc e dec para incrementar ou decrementar, respectivamente, os campos em questão, e levam um parâmetro opcional que indica a quantidade a ser alterada. Nada o impede, também, de construir a query em vários passos: query:update('guilds') local payment = tmp.payment query:set('balance', dec(payment)) local id = getPlayerGuild(cid) --não sei se essa função existe, é apenas um exemplo query:where('id', id) E também, você pode saber se sua query foi executada ou não: if query:execute() then (...) Veja outros exemplos de código: query:insert_into('players'):values({name = 'Lordfire\'Rook', account_id = 0, level = 39, vocation = 0}):execute() query:update('players'):set({vocation = 4, access = inc(), level = inc(5)}):where('name', 'Lordfire\'Rook'):execute() query:select():from('players', 'accounts'):where('players.level', '>=', 39):where('players.access', 1):execute() query:delete_from('players'):where('level', '>=', 30):where('access', 0):execute() Repare que, para inserir, você usa o método values e envia uma tabela com as informações. A query automaticamente ordena os campos a serem preenchidos com seus respectivos dados. Você pode informar múltiplas tabelas no método from, mas deve indicar os campos com o nome da tabela para evitar redundância (por exemplo: level -> players.level) O método where também leva um parâmetro opcional, no meio, caso você queira usar alguma comparação que seja diferente de =. Estes códigos geram as seguintes queries, para efeito de consulta, que você pode pegar com o método query(), caso queira usar junto com outra query: INSERT INTO `players`(`account_id`,`vocation`,`name`,`level`)VALUES(0,0,"Lordfire'Rook",39); UPDATE players SET `level`=`level`+5,`vocation`=4,`access`=`access`+1 WHERE `name`="Lordfire'Rook"; SELECT * FROM `players`,`accounts` WHERE `players`.`level`>=39 AND `players`.`access`=1; DELETE FROM players WHERE `level`>=30 AND `access`=0; Lib: Pastebin: http://pastebin.com/2bjuFBDD Código: function mod(key, _type, value) if value == nil then value = 1 end return key .. _type .. value end function inc(value) return function(key) return mod(key, [[+]], value) end end function dec(value) return function(key) return mod(key, [[-]], value) end end Query = {} function Query:new() return setmetatable({type = [[]], columns = [[]], tables = [[]], conditions = {}}, {__index = self}) end -- C function Query:insert_into(_table) self.type, self.columns, self.tables, self.conditions = [[insert]], [[]], [[`]] .. _table .. [[`]], {} return self end function Query:values(values) local _columns, _values = {}, {} for k, v in pairs(values) do table.insert(_columns, [[`]] .. k .. [[`]]) if type(v) == "string" then v = [["]] .. v:gsub([[\"]], [[\"]]) .. [["]] end table.insert(_values, v) end self.columns, self.conditions = [[(]] .. table.concat(_columns, [[,]]) .. [[)]], _values return self end -- R function Query:select(...) self.type, self.columns, self.tables, self.conditions = [[select]], [ [*]], [[]], {} local columns = {...} if #columns > 0 then for i, c in ipairs(columns) do columns[i] = [[`]] .. c .. [[`]] end self.columns = table.concat(columns, [[,]]) end return self end -- U function Query:update(_table) self.type, self.columns, self.tables, self.conditions = [[update]], [[]], _table, {} return self end function Query:set(columns) local _columns = {} for k, v in pairs(columns) do k = [[`]] .. k:gsub([[\.]], [[`.`]]) .. [[`]] if type(v) == "string" then v = [["]] .. v:gsub([[\"]], [[\"]]) .. [["]] elseif type(v) == "function" then v = v(k) end table.insert(_columns, k .. [[=]] .. v) end self.columns = table.concat(_columns, [[,]]) return self end -- D function Query:delete_from(_table) self.type, self.columns, self.tables, self.conditions = [[delete]], [[]], _table, {} return self end -- RU function Query:where(...) local params = {...} local column, comparison, value = [[`]] .. params[1]:gsub([[%.]], [[`.`]]) .. [[`]], [[=]], nil if #params == 2 then value = params[2] elseif #params == 3 then if params[2]:find("[<>]=") then comparison, value = params[2], params[3] else comparison = [[ ]] .. params[2] .. [[ ]] end else return false end if type(value) == "string" then value = [["]] .. value:gsub([[\"]], [[\"]]) .. [["]] end table.insert(self.conditions, column .. comparison .. value) return self end -- RD function Query:from(...) local tables = {...} for i, t in ipairs(tables) do tables[i] = [[`]] .. t .. [[`]] end self.tables = table.concat(tables, [[,]]) return self end function Query:query() local query = [[]], {} if self.type == [[insert]] then query = [[iNSERT INTO ]] .. self.tables .. self.columns .. [[VALUES(]] .. table.concat(self.conditions, [[,]]) .. [[)]] elseif self.type == [[select]] then local where = [[]] if self.conditions ~= [[]] then where = [[ WHERE ]] .. table.concat(self.conditions, [[ AND ]]) end query = [[sELECT ]] .. self.columns .. [[ FROM ]] .. self.tables .. where elseif self.type == [[update]] then local where = [[]] if self.conditions ~= [[]] then where = table.concat({[[ WHERE]], table.concat(self.conditions, [[ AND ]])}, [[ ]]) end query = [[uPDATE ]] .. self.tables .. [[ SET ]] .. self.columns .. where elseif self.type == [[delete]] then local where = [[]] if self.conditions ~= [[]] then where = table.concat({[[ WHERE]], table.concat(self.conditions, [[ AND ]])}, [[ ]]) end query = [[DELETE FROM ]] .. self.tables .. where end return query .. [[;]] end function Query:execute() local query, result = self:query() if self.type == [[insert]] then local result = {} query = db.getResult(query) for k, v in pairs(query.val) do result[k] = v end return result end return db.executeQuery(query) end query = Query:new() Avisos: Isso não é uma biblioteca completa de MVC ou qualquer coisa parecida. É apenas um "wrapper" para construir queries de um jeito mais dinâmico, organizado e sem se preocupar com concatenação e afins. Não há sanitização de strings, testes para verificar se as funções existem ou coisa do tipo, portanto, tome cuidado. A biblioteca ainda está em fase de testes, não cheguei a usar ela num servidor com muitos players online. Se alguém puder fazer isso, ficarei agradecido. Posso transformar as queries para a sintaxe da biblioteca, se necessário.
  3. Reset LIB 100%

    •Nome: Reset LIB •Autor: Ukiro (eu) •Server Testado: 8.60 Baiak (Rook War v1.0) •Add: É uma função pra usar em scripts que simplifica o reset de uma pessoa..(pra mim ajudou). Vá em Data/Lib e no .lua das suas funções, coloque lá em baixo\/: -- Reset LIB By Ukiiro function getResets(cid) return getPlayerStorageValue(cid,[color=red]123[/color]) end function addReset(cid) setPlayerStorageValue(cid,[color=red]123[/color],getResets(cid)+1) playerid = getPlayerGUID(cid) doRemoveCreature(cid) db.executeQuery("UPDATE `players` SET `level`=[color=lime]8[/color],`experience`=[color=magenta]4200[/color] WHERE `players`.`id`= ".. playerid .."") end -- ~// Vermelho: Storage Livre para os Resets da pessoa. Verde: Level que a pessoa vai ficar quando resetar. Rosa: Experiencia que a pessoa vai ter quando resetar. Exemplo de Script: (talkaction) function onSay(cid, words, param) if (getPlayerLevel(cid) >= 1500) then addReset(cid) end end No caso Quando a pessoa falar a palavra do talkaction se ela for level 1500 ou mais, ela vai ser kikada, e quando entrar ja vai está com level 8,experiencia 4200 e + 1 reset no storage.
  4. isWall, isOpnedDoor & isClosedDoor

    |Nome: Functions "is..." |Créditos: Conde2, TFS Team |Versão: 1.0 |Servidor Testado: The Forgotten Server 0.3.5 Aew galera vim trazer para vocês mais 3 funções super úteis XD Bom para começar eu tive um trabalho do cão pra fazer a isWall então não quero escutar nenhuma reclamação !! IMPORTANTE: Uma observação importante é que a isWall não tem todas as paredes !! E tambem não inclui paredes com janelas, apenas paredes normais. Se alguem quiser adicionar mais sinta-se a vontade =D Bom vamos ao que interessa: Em data/lib/constant.lua ou data/global.lua adicione todos esse código !!! walls = {1025, 1026, 1027, 1028, 1029, 1030, 1031, 1032, 1033, 1034, 1035, 1036, 1037, 1038, 1039, 1040, 1041, 1042, 1043, 1044, 1045, 1046, 1047, 1048, 1049, 1050, 1051, 1052, 1053, 1054, 1055, 1056, 1057, 1058, 1059, 1060, 1061, 1062, 1063, 1064, 1065, 1066, 1067, 1068, 1069, 1070, 1164, 1165, 1166, 1167, 1168, 1169, 1170, 1171, 1172, 1173, 1174, 1175, 1176, 1177, 1178, 1179, 1180, 1181, 1182, 1183, 1184, 1185, 1186, 1187, 1188, 1189, 1190, 1191, 1192, 1193, 1194, 1195, 1196, 1197, 1198, 1199, 1200, 1201, 1202, 1203, 1204, 3361, 3362, 3363, 3364, 3365, 3366, 3367, 3368, 3369, 3370, 3371, 3372, 3373, 3374, 3375, 3376, 3377, 3378, 3379, 3380, 3381, 3423, 3424, 3425, 3426, 3427, 3428, 3429, 3430, 3431, 3432, 3433, 3454, 3455, 3456, 3457, 3458, 3459, 3460, 3461, 3462, 3463, 3464, 3465, 3466, 3467, 3468, 3469, 3470, 3471, 3472, 3473, 3474, 3475, 3508, 3509, 3510, 3511, 3513, 3514, 3515, 3516, 3517, 3518, 3519, 5146, 5147, 5148, 5149, 5150, 5151, 5152, 5153, 5154, 5155, 5261, 5262, 5263, 5264, 5265, 5266, 5267, 5268, 5269, 5270, 5271, 5272, 5273, 5274, 5275, 6133, 6134, 6135, 6136, 6137, 6138, 6139, 6140, 6141, 6142, 6143, 6144, 6145, 6146, 6147, 6148, 6149, 6150, 6151, 6152, 6238, 6239, 6240, 6241, 6242, 6243, 6244, 6245, 6246, 6247, 6248, 6395, 6396, 6397, 6398, 6399, 6400, 6401, 6402, 6403, 6404, 6405, 6406, 6407, 6768, 6769, 6770, 6771, 6772, 6839, 6840, 6841, 6842, 6843, 6844, 6845, 6846, 6847, 6848, 6849, 6850, 6851, 6852, 6853, 6854, 6855, 6856, 6857, 6858, 6859, 6860, 6861, 6862, 6863, 6864, 6865, 6866, 6867, 8475, 8476, 8477, 8478, 8479, 8480, 8481, 8482, 8483, 8484, 8485, 8486, 8487, 8488, 8489, 8490, 8491, 8492, 8493, 8494, 8495, 8496, 8497, 8498, 8499, 8500, 8501, 8502, 8503, 8504, 8505, 8506, 8507, 8508, 8509, 8510, 8511, 8512, 8513, 8514, 8515, 8516, 8517, 8518, 8519, 8520, 8521, 8522, 8523, 8524, 8525, 9118, 9119, 9120, 9121, 9122, 9123, 9124, 9125, 9126, 9127, 9128, 9129, 9130, 9131, 9132, 9133, 9134, 9135, 9136, 9137, 9138, 9139, 9147, 9148, 9149, 9150, 9151, 9152, 9153, 9154, 9155, 9156, 9157, 9158, 9370, 9371, 9372, 9373, 9374, 9375, 9376, 9377, 9378, 9379, 9380, 9381, 9382, 9383, 9384, 9385, 9386, 9714, 9715, 9716, 9717, 9718, 9719} closedDoors = {1209, 1210, 1212, 1213, 1219, 1221, 1231, 1232, 1234, 1235, 1237, 1239, 1249, 1250, 1252, 1253, 1539, 1541, 3535, 3536, 3538, 3544, 3545, 3547, 4913, 4914, 4916, 4917, 5082, 5084, 5098, 5099, 5101, 5107, 5108, 5110, 5116, 5117, 5119, 5125, 5126, 5128, 5134, 5135, 5137, 5138, 5140, 5141, 5143, 5144, 5278, 5279, 5281, 5282, 5284, 5286, 5515, 5517, 5732, 5733, 5735, 5736, 6192, 6193, 6195, 6196, 6198, 6200, 6249, 6250, 6252, 6253, 6255, 6257, 6795, 6797, 6799, 6801, 6891, 6892, 6894, 6900, 6901, 6903, 7033, 7034, 7036, 7042, 7043, 7045, 7054, 7056, 8541, 8542, 8544, 8545, 8547, 8549, 9165, 9166, 9168, 9169, 9171, 9173, 9267, 9268, 9270, 9271, 9273, 9275, 10276, 10274, 10268, 10269, 10271, 10272, 10471, 10480, 10477, 10478, 10468, 10469} ---------------------------------------------------------------------------------------------- Agora em data/lib/data.lua adicione todos esses códigos na ultima linha !!!: function isWall(uid) return isInArray(walls, uid) end function isClosedDoor(uid) return isInArray(closedDoors, uid) end function isOpenedDoor(uid) if isInArray(horizontalOpenDoors, uid) == TRUE or isInArray(verticalOpenDoors, uid) == TRUE then return TRUE end return FALSE end
  5. [8.1] Mock Script lib 1.0

    Bom esta e minha 1ª lib de funçoes. agumas sao um pouco inuteis outras +/- eu so fiz 5 pq tava meio sem criatividade Bom eu fiz tipo a lib do colex toda criptografada xD Pra baixa o link direto e aqui tive que zipa pq o geocities do yahoo so aceitou em .zip --' Bom pra fazer ela rodad é o seguinte: 1º ponha a lib na pasta do seu ot (não e na data) 2º Abra a pasta DATA e abra o global.lua e ponha isso nele: 3º execute o seu server e curta Aqui a lista de funçoes: doItemBroken(cid, itemid, chancemin, chancemax) -- Bom para usar em weapons. doSummonCreatureWithCheck(name, pos) -- Verifica se a posição esta vazia se estiver sumona um bixo isLevel(cid,level) -- Verifica se o player é level X ou maior printServerStatus() -- Mosta noo binario algunas informaçoes uteis como uptime players online se esta pvp o servere quantos mosntros no server getPlayerMoney(cid) -- Essa e boa pra bank pois ela da return na quantidade de dinheiro qu o player tem.
×