Ir para conteúdo
  • 0

Ajudinha Upgrade System


brendoonh

Pergunta

Boa noite galerinha do xtibia...

 

Estou precisando de uma ajuda aqui com um script que estou usando, o famoso upgrade system...

Como todos sabem esse system é para aprimorar uma arma deixando ela +1 +2 +3...

Nesse sistema eu utilizo 2 pedras:

Flawless Ice Crystal (Free)
Pure Energy (Vip)

Quero que a pedra free, volte um refine caso falhe.

Por exemplo, a arma tá +6, se ele tenta refinar e falha, o item volte +5. Isso so iria acontecer com a pedra free.

Alguém sabe? No caso so iria mexer na pedra free, pois a vip ja está como eu quero, que mesmo se falhar o item continua no mesmo nivel.

 

 

Script que utilizo.

 

 

 

--[[
PERFECT UPGRADE SYSTEM
2.0
Criado por Oneshot
É proibido a venda ou a cópia sem os devidos créditos desse script.
]]--
UpgradeHandler = {
levels = {
[1] = {100, false, true},
[2] = {100, false, true},
[3] = {60, false, true},
[4] = {50, false, true},
[5] = {40, false, true},
[6] = {25, false, true},
[7] = {20, false, true},
[8] = {10, false, true},
[9] = {5, false, true},
[10] = {2, false, true}
},
broadcast = 9,
attributes = {
["attack"] = 2,
["defense"] = 1,
["armor"] = 1,
},
message = {
console = "Trying to refine %s to level +%s with %s%% success rate.",
success = "You have upgraded %s to level +%s",
fail = "You have failed in upgrade of %s to level +%s",
downgrade = "The upgrade level of %s has downgraded to +%s",
erase = "The upgrade level of %s has been erased.",
maxlevel = "The targeted %s is already on max upgrade level.",
notupgradeable = "This item is not upgradeable.",
broadcast = "The player %s was successful in upgrading %s to level +%s.\nCongratulations!!",
invalidtool = "This is not a valid upgrade tool.",
toolrange = "This upgrade tool can only be used in items with level between +%s and +%s"
},
tools = {
[8300] = {range = {0, 10}, info = {chance = 0, removeable = true}},
[8306] = {range = {0, 10}, info = {chance = 30, removeable = true}},
},
isEquipment = function(self)
local weaponType = self:getItemWeaponType()
return ((weaponType > 0 and weaponType < 7) or self.item.armor ~= 0)
end,
setItemName = function(self, name)
return doItemSetAttribute(self.item.uid, "name", name)
end,
chance = function(self)
local chances = {}
chances.upgrade = (self.levels[self.item.level + 1][1] or 100)
chances.downgrade = (self.item.level * 5)
chances.erase = (self.item.level * 11)
return chances
end
}
function UpgradeHandler:new(item)
local obj, ret = {}
obj.item = {}
obj.item.level = 0
obj.item.uid = item.uid
for key, value in pairs(getItemInfo(item.itemid)) do
obj.item[key] = value
end
ret = setmetatable(obj, {__index = function(self, index)
if _G[index] then
return (setmetatable({callback = _G[index]}, {__call = function(self, ...)
return self.callback(item.uid, ...)
end}))
else
return UpgradeHandler[index]
end
end})
if ret:isEquipment() then
ret:update()
return ret
end
return false
end
function UpgradeHandler:update()
self.item.level = (tonumber(self:getItemName():match("%+(%d+)")) or 0)
end
function UpgradeHandler:refine(uid, item)
if not self.item then
doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, self.message.notupgradeable)
return "miss"
end
local tool = self.tools[item.itemid]
if(tool == nil) then
doPlayerSendTextMessage(uid, MESSAGE_EVENT_DEFAULT, self.message.invalidtool)
return "miss"
end
if(self.item.level > #self.levels) then
doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_RED, self.message.maxlevel:format(self.item.name))
return "miss"
end
if(self.item.level < tool.range[1] or self.item.level >= tool.range[2]) then
doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_RED, self.message.toolrange:format(unpack(tool.range)))
return "miss"
end
local chance = (self:chance().upgrade + tool.info.chance)
doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, self.message.console:format(self.item.name, (self.item.level + 1), math.min(100, chance)))
if(tool.info.removeable == true) then
doRemoveItem(item.uid, 1)
end
if chance * 100 > math.random(1, 10000) then
doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_ORANGE, self.message.success:format(self.item.name, (self.item.level + 1)))
if (self.item.level + 1) >= self.broadcast then
end
self:setItemName((self.item.level > 0 and self:getItemName():gsub("%+(%d+)", "+".. (self.item.level + 1)) or (self:getItemName() .." +1")))
for key, value in pairs(self.attributes) do
if getItemAttribute(self.item.uid, key) ~= nil or self.item[key] ~= 0 then
doItemSetAttribute(self.item.uid, key, (self.item.level > 0 and getItemAttribute(self.item.uid, key) or self.item[key]) + value)
end
end
return "success"
else
if(self.levels[self.item.level][11] == true and (self:chance().erase * 100) > math.random(1, 10000)) then
doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_RED, self.message.erase:format(self.item.name))
self:setItemName(self.item.name)
for key, value in pairs(self.attributes) do
if self.item[key] > 0 then
doItemSetAttribute(self.item.uid, key, self.item[key])
end
end
elseif(self.levels[self.item.level][2] == true and (self:chance().downgrade * 100) > math.random(1, 10000)) then
doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_RED, self.message.downgrade:format(self.item.name, (self.item.level - 1)))
self:setItemName((self.item.level == 1 and self.item.name or self:getItemName():gsub("%+(%d+)", "+".. (self.item.level - 1))))
for key, value in pairs(self.attributes) do
if getItemAttribute(self.item.uid, key) ~= nil or self.item[key] ~= 0 then
doItemSetAttribute(self.item.uid, key, (self.item[key] + value * (self.item.level - 1)))
end
end
else
doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_RED, self.message.fail:format(self.item.name, (self.item.level + 1)))
end
return "fail"
end
end

 

