Por
Garou
ADVANCED FORGE SYSTEM
O SISTEMA DE CRIAÇÃO DE ITENS PARA SEU SERVIDOR
Creio que muitos já conhecem o sistema de forja criado por mim, acontece que o código já estava um pouco obsoleto, então resolvi reescrever ele do 0.
Simplesmente consiste em um sistema de criação de itens avançado que ressuscita um pouco do RPG perdido nos servidores de hoje em dia. O jogador poderá criar itens através de forja, agindo como um verdadeiro ferreiro medieval. Adiciona itens em cima de uma bigorna previamente colocada no mapa e com um martelo cria um item totalmente novo.
CARACTERÍSTICAS DA VERSÃO FINAL:
- Configuração intuitiva e fácil de compreender;
- Mini-tutorial auxiliando criação de novas receitas;
- Receitas podem conter até 250 itens diferentes com suas respectivas quantidades;
- Sistema inteligente que identifica uma receita em qualquer ordem;
- Código totalmente orientado a objetos;
- Possibilidade de configurar diferentes requerimentos, diferentes skills, magic level e level
Há dois modos de instalar o Advanced Forge System, o primeiro é seguir os passos deste tópico e o segundo e baixar pasta data/ anexada no tópico com os arquivos em seus respectivos diretórios, precisando apenas o registro das chaves nos arquivos XML.
Escolha o modo que mais convém a você.
Crie um arquivo em data/lib chamado forgesystem.lua e cole o conteúdo abaixo:
--[[
ADVANCED FORGE SYSTEM
FINAL
Criado por Oneshot
É proibido a venda ou a cópia sem os devidos créditos desse script.
]]--
RecipeHandler = {
itemtype = 0,
items = {},
level = 1,
maglevel = 0,
skills = {[0] = 0, [1] = 0, [2] = 0, [3] = 0, [4] = 0, [5] = 0, [6] = 0}
}
Forge = {
type = nil,
position = nil,
magicEffect = CONST_ME_MAGIC_GREEN,
messages = {
class = MESSAGE_STATUS_DEFAULT,
success = "You have successfully forged a %s.",
needskill = "You don't have enough %s to create a %s.",
needlevel = "You need level %s to create a %s.",
needmaglevel = "You need magic level %s to create a %s."
}
}
function RecipeHandler:new(itemtype, items, level, maglevel, skills)
local obj = {
itemtype = (itemtype or 0),
items = (items or {}),
level = (level or 1),
maglevel = (maglevel or 0),
skills = (skills or {[0] = 0, [1] = 0, [2] = 0, [3] = 0, [4] = 0, [5] = 0, [6] = 0})
}
table.insert(Recipes, obj)
return setmetatable(obj, {__index = self})
end
function RecipeHandler:setItem(itemtype)
self.itemtype = (itemtype or 0)
end
function RecipeHandler:setRecipe(...)
self.items = {...}
end
function RecipeHandler:setRecipeItem(itemid, amount)
table.insert(self.items, {itemid, amount})
end
function RecipeHandler:setSkill(skillid, value)
self.skills[skillid] = value
end
function RecipeHandler:setLevel(value)
self.level = value
end
function RecipeHandler:setMagLevel(value)
self.maglevel = value
end
function RecipeHandler:check(position)
local match = false
for n, item in ipairs(self.items) do
local thing = getTileItemById(position, item[1])
if thing.uid > 0 and math.max(1, thing.type) >= item[2] then
if n == #self.items then
match = true
end
else
break
end
end
return match
end
function RecipeHandler:get(position)
if self:check(position) == true then
return setmetatable({type = self, position = position}, {__index = Forge})
end
return false
end
function Forge:create(cid)
if self.type.itemid == 0 then
print("[FORGE SYSTEM - ERROR] ATTEMPT TO CREATE A RECIPE ITEMID 0")
return
end
local status = true
if(cid) then
if getPlayerLevel(cid) < self.type.level then
doPlayerSendTextMessage(cid, self.messages.class, self.messages.needlevel:format(self.type.level, getItemNameById(self.type.itemtype)))
return
end
if getPlayerMagLevel(cid) < self.type.maglevel then
doPlayerSendTextMessage(cid, self.messages.class, self.messages.needmaglevel:format(self.type.maglevel, getItemNameById(self.type.itemtype)))
return
end
for skillid, value in pairs(self.type.skills) do
if getPlayerSkillLevel(cid, skillid) < value then
status = false
doPlayerSendTextMessage(cid, self.messages.class, self.messages.needskill:format(SKILL_NAMES[skillid], getItemNameById(self.type.itemtype)))
break
end
end
end
if status == true then
for _, item in ipairs(self.type.items) do
local thing = getTileItemById(self.position, item[1])
doRemoveItem(thing.uid, item[2])
end
doSendMagicEffect(self.position, self.magicEffect)
doPlayerSendTextMessage(cid, self.messages.class, self.messages.success:format(getItemNameById(self.type.itemtype)))
doCreateItem(self.type.itemtype, self.position)
end
end
dofile(getDataDir() .."/lib/recipes.lua")
Crie um arquivo em data/lib chamado recipes.lua e adicione o conteúdo abaixo:
----------------------------------------
-----** TUTORIAL DE CONFIGURAÇÃO **-----
----------------------------------------
--[[
O 'ADVANCED FORGE SYSTEM' é muito fácil e intuitivo de configurar, você só precisa chamar
a função RecipeHandler:new(...), sendo que você já configurar os atributos da receita nela
ou usar outras funções para isso.
Por exemplo, quero criar uma Magic Sword que precise de 100 Gold Nuggets.
RecipeHandler:new(2400, {{2157, 100}})
Ou então
Magic_Sword = RecipeHandler:new()
Magic_Sword:setItem(2400)
Magic_Sword:setRecipe({2157, 100})
Funções do Sistema:
RecipeHandler:new(itemtype, items, level, maglevel, skills) --> Cria uma nova instância de forja.
RecipeHandler:setItem(itemtype) --> Atribui um certo itemid como resultado da receita.
RecipeHandler:setRecipe(recipe) --> Atribui uma receita.
RecipeHandler:setRecipeItem(itemid, amount) --> Adiciona um itemid e sua quantidade a receita.
RecipeHandler:setSkill(skillid, value) --> Atribui um valor necessário de uma certa skill para poder criar a receita.
RecipeHandler:setLevel(value) --> Atribui o level necessário para criar uma receita.
RecipeHandler:setMagLevel(value) --> Atribui o magic level necessário para criar uma receita.
]]--
--[[
Este é um exemplo de receita usando algumas funções.
É uma Magic Sword (ITEMID: 2400) que precisa de 100 Gold Nuggets (ITEMID: 2157),
além disso, o personagem que tentar forjar, precisa ter Level 100 e Sword Fighting 50.
]]--
Recipes = {}
magicsword = RecipeHandler:new()
magicsword:setItem(2400)
magicsword:setRecipeItem(2157, 100)
magicsword:setLevel(100)
magicsword:setSkill(2, 50)
Agora em data/actions/scripts, crie um arquivo chamado iron_hammer.lua e adicione o conteúdo abaixo:
function onUse(cid, item, fromPosition, itemEx, toPosition)
local recipe = nil
for _, v in ipairs(Recipes) do
recipe = v:get(toPosition)
if(recipe ~= false) then
break
end
end
if(recipe) then
recipe:create(cid)
else
doPlayerSendCancel(cid, "This is not a valid recipe.")
end
return true
end
E por fim em actions.xml, adicione a seguinte linha:
<action itemid="4846" event="script" value="iron_hammer.lua"/>
OPCIONAL - TALKACTION A talkaction abaixo mostra ao jogadoras receitas configuradas no servidor que ele pode fazer. Em data/talkactions/scripts, crie um arquivo chamado recipes.lua e adicione o conteúdo abaixo:
function onSay(cid, words, param, channel)
local ret = {}
local msg = " ADVANCED FORGE SYSTEM\n"
for _, recipe in ipairs(Recipes) do
local skills = true
for skillid, value in pairs(recipe.skills) do
if getPlayerSkillLevel(cid, skillid) < value then
skills = false
break
end
end
if skills == true then
if getPlayerLevel(cid) >= recipe.level and getPlayerMagLevel(cid) >= recipe.maglevel then
table.insert(ret, {recipe, true})
else
table.insert(ret, {recipe, false})
end
else
table.insert(ret, {recipe, false})
end
end
for _, recipe in ipairs(ret) do
msg = msg .."\nRecipe for ".. getItemNameById(recipe[1].itemtype) ..":\n\n"
if recipe[2] == true then
for _, item in ipairs(recipe[1].items) do
msg = msg .."* ".. getItemNameById(item[1]) .." [".. math.min(item[2], math.max(0, getPlayerItemCount(cid, item[1]))) .."/".. item[2] .."]\n"
end
else
msg = msg .."[LOCKED]\n"
end
end
doShowTextDialog(cid, 2555, msg)
return true
end
Em data/talkactions/talkactions.xml, adicione a linha:
<talkaction words="/recipes" event="script" value="recipes.lua"/>
Siga as instruções para configuração de novas receitas.
Em breve vídeo de funcionamento
Advanced Forge System.rar
Posts Recomendados
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.