Eba Nostradamus de volta, zuera xD
Nao sei nem o que dizer do tópico, sua net nao tava colaborando muito mesmo porque deu tempo de fazer essa coisa enorme, parabéns pra você e fiz um sistema de tapete voador controlável, se você quiser olhar me avisa por PM se não acho que posto pra galera aqui do XTibia.






info
Grupo: Visconde
Registrado: 10/06/06
Posts: 338
Reputação: +6
Char no Tibia: Setyte Berseker
Fala galera, estou aqui mais uma vez para liberar um script que fiz em meu tempo livre, apesar de eu ter saído de OpenTibia, eu não consigo parar com Lua, e como a internet não estava coperando hoje, dediquei um tempinho para fazer um começo de um NPC System, aos quais eu jugo ser mais organizado que qualquer outro.
Features
Por enquanto, eu não ainda fiz o sistema e sim apenas a biblioteca de funções básicas, por isso o que temos ainda:
Não sei se irei seguir a frente com isso, mas, creio que isso irá servir para uso didático para muito "scripter" que está começando.
Eis então o script:
--[[ Nostradamus NPC Library 0.1 Features ratePrice multiplier Buy/Sell/Teleport modules Dynamic error threatment --]] NPC = { ratePrice = 1, BUY_LIST = { ["item_name"] = {id = , price = , count = } }, SELL_LIST = { ["item_name"] = {id = , price = , count = } }, TELEPORT_PLACES = { ["name"] = {pos = {x = , y = , z = }, price = } } ERRORS = { maxCount = "Item count should be less then 100.", noCount = "Item count should be especified.", noMoney = "The player does not have enought money.", noItem = "Desired item not found in the buying list.", noPlayerItem = "The player does not have the item to sell it.", noPlace = "Desired place does not exists." } } function NPC:new() o = o or {} return setmetatable(o, self) self.__index = self return o end function NPC.doPlayerAddMoney(cid, amount) local crystals = math.floor(amount / 10000) amount = amount - crystals * 10000 local platinum = math.floor(amount / 100) amount = amount - platinum * 100 local gold, ret = amount, 0 if (crystals > 0) then ret = doPlayerAddItem(cid, ITEM_CRYSTAL_COIN, crystals) if (ret ~= LUA_NO_ERROR) then return LUA_ERROR end end if (platinum > 0) then ret = doPlayerAddItem(cid, ITEM_PLATINUM_COIN, platinum) if (ret ~= LUA_NO_ERROR) then return LUA_ERROR end end if (gold > 0) then ret = doPlayerAddItem(cid, ITEM_GOLD_COIN, gold) if (ret ~= LUA_NO_ERROR) then return LUA_ERROR end end return LUA_NO_ERROR end function NPC:Buy(cid, itemName, count) local item = self.BUY_LIST[itemName] local totalCount, totalPrice = item.count + count, (item.price * count) * self.ratePrice if (item ~= nil) then if (doPlayerRemoveMoney(cid, totalPrice) == TRUE) then if (item.count ~= nil) then if (totalCount <= 100) then -- TODO: Support to charges and counts separately doPlayerAddItem(cid, item.id, totalCount) doPlayerRemoveMoney(cid, totalPrice) return TRUE else -- TODO: Make possible to add items no matter is the count return self.ERRORS.maxCount end else return self.ERRORS.noCount end else return self.ERRORS.noMoney end else return self.ERRORS.noItem end end function NPC:Sell(cid, itemName, count) local item = self.SELL_LIST[itemName] local totalCount, totalPrice = item.count + count, (item.price * count) * self.ratePrice if (item ~= nil) then if (getPlayerItemCount(cid) >= count) then if (item.count ~= nil) then if (totalCount <= 100) then doPlayerRemoveItem(cid, item.id, totalCount) self.doPlayerAddMoney(cid, totalPrice) return TRUE else -- TODO: Make possible to add items no matter is the count return self.ERRORS.maxCount end else return self.ERRORS.noCount end else return self.ERRORS.noPlayerItem end else return self.ERRORS.noItem end end function NPC:Teleport(cid, placeName) local place = self.TELEPORT_PLACES[placeName] if (place ~= nil) then if (doPlayerRemoveMoney(cid, place.price) == TRUE) then -- Is this bellow necessary? I don't remember... doPlayerRemoveMoney(cid, place.price) doTeleportThing(cid, place.pos) else return self.ERRORS.noMoney end else return self.ERRORS.noPlace end endApenas quero destacar que como não foi testado, o script pode ter alguns erros bobos, e eu recomendo que não seja usado para servidores e sim para fins didáticos.
Até mais.