Action da pedra FREE

 

 

function onUse(cid, item, fromPosition, itemEx, toPosition)

if isCreature(itemEx.uid) then
return doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
end
local obj = UpgradeHandler:new(itemEx)
if(obj == false) then
return doPlayerSendCancel(cid, UpgradeHandler.message.notupgradeable)
end
local status = obj:refine(cid, item)
if status == "success" then
doSendAnimatedText(toPosition, "Upgraded", COLOR_BLUE)
doSendMagicEffect(toPosition, 39)
elseif status == "fail" then
doSendAnimatedText(toPosition, "Failed", COLOR_BLUE)
doSendMagicEffect(toPosition, CONST_ME_POFF)
else
doSendMagicEffect(toPosition, CONST_ME_POFF)
end
return true
end

 


up


up

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

6 respostass a esta questão

Posts Recomendados

  • 0

Exatamente como eu queria. So que tem um porem... A pedra vip(8306) tb está voltando 1 nivel caso falhe. Queria que acontecesse somente com a pedra Free(8300)

Tente assim:

 

--[[

PERFECT UPGRADE SYSTEM
2.0

Criado por Oneshot

É proibido a venda ou a cópia sem os devidos créditos desse script.

]]--

UpgradeHandler = {
	levels = {
		[1] = {100, false, true},
		[2] = {100, false, true},
		[3] = {60, false, true},
		[4] = {50, false, true},
		[5] = {40, false, true},
		[6] = {25, false, true},
		[7] = {20, false, true},
		[8] = {10, false, true},
		[9] = {5, false, true},
		[10] = {2, false, true}
	},
	broadcast = 9,
	attributes = {
		["attack"] = 2,
		["defense"] = 1,
		["armor"] = 1,
	},
	message = {
		console = "Trying to refine %s to level +%s with %s%% success rate.",
		success = "You have upgraded %s to level +%s",
		fail = "You have failed in upgrade of %s to level +%s",
		downgrade = "The upgrade level of %s has downgraded to +%s",
		erase = "The upgrade level of %s has been erased.",
		maxlevel = "The targeted %s is already on max upgrade level.",
		notupgradeable = "This item is not upgradeable.",
		broadcast = "The player %s was successful in upgrading %s to level +%s.\nCongratulations!!",
		invalidtool = "This is not a valid upgrade tool.",
		toolrange = "This upgrade tool can only be used in items with level between +%s and +%s"
	},
	tools = {
		[8300] = {range = {0, 10}, info = {chance = 0, removeable = true}},
		[8306] = {range = {0, 10}, info = {chance = 30, removeable = true}},
	},
	
	isEquipment = function(self)
		local weaponType = self:getItemWeaponType()
		return ((weaponType > 0 and weaponType < 7) or self.item.armor ~= 0)
	end,
	
	setItemName = function(self, name)
		return doItemSetAttribute(self.item.uid, "name", name)
	end,
	
	chance = function(self)
		local chances = {}
		chances.upgrade = (self.levels[self.item.level + 1][1] or 100)
		chances.downgrade = (self.item.level * 5)
		chances.erase = (self.item.level * 11)
		
		return chances
	end
}

