Ir para conteúdo

Nostradamus

Visconde
  • Total de itens

    338
  • Registro em

  • Última visita

Tudo que Nostradamus postou

  1. Desenvolvi algumas funções para tratamento de arquivos fácilmente, não é como a do Colex, que por sinal, é mais completa, mas, já ajuda. function File:Exists(filename) local file = io.open(filename, "r") if (file == nil) then return false else file:close() return true end end function File:Create(filename, content) if (content == nil) then return false end local file = io.open(filename, "w") if (file == nil) then return false end file:write(content) file:flush() file:close() return true end function File:Save(filename, content) if (content == nil) then return false end local file = io.open(filename, "w+b") if (file == nil) then return false end file:write(content) file:flush() file:close() return true end function File:Load(filename) local file = io.open(filename, "r") if (file == nil) then return nil end local load = file:read("*all") file:close() return (load) end function File:LoadAsTable(filename) local file = io.open(filename, "r") if (file == nil) then return nil end local load = {} while true do local line = file:read("*l") if (line == nil) then break end table.insert(load, line) end file:close() return load, table.getn(load) end function File:GetExtension(filename) local fileExt = nil for w in string.gfind(filename, "(%.%a*)") do fileExt = string.lower(string.sub(w, 2, 10)) end return fileExt end function File:GetName(filename) local rFileName = nil for w in string.gfind(filename,"(%w*%.%w*)") do rFileName = string.lower(string.sub(w, 1, string.find(w, "%.")-1)) end return rFileName end Creio que o nome das funções se auto-explicam, mas se tiverem dúvidas, é só postarem.
  2. Muito bom tutorial, eu até leria, se não soubesse, como já sei tudo disso, só me resta comentar.
  3. Vi em um fórum uma função chamada onAdvance feita pelo 4220niller, mas eu não gostei nada do código, então resolvi fazer por eu mesmo. Não cheguei a testar o código, mas tenho quase certeza de que irá funcionar. creatureevent.cpp Depois de: m_logoutEvent = NULL; Adicione: m_advanceEvent = NULL; Depois de: delete m_logoutEvent; Adicione: delete m_advanceEvent; Depois de: m_logoutEvent->clearEvent(); Adicione: m_advanceEvent->clearEvent(); Depois de:: case CREATURE_EVENT_LOGOUT: delete m_logoutEvent; m_logoutEvent = creatureEvent; return true; Adicione: case CREATURE_EVENT_ADVANCE: delete m_advanceEvent; m_advanceEvent = creatureEvent; return true; Depois de: uint32_t CreatureEvents::playerLogout(Player* player) { if(m_logoutEvent) return m_logoutEvent->executeOnLogout(player); else return 0; } Adicione: uint32_t CreatureEvents::playerAdvance(Player* player) { if(m_advanceEvent) return m_advanceEvent->executeOnAdvance(player); else return 0; } Depois de: else if(str == "logout") m_type = CREATURE_EVENT_LOGOUT; Adicione: else if(str == "advance") m_type = CREATURE_EVENT_ADVANCE; Depois de: case CREATURE_EVENT_LOGOUT: return "onLogout"; Adicione: case CREATURE_EVENT_ADVANCE: return "onAdvance"; No final do arquivo, Adicione: uint32_t CreatureEvent::executeOnAdvance(Player* player) { //onAdvance(cid) if(m_scriptInterface->reserveScriptEnv()) { ScriptEnviroment* env = m_scriptInterface->getScriptEnv(); #ifdef __DEBUG_LUASCRIPTS__ char desc[30]; sprintf(desc, "%s", player->getName().c_str()); env->setEventDesc(desc); #endif env->setScriptId(m_scriptId, m_scriptInterface); env->setRealPos(player->getPosition()); uint32_t cid = env->addThing(player); lua_State* L = m_scriptInterface->getLuaState(); m_scriptInterface->pushFunction(m_scriptId); lua_pushnumber(L, cid); int32_t result = m_scriptInterface->callFunction(1); m_scriptInterface->releaseScriptEnv(); return (result == LUA_TRUE); } else { std::cout << "[Error] Call stack overflow. CreatureEvent::executeOnAdvance" << std::endl; return 0; } } creatureevent.h Depois de:: CREATURE_EVENT_LOGOUT, Adicione: CREATURE_EVENT_ADVANCE Depois de: uint32_t playerLogout(Player* player); Adicione: uint32_t playerAdvance(Player* player); Depois de:: CreatureEvent* m_logoutEvent; Adicione: CreatureEvent* m_advanceEvent; Depois de:: uint32_t executeOnLogout(Player* player); Adicione: uint32_t executeOnAdvance(Player* player); player.cpp Depois de: levelMsg << "You advanced from Level " << prevLevel << " to Level " << newLevel << "."; sendTextMessage(MSG_EVENT_ADVANCE, levelMsg.str()); Adicione: //scripting event - onAdvance g_creatureEvents->playerAdvance(this); Depois de: advMsg << "You advanced in " << g_game.getSkillName(skill) << "."; client->sendTextMessage(MSG_EVENT_ADVANCE, advMsg.str()); client->sendSkills(); Adicione: //scripting event - onAdvance g_creatureEvents->playerAdvance(this); Depois de: MaglvMsg << "You advanced to magic level " << magLevel << "."; sendTextMessage(MSG_EVENT_ADVANCE, MaglvMsg.str()); sendStats(); Adicione: //scripting event - onAdvance g_creatureEvents->playerAdvance(this);
  4. Só acho bobeira colocar idioma inglês, já que o conteúdo é em português.
  5. Conteúdo Removido Motivo: Leia
  6. Muito bom, aliás, o que seu é ruim Arkilus? ;P
  7. @FrozenMapper Leia o post até o final e verás...
  8. @colex Obviamente, mas creio que só o Forgotten tem essa função, já que foi o próprio Talaturen que a fez.
  9. Muito legal, a BlackOnix fez isso a algum tempo, só aconselho que vá aprender a usar arrays para deixar seu script mais "inteligente".
  10. @Conde Sapo Ao invés de usar esse tanto de OR, coloque os ids em arrays e use a função isInArray
  11. Detalhes: Esse script, só funcionará no Forgotten, pois usa a função: mayNotMove(cid,1) Colex, aconselho colocar mayNotLogout(cid, 1) também.
  12. Como muitos devem saber, eu programava PHP(e ainda o faço), e, ao começar a usar o LuaSQL, encontrei algumas funções meio "estranhas", então, resolvi "converter" tais funções do LuaSQL para o PHP, que em minha visão, é mais fácil, ou pelo menos, acho que me aconstumei. Aqui vão elas: function mysql_connect(mysqlDatabase, mysqlUser, mysqlPass, mysqlHost) Environment = assert(luasql.mysql()) Con = assert(Environment:connect(mysqlDatabase, mysqlUser, mysqlPass, mysqlHost, mysqlPort)) return true end function mysql_fetch_array(arr, query) query:fetch(arr) return true end function mysql_query(query) assert(Con:execute(queyr)) return true end function mysql_num_rows(query) query:numrows() return true end Aconselho usar o LuaSQL para LUA 5.1, mas tais funções não deixarão de funcionar caso você mude.
  13. De princípio esse XML Parser fora criado para a BlackOnix para ler certos atribuitos. Mas, como o revdbsys está chegando, achamos que não iríamos precisar mais. Créditos: Nostradamus & Jovial function fileToString(dir) local line local string = '' for (line in io.lines(dir)) do string = string..line..'\n' end return string end function ParseArgs(s) local arg = {} string.gsub(s, "(%w+)=([\"'])(.-)%2", function (w, _, a) arg[w] = a end) return arg end function XMLReader(s) local stack = {} local top = {} table.insert(stack, top) local ni,c,label,xarg, empty local i, j = 1, 1 while (true) do ni,j,c,label,xarg, empty = string.find(s, "<(%/?)(%w+)(.-)(%/?)>", j) if (not ni) then break end local text = string.sub(s, i, ni-1) if (not string.find(text, "^%s*$")) then table.insert(top, text) end if (empty == "/") then table.insert(top, {label=label, xarg=ParseArgs(xarg), empty=1}) elseif (c == "") then top = {label=label, xarg=ParseArgs(xarg)} table.insert(stack, top) else local toclose = table.remove(stack) top = stack[#stack] if (#stack < 1) then error("nothing to close with "..label) end if (toclose.label ~= label) then error("trying to close "..toclose.label.." with "..label) end table.insert(top, toclose) end i = j+1 end local text = string.sub(s, i) if (not string.find(text, "^%s*$")) then table.insert(stack[stack.n], text) end if (#stack > 1) then error("unclosed "..stack[stack.n].label) end return stack[1] end Detalhes: o código foi desenvolvido obedecendo a documentação de estruturação padrão da BlackOnix desenvolvido por Nostradamus. E sim, fora baseado num exemplo do LUA-Users, eu mesmo me encarreguei de atualizar no WIKI de lá, mais tarde irei atualizar novamente, devido ao fato de esse script aqui postado, ter a função fileToString.
  14. Esse é um de meus presentes para o aniversário do XTibia, uma magia com o formato da logomarca do mesmo. Antes de mais nada, vamos a uma amostra dessa magia: Vocês podem observar que o inovador dessa magia é que ela usa dois efeitos ao mesmo tempo. Vamos então ao script: Crie um arquivo chamado xtibia.lua e coloque: local combat1 = createCombatObject() setCombatParam(combat1, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE) setCombatParam(combat1, COMBAT_PARAM_EFFECT, CONST_ME_GREEN_RINGS) setCombatFormula(combat1, COMBAT_FORMULA_LEVELMAGIC, -2.0, -150, -1.6, -150) local combat2 = createCombatObject() setCombatParam(combat2, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE) setCombatParam(combat2, COMBAT_PARAM_EFFECT, CONST_ME_YELLOW_RINGS) setCombatFormula(combat2, COMBAT_FORMULA_LEVELMAGIC, -2.0, -150, -1.6, -150) arr1 = { {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0}, {0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0}, {0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0}, {0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0}, {0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0}, {0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0}, {0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, } arr2 = { {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1}, {0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0}, {0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0}, {0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0}, {0, 0, 0, 0, 0, 2, 1, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0}, {0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0}, {0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0}, {0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1}, {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, } local area1 = createCombatArea(arr1) local area2 = createCombatArea(arr2) setCombatArea(combat1, area1) setCombatArea(combat2, area2) local function onCastSpell1(parameters) doCombat(parameters.cid, parameters.combat1, parameters.var) end local function onCastSpell2(parameters) doCombat(parameters.cid, parameters.combat2, parameters.var) end function onCastSpell(cid, var) local parameters = { cid = cid, var = var, combat1 = combat1, combat2 = combat2 } addEvent(onCastSpell1, 0, parameters) addEvent(onCastSpell2, 0, parameters) end Agora em spells.xml coloque: <instant name="XTibia" words="hail xtibia" aggressive="1" lvl="100" maglv="60" manapercent="50" soul="0" exhaustion="1000" prem="1" enabled="1" needlearn="0" script="xtibia.lua"><vocation name="Master Sorcerer"/><vocation name="Elder Druid"/></instant> Edite a seu gosto.
  15. Ótimo! JV já tinha me falado sobre algo a respeito de tal projeto, e eu amei! Para ser sincero, não sou de comentar em novidades do fórum e tudo mais, mas esse projeto é muito especial e eu TINHA que comentar algo sobre tal. Absolutamente brilhante!
  16. @Dare Devil Não foi ripping, a idéia pode até ter sido, mas veja que o script é diferente.
  17. @Monster Kill Dá sim, mas eu não vi o porque de fazer assim..
  18. Antes de mais nada, gostaria de dizer que esse sistema só irá funcionar para servidores que possuírem a biblioteca LuaSQL. Até agora, só vi um servidor com ela: Forgotten Server. Quero dizer também, que o script não está completo, mas dá para se tirar uma boa base, o sistema de SQL funciona quase que 100%, mas ainda o mesmo, não equipa o char e nem insere skills por enquanto. Estou postando apenas para fins didáticos, para os preguiçosos, melhor nem lerem isso, já que, para ter esse sistema funcionando certo, terá que utilizar das funções então aqui postadas, para então servir de algo. Chega de conversas e vamos às funções: ---------------------------------------------------------------------------------------------------------------------------------------------- -- BEGIN - CONFIGURATION PART -- ---------------------------------------------------------------------------------------------------------------------------------------------- Char = { x = 12, y = 12, z = 7, level = 8, exp = 3200, soul = 100, townid = 1 } Voc = { mage = { health = 100, mana = 100, cap = 100, skill = { ml = 5, fist = 10, club = 10, sword = 10, axe = 10, distance = 10, shielding = 10, fishing = 10 } } paladin = { health = 100, mana = 100, cap = 100, skill = { ml = 5, fist = 10, club = 10, sword = 10, axe = 10, distance = 10, shielding = 10, fishing = 10 } } knight = { health = 100, mana = 100, cap = 100, skill = { ml = 5, fist = 10, club = 10, sword = 10, axe = 10, distance = 10, shielding = 10, fishing = 10 } } } Sex = { female = { id = 0, look = { type = 136, head = 25, body = 35, legs = 45, feet = 20, addons = 0 } } male = { id = 0, look = { type = 136, head = 25, body = 35, legs = 45, feet = 20, addons = 0 } } } ---------------------------------------------------------------------------------------------------------------------------------------------- -- END - CONFIGURATION PART -- ---------------------------------------------------------------------------------------------------------------------------------------------- function Global:checkPassword(password) if (string.find(password, '^[a-zA-Z0-9 -]+$') then if (string.len(password) <= 20 or string.len(password) <= 2) then return TRUE end else return FALSE end end function XML:checkAccount(account) if (string.find(account, '^[0-9]+$') then if (string.len(account) <= 7 or string.len(account) >= 6) then if (io.open(getDataDir() .. 'accounts/' .. account .. '.xml', 'r')) == nil) then return TRUE end end else return FALSE end end function XML:checkCharName(name) if (io.open(getDataDir() .. 'players/' .. name .. '.xml', 'r')) == nil) then return TRUE else return FALSE end end function XML:generateAccount(account) randomAcc = math.random(100000, 9999999) if (io.open(getDataDir() .. 'accounts/' .. randomAcc .. '.xml', 'r')) == nil) then return randomAcc else return FALSE end end function SQL:checkAccount(account) local cursor = assert(Con:execute("SELECT `account` FROM `accounts` WHERE `account` = " .. account .. ";")) if (cursor:numrows() > 0) then return TRUE else return FALSE end end -- TODO: make a query to check if the desired account exists (or is valid) function SQL:createPlayer(account, name, vocation, sex) if (string.find(name, '^[a-zA-Z0-9 -]+$') then if (string.len(name) <= 25 or string.len(name) <= 3) then if (SQL:checkCharName(name) == TRUE) then return false else if (sex == "male") then if (vocation == "druid" or vocation == "sorcerer") then local cursor = assert(Con:execute("INSERT INTO `players` VALUES ("", " .. name .. ", "0", " .. account .. ", " .. vocation .. ", " .. Voc.mage.health .. ", " .. Voc.mage.health .. ", " .. Char.exp .. ", " .. Sex.look.body .. ", " .. Sex.look.feet .. ", " .. Sex.look.head .. ", " .. Sex.look.legs .. ", " .. Sex.look.type .. ", " .. Sex.look.addons .. ", " .. Voc.mage.skill.ml .. ", " .. Voc.mage.mana .. ", " .. Voc.mage.mana .. ", "0", " .. Char.soul .. ", " .. Char.townid .. ", " .. Char.x .. ", " .. Char.y .. ", " .. Char.z .. ", "", " .. Voc.mage.cap .. ", " .. Sex.male.id .. ", "0", "0", "1", "0", "0", "", "", "", "0", "1");")) elseif (vocation == "paladin") then local cursor = assert(Con:execute("INSERT INTO `players` VALUES ("", " .. name .. ", "0", " .. account .. ", " .. vocation .. ", " .. Voc.paladin.health .. ", " .. Voc.paladin.health .. ", " .. Char.exp .. ", " .. Sex.look.body .. ", " .. Sex.look.feet .. ", " .. Sex.look.head .. ", " .. Sex.look.legs .. ", " .. Sex.look.type .. ", " .. Sex.look.addons .. ", " .. Voc.paladin.skill.ml .. ", " .. Voc.paladin.mana .. ", " .. Voc.paladin.mana .. ", "0", " .. Char.soul .. ", " .. Char.townid .. ", " .. Char.x .. ", " .. Char.y .. ", " .. Char.z .. ", "", " .. Voc.paladin.cap .. ", " .. Sex.male.id .. ", "0", "0", "1", "0", "0", "", "", "", "0", "1");")) else local cursor = assert(Con:execute("INSERT INTO `players` VALUES ("", " .. name .. ", "0", " .. account .. ", " .. vocation .. ", " .. Voc.knight.health .. ", " .. Voc.knight.health .. ", " .. Char.exp .. ", " .. Sex.look.body .. ", " .. Sex.look.feet .. ", " .. Sex.look.head .. ", " .. Sex.look.legs .. ", " .. Sex.look.type .. ", " .. Sex.look.addons .. ", " .. Voc.knight.skill.ml .. ", " .. Voc.knight.mana .. ", " .. Voc.knight.mana .. ", "0", " .. Char.soul .. ", " .. Char.townid .. ", " .. Char.x .. ", " .. Char.y .. ", " .. Char.z .. ", "", " .. Voc.knight.cap .. ", " .. Sex.male.id .. ", "0", "0", "1", "0", "0", "", "", "", "0", "1");")) end else if (vocation == "druid" or vocation == "sorcerer") then local cursor = assert(Con:execute("INSERT INTO `players` VALUES ("", " .. name .. ", "0", " .. account .. ", " .. vocation .. ", " .. Voc.mage.health .. ", " .. Voc.mage.health .. ", " .. Char.exp .. ", " .. Sex.look.body .. ", " .. Sex.look.feet .. ", " .. Sex.look.head .. ", " .. Sex.look.legs .. ", " .. Sex.look.type .. ", " .. Sex.look.addons .. ", " .. Voc.mage.skill.ml .. ", " .. Voc.mage.mana .. ", " .. Voc.mage.mana .. ", "0", " .. Char.soul .. ", " .. Char.townid .. ", " .. Char.x .. ", " .. Char.y .. ", " .. Char.z .. ", "", " .. Voc.mage.cap .. ", " .. Sex.female.id .. ", "0", "0", "1", "0", "0", "", "", "", "0", "1");")) elseif (vocation == "paladin") then local cursor = assert(Con:execute("INSERT INTO `players` VALUES ("", " .. name .. ", "0", " .. account .. ", " .. vocation .. ", " .. Voc.paladin.health .. ", " .. Voc.paladin.health .. ", " .. Char.exp .. ", " .. Sex.look.body .. ", " .. Sex.look.feet .. ", " .. Sex.look.head .. ", " .. Sex.look.legs .. ", " .. Sex.look.type .. ", " .. Sex.look.addons .. ", " .. Voc.paladin.skill.ml .. ", " .. Voc.paladin.mana .. ", " .. Voc.paladin.mana .. ", "0", " .. Char.soul .. ", " .. Char.townid .. ", " .. Char.x .. ", " .. Char.y .. ", " .. Char.z .. ", "", " .. Voc.paladin.cap .. ", " .. Sex.female.id .. ", "0", "0", "1", "0", "0", "", "", "", "0", "1");")) else local cursor = assert(Con:execute("INSERT INTO `players` VALUES ("", " .. name .. ", "0", " .. account .. ", " .. vocation .. ", " .. Voc.knight.health .. ", " .. Voc.knight.health .. ", " .. Char.exp .. ", " .. Sex.look.body .. ", " .. Sex.look.feet .. ", " .. Sex.look.head .. ", " .. Sex.look.legs .. ", " .. Sex.look.type .. ", " .. Sex.look.addons .. ", " .. Voc.knight.skill.ml .. ", " .. Voc.knight.mana .. ", " .. Voc.knight.mana .. ", "0", " .. Char.soul .. ", " .. Char.townid .. ", " .. Char.x .. ", " .. Char.y .. ", " .. Char.z .. ", "", " .. Voc.knight.cap .. ", " .. Sex.female.id .. ", "0", "0", "1", "0", "0", "", "", "", "0", "1");")) end end return TRUE end end end end function SQL:createAccount(account, password) if (string.find(account, '^[0-9]+$') then if (string.len(account) <= 7 or string.len(account) >= 6) then if (SQL:checkAccount(account) == TRUE) return FALSE else local query = assert(Con:execute("INSERT INTO `accounts` VALUES (" .. account .. ", " .. password .. ", "0", "0", "", "", "", "0", "");")) return TRUE end end end end function SQL:checkCharName(name) local cursor = assert(Con:execute("SELECT `name` FROM `players` WHERE `name` = " .. name .. ";")) if (cursor:numrows() > 0) then return TRUE else return FALSE end end function SQL:generateAccount(account) randomAcc = math.random(100000, 9999999) local cursor = assert(Con:execute("SELECT `account` FROM `accounts` WHERE `account` = " .. account .. ";")) if (cursor:numrows() < 0) then return randomAcc else return FALSE end end
  19. Opa velho, ficou bom. Valeu ai.
  20. Em novas versões ficaria assim: broadcastMessage(getCreatureName(cid) .. ' say: ' .. msg, MESSAGE_STATUS_CONSOLE_RED)
  21. Lembrando que isso seria feito em Javascript, PHP ou qualquer outra linguagem WEB e não HTML.
  22. Para versões mais atuais, usem broadcastMessage ou mesmo broadcastMessageEx, lembrando que isso depende da versão utilizada.
  23. Pode até funcionar, mas é bem rudimentar...
  24. Isso apenas irá enviar a login msg, para uma janela (pop up). Dá para se fazer em LUA até.
  25. @TheChaos Verdade, a SVN agora está removendo além disso TUDO de XML do OpenTibia, com a revdbsystem, depois dá uma conferida. A propósito, gostaria de ter uma conversa com você, adicione-me no MSN: ntsonline@30gigs.com
  • Quem Está Navegando   0 membros estão online

    • Nenhum usuário registrado visualizando esta página.
×
×
  • Criar Novo...