function UpgradeHandler:new(item)
	local obj, ret = {}
	obj.item = {}
	
	obj.item.level = 0
	obj.item.uid = item.uid
	for key, value in pairs(getItemInfo(item.itemid)) do
		obj.item[key] = value
	end
	
	ret = setmetatable(obj, {__index = function(self, index)
			if _G[index] then
					return (setmetatable({callback = _G[index]}, {__call = function(self, ...)
						return self.callback(item.uid, ...)
				end}))
			else
				return UpgradeHandler[index]
			end
	end})
	
	if ret:isEquipment() then
		ret:update()
		return ret
	end
	return false
end

function UpgradeHandler:update()
	self.item.level = (tonumber(self:getItemName():match("%+(%d+)")) or 0)
end

function UpgradeHandler:refine(uid, item)
	if not self.item then
		doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, self.message.notupgradeable)
		return "miss"
	end
	
	local tool = self.tools[item.itemid]
	
	if(tool == nil) then
		doPlayerSendTextMessage(uid, MESSAGE_EVENT_DEFAULT, self.message.invalidtool)
		return "miss"
	end
	
	if(self.item.level > #self.levels) then
		doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_RED, self.message.maxlevel:format(self.item.name))
		return "miss"
	end
	
	if(self.item.level < tool.range[1] or self.item.level >= tool.range[2]) then
		doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_RED, self.message.toolrange:format(unpack(tool.range)))
		return "miss"
	end
	
	local chance = (self:chance().upgrade + tool.info.chance)
	doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, self.message.console:format(self.item.name, (self.item.level + 1), math.min(100, chance)))
	
	if(tool.info.removeable == true) then
		doRemoveItem(item.uid, 1)
	end
	
	if chance * 100 > math.random(1, 10000) then
		doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_ORANGE, self.message.success:format(self.item.name, (self.item.level + 1)))
		if (self.item.level + 1) >= self.broadcast then
		end
		
		self:setItemName((self.item.level > 0 and self:getItemName():gsub("%+(%d+)", "+".. (self.item.level + 1)) or (self:getItemName() .." +1")))
		for key, value in pairs(self.attributes) do
			if getItemAttribute(self.item.uid, key) ~= nil or self.item[key] ~= 0 then
				doItemSetAttribute(self.item.uid, key, (self.item.level > 0 and getItemAttribute(self.item.uid, key) or self.item[key]) + value)
			end
		end
		return "success"
	elseif item.itemid == 8300 then
		doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_RED, self.message.downgrade:format(self.item.name, (self.item.level - 1)))
		self:setItemName((self.item.level == 1 and self.item.name or self:getItemName():gsub("%+(%d+)", "+".. (self.item.level - 1))))
		for key, value in pairs(self.attributes) do
			if getItemAttribute(self.item.uid, key) ~= nil or self.item[key] ~= 0 then
				doItemSetAttribute(self.item.uid, key, (self.item[key] + value * (self.item.level - 1)))
			end
		end
		return "fail"
	end
end

 

Link para o comentário
Compartilhar em outros sites

  • 0

Tenta assim:

 

--[[

PERFECT UPGRADE SYSTEM
2.0

Criado por Oneshot

É proibido a venda ou a cópia sem os devidos créditos desse script.

]]--

UpgradeHandler = {
	levels = {
		[1] = {100, false, true},
		[2] = {100, false, true},
		[3] = {60, false, true},
		[4] = {50, false, true},
		[5] = {40, false, true},
		[6] = {25, false, true},
		[7] = {20, false, true},
		[8] = {10, false, true},
		[9] = {5, false, true},
		[10] = {2, false, true}
	},
	broadcast = 9,
	attributes = {
		["attack"] = 2,
		["defense"] = 1,
		["armor"] = 1,
	},
	message = {
		console = "Trying to refine %s to level +%s with %s%% success rate.",
		success = "You have upgraded %s to level +%s",
		fail = "You have failed in upgrade of %s to level +%s",
		downgrade = "The upgrade level of %s has downgraded to +%s",
		erase = "The upgrade level of %s has been erased.",
		maxlevel = "The targeted %s is already on max upgrade level.",
		notupgradeable = "This item is not upgradeable.",
		broadcast = "The player %s was successful in upgrading %s to level +%s.\nCongratulations!!",
		invalidtool = "This is not a valid upgrade tool.",
		toolrange = "This upgrade tool can only be used in items with level between +%s and +%s"
	},
	tools = {
		[8300] = {range = {0, 10}, info = {chance = 0, removeable = true}},
		[8306] = {range = {0, 10}, info = {chance = 30, removeable = true}},
	},
	
	isEquipment = function(self)
		local weaponType = self:getItemWeaponType()
		return ((weaponType > 0 and weaponType < 7) or self.item.armor ~= 0)
	end,
	
	setItemName = function(self, name)
		return doItemSetAttribute(self.item.uid, "name", name)
	end,
	
	chance = function(self)
		local chances = {}
		chances.upgrade = (self.levels[self.item.level + 1][1] or 100)
		chances.downgrade = (self.item.level * 5)
		chances.erase = (self.item.level * 11)
		
		return chances
	end
}

function UpgradeHandler:new(item)
	local obj, ret = {}
	obj.item = {}
	
	obj.item.level = 0
	obj.item.uid = item.uid
	for key, value in pairs(getItemInfo(item.itemid)) do
		obj.item[key] = value
	end
	
	ret = setmetatable(obj, {__index = function(self, index)
			if _G[index] then
					return (setmetatable({callback = _G[index]}, {__call = function(self, ...)
						return self.callback(item.uid, ...)
				end}))
			else
				return UpgradeHandler[index]
			end
	end})
	
	if ret:isEquipment() then
		ret:update()
		return ret
	end
	return false
end

function UpgradeHandler:update()
	self.item.level = (tonumber(self:getItemName():match("%+(%d+)")) or 0)
end

function UpgradeHandler:refine(uid, item)
	if not self.item then
		doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, self.message.notupgradeable)
		return "miss"
	end
	
	local tool = self.tools[item.itemid]
	
	if(tool == nil) then
		doPlayerSendTextMessage(uid, MESSAGE_EVENT_DEFAULT, self.message.invalidtool)
		return "miss"
	end
	
	if(self.item.level > #self.levels) then
		doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_RED, self.message.maxlevel:format(self.item.name))
		return "miss"
	end
	
	if(self.item.level < tool.range[1] or self.item.level >= tool.range[2]) then
		doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_RED, self.message.toolrange:format(unpack(tool.range)))
		return "miss"
	end
	
	local chance = (self:chance().upgrade + tool.info.chance)
	doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, self.message.console:format(self.item.name, (self.item.level + 1), math.min(100, chance)))
	
	if(tool.info.removeable == true) then
		doRemoveItem(item.uid, 1)
	end
	
	if chance * 100 > math.random(1, 10000) then
		doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_ORANGE, self.message.success:format(self.item.name, (self.item.level + 1)))
		if (self.item.level + 1) >= self.broadcast then
		end
		
		self:setItemName((self.item.level > 0 and self:getItemName():gsub("%+(%d+)", "+".. (self.item.level + 1)) or (self:getItemName() .." +1")))
		for key, value in pairs(self.attributes) do
			if getItemAttribute(self.item.uid, key) ~= nil or self.item[key] ~= 0 then
				doItemSetAttribute(self.item.uid, key, (self.item.level > 0 and getItemAttribute(self.item.uid, key) or self.item[key]) + value)
			end
		end
		return "success"
	else
		doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_RED, self.message.downgrade:format(self.item.name, (self.item.level - 1)))
		self:setItemName((self.item.level == 1 and self.item.name or self:getItemName():gsub("%+(%d+)", "+".. (self.item.level - 1))))
		for key, value in pairs(self.attributes) do
			if getItemAttribute(self.item.uid, key) ~= nil or self.item[key] ~= 0 then
				doItemSetAttribute(self.item.uid, key, (self.item[key] + value * (self.item.level - 1)))
			end
		end
		return "fail"
	end
end

 

Link para o comentário
Compartilhar em outros sites

  • 0

Tenta assim:

 

 

--[[

PERFECT UPGRADE SYSTEM
2.0

Criado por Oneshot

É proibido a venda ou a cópia sem os devidos créditos desse script.

]]--

UpgradeHandler = {
	levels = {
		[1] = {100, false, true},
		[2] = {100, false, true},
		[3] = {60, false, true},
		[4] = {50, false, true},
		[5] = {40, false, true},
		[6] = {25, false, true},
		[7] = {20, false, true},
		[8] = {10, false, true},
		[9] = {5, false, true},
		[10] = {2, false, true}
	},
	broadcast = 9,
	attributes = {
		["attack"] = 2,
		["defense"] = 1,
		["armor"] = 1,
	},
	message = {
		console = "Trying to refine %s to level +%s with %s%% success rate.",
		success = "You have upgraded %s to level +%s",
		fail = "You have failed in upgrade of %s to level +%s",
		downgrade = "The upgrade level of %s has downgraded to +%s",
		erase = "The upgrade level of %s has been erased.",
		maxlevel = "The targeted %s is already on max upgrade level.",
		notupgradeable = "This item is not upgradeable.",
		broadcast = "The player %s was successful in upgrading %s to level +%s.\nCongratulations!!",
		invalidtool = "This is not a valid upgrade tool.",
		toolrange = "This upgrade tool can only be used in items with level between +%s and +%s"
	},
	tools = {
		[8300] = {range = {0, 10}, info = {chance = 0, removeable = true}},
		[8306] = {range = {0, 10}, info = {chance = 30, removeable = true}},
	},
	
	isEquipment = function(self)
		local weaponType = self:getItemWeaponType()
		return ((weaponType > 0 and weaponType < 7) or self.item.armor ~= 0)
	end,
	
	setItemName = function(self, name)
		return doItemSetAttribute(self.item.uid, "name", name)
	end,
	
	chance = function(self)
		local chances = {}
		chances.upgrade = (self.levels[self.item.level + 1][1] or 100)
		chances.downgrade = (self.item.level * 5)
		chances.erase = (self.item.level * 11)
		
		return chances
	end
}

function UpgradeHandler:new(item)
	local obj, ret = {}
	obj.item = {}
	
	obj.item.level = 0
	obj.item.uid = item.uid
	for key, value in pairs(getItemInfo(item.itemid)) do
		obj.item[key] = value
	end
	
	ret = setmetatable(obj, {__index = function(self, index)
			if _G[index] then
					return (setmetatable({callback = _G[index]}, {__call = function(self, ...)
						return self.callback(item.uid, ...)
				end}))
			else
				return UpgradeHandler[index]
			end
	end})
	
	if ret:isEquipment() then
		ret:update()
		return ret
	end
	return false
end

function UpgradeHandler:update()
	self.item.level = (tonumber(self:getItemName():match("%+(%d+)")) or 0)
end

function UpgradeHandler:refine(uid, item)
	if not self.item then
		doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, self.message.notupgradeable)
		return "miss"
	end
	
	local tool = self.tools[item.itemid]
	
	if(tool == nil) then
		doPlayerSendTextMessage(uid, MESSAGE_EVENT_DEFAULT, self.message.invalidtool)
		return "miss"
	end
	
	if(self.item.level > #self.levels) then
		doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_RED, self.message.maxlevel:format(self.item.name))
		return "miss"
	end
	
	if(self.item.level < tool.range[1] or self.item.level >= tool.range[2]) then
		doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_RED, self.message.toolrange:format(unpack(tool.range)))
		return "miss"
	end
	
	local chance = (self:chance().upgrade + tool.info.chance)
	doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, self.message.console:format(self.item.name, (self.item.level + 1), math.min(100, chance)))
	
	if(tool.info.removeable == true) then
		doRemoveItem(item.uid, 1)
	end
	
	if chance * 100 > math.random(1, 10000) then
		doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_ORANGE, self.message.success:format(self.item.name, (self.item.level + 1)))
		if (self.item.level + 1) >= self.broadcast then
		end
		
		self:setItemName((self.item.level > 0 and self:getItemName():gsub("%+(%d+)", "+".. (self.item.level + 1)) or (self:getItemName() .." +1")))
		for key, value in pairs(self.attributes) do
			if getItemAttribute(self.item.uid, key) ~= nil or self.item[key] ~= 0 then
				doItemSetAttribute(self.item.uid, key, (self.item.level > 0 and getItemAttribute(self.item.uid, key) or self.item[key]) + value)
			end
		end
		return "success"
	else
		doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_RED, self.message.downgrade:format(self.item.name, (self.item.level - 1)))
		self:setItemName((self.item.level == 1 and self.item.name or self:getItemName():gsub("%+(%d+)", "+".. (self.item.level - 1))))
		for key, value in pairs(self.attributes) do
			if getItemAttribute(self.item.uid, key) ~= nil or self.item[key] ~= 0 then
				doItemSetAttribute(self.item.uid, key, (self.item[key] + value * (self.item.level - 1)))
			end
		end
		return "fail"
	end
end

 

Exatamente como eu queria. So que tem um porem... A pedra vip(8306) tb está voltando 1 nivel caso falhe. Queria que acontecesse somente com a pedra Free(8300)

Link para o comentário
Compartilhar em outros sites

×
×
  • Criar Novo...