Ir para conteúdo
  • 0

Ajuda aumentar chances se o item for 8300


maikons

Pergunta

Queria que cada item tivesse uma chance pra que o itemid 8300 fosse 2 vezes mais fácil de acertar

 

If item 8306 changes =

	  levels = {	  [1] = {50, false, false},	  [2] = {20, false, false},	  [3] = {10, true, true}	  },

 

Else if item 8300 changes =

	  levels = {	  [1] = {100, false, false},	  [2] = {40, false, false},	  [3] = {20, true, true}	  },

 


script

	--PERFECT UPGRADE SYSTEM	  UpgradeHandler = {	     nameLv = {	      [1] = "UNIQ",	      [2] = "RARE",	      [3] = "EPIC"	    },	  levels = {	  [1] = {50, false, false},	  [2] = {20, false, false},	  [3] = {10, true, true}	  },	  broadcast = 3,	  attributes = {	  ["attack"] = 3,	  ["defense"] = 2,	  ["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 = {	  [8306] = {range = {0, 10}, info = {chance = 0, removeable = true}},	  [8300] = {range = {0, 10}, info = {chance = 0, 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 * 3)	  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()	  -- this will return the level by the quality or 0 if it has no quality.	  self.item.level = 0	     for r, v in ipairs(self.nameLv) do	      if self:getItemName():find(v) then	      self.item.level = r	      end	     end	  end	  function UpgradeHandler:refine(uid, item)	     if (self.item.level >= 3) then	       return true	     end	 	  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	  doBroadcastMessage(self.message.broadcast:format(getCreatureName(uid), self.item.name, (self.item.level + 1)))	  end	  -- it says if the item's level is greater then 0 (meaning is level equal to 1 or more) if it is add 1 more	  -- if the current level equals 0 add 1 to it	  self:setItemName(self.item.level > 0 and self.nameLv[self.item.level + 1].." "..(self:getItemName():gsub(self.nameLv[self.item.level].." ", "")) or self.nameLv[1].." "..self:getItemName())	  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 item.itemid == 8300 then	  if self.item.level > 0 then	  -- this will remove any number with a + sign in front of it from the string	  self:setItemName(self:getItemName():gsub((self.nameLv[self.item.level].." "), ""))	  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, getItemAttribute(self.item.uid, key) - self.item.level * value)	  end	  end	  end	  else	  doRemoveItem(self.item.uid, 1)	  end	  doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, item.itemid == 8300 and "Your item level has been reseted." or "You have broken your item while trying to upgrade it.")	  end	  end

Link para o comentário
Compartilhar em outros sites

6 respostass a esta questão

Posts Recomendados

  • 0
	--PERFECT UPGRADE SYSTEM	  UpgradeHandler = {	     nameLv = {	      [1] = "UNIQ",	      [2] = "RARE",	      [3] = "EPIC"	    },	  levels = {	  [1] = {50, false, false},	  [2] = {20, false, false},	  [3] = {10, true, true}	  },	  broadcast = 3,	  attributes = {	  ["attack"] = 3,	  ["defense"] = 2,	  ["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 = {	  [8306] = {range = {0, 10}, info = {chance = 1, removeable = true}},	  [8300] = {range = {0, 10}, info = {chance = 2, 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 * 3)	  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()	  -- this will return the level by the quality or 0 if it has no quality.	  self.item.level = 0	     for r, v in ipairs(self.nameLv) do	      if self:getItemName():find(v) then	      self.item.level = r	      end	     end	  end	  function UpgradeHandler:refine(uid, item)	     if (self.item.level >= 3) then	       return true	     end	 	  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	  doBroadcastMessage(self.message.broadcast:format(getCreatureName(uid), self.item.name, (self.item.level + 1)))	  end	  -- it says if the item's level is greater then 0 (meaning is level equal to 1 or more) if it is add 1 more	  -- if the current level equals 0 add 1 to it	  self:setItemName(self.item.level > 0 and self.nameLv[self.item.level + 1].." "..(self:getItemName():gsub(self.nameLv[self.item.level].." ", "")) or self.nameLv[1].." "..self:getItemName())	  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 item.itemid == 8300 then	  if self.item.level > 0 then	  -- this will remove any number with a + sign in front of it from the string	  self:setItemName(self:getItemName():gsub((self.nameLv[self.item.level].." "), ""))	  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, getItemAttribute(self.item.uid, key) - self.item.level * value)	  end	  end	  end	  else	  doRemoveItem(self.item.uid, 1)	  end	  doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, item.itemid == 8300 and "Your item level has been reseted." or "You have broken your item while trying to upgrade it.")	  end	  end

agora vc edita ali na chance da tools: 8306 é 1x e 8300 é 2x.

Link para o comentário
Compartilhar em outros sites

  • 0

Voce pode fazer na mão o calculo, como o @Night Wolf fez. Porém se for usar em uma tabela muito grande isso pode ser bem massivo e desgastante.

Para resolver tu pode fazer um algoritimo que leva como base a soma das rates, e vai somando-as até que se chegue no numero sorteado.

Em lua quando se usa a função math.random() sem parametros ela retorna um numero flutuante de 0.0 a 1.0

 

Genericamente poderia ser escrita uma função assim:
 

function randomItemsTable(itemsTable)	local total = 0	for _, it in ipairs(itemsTable) do		total = total + it.rate	end	table.sort(itemsTable, function(a, b) return a.rate < b.rate end)		local rand = math.random()	local sum = 0	for _, it in ipairs(itemsTable) do		sum = sum + it.rate/total		if sum > rand then			return it.id		end	endend

 

Exemplo de uso, com estatistica pra tu ver a precisão:

function randomItemsTable(itemsTable)	local total = 0	for _, it in ipairs(itemsTable) do		total = total + it.rate	end	table.sort(itemsTable, function(a, b) return a.rate < b.rate end)		local rand = math.random()	local sum = 0	for _, it in ipairs(itemsTable) do		sum = sum + it.rate/total		if sum > rand then			return it.id		end	endendlocal items = {	{id = 50, rate = 1};	{id = 60, rate = 2};	{id = 51, rate = 1};	{id = 80, rate = 3};	{id = 123, rate = 8}}local results = {}for _, it in ipairs(items) do	results[it.id] = 0endlocal tries = 500000math.randomseed(os.time())for i = 0, tries do 	id = randomItemsTable(items)	results[id] = results[id] + 1endprint("Number of tries: ".. tries)for _, it in ipairs(items) do	print(string.format("ID: %d\t\tRate: %d\t\tRate percent: %.2f%%\tSorted times: %d", it.id, it.rate, 100 * results[it.id]/tries, results[it.id]))end

Captura de tela de 2016-05-17 20:41:51.png

573bac90d6732_Capturadetelade2016-05-17204151.png.3eebfc00bc8f73dcd2e6a583bff39129.png

Link para o comentário
Compartilhar em outros sites

  • 0
21 hours ago, Night Wolf said:
	--PERFECT UPGRADE SYSTEM	  UpgradeHandler = {	     nameLv = {	      [1] = "UNIQ",	      [2] = "RARE",	      [3] = "EPIC"	    },	  levels = {	  [1] = {50, false, false},	  [2] = {20, false, false},	  [3] = {10, true, true}	  },	  broadcast = 3,	  attributes = {	  ["attack"] = 3,	  ["defense"] = 2,	  ["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 = {	  [8306] = {range = {0, 10}, info = {chance = 1, removeable = true}},	  [8300] = {range = {0, 10}, info = {chance = 2, 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 * 3)	  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()	  -- this will return the level by the quality or 0 if it has no quality.	  self.item.level = 0	     for r, v in ipairs(self.nameLv) do	      if self:getItemName():find(v) then	      self.item.level = r	      end	     end	  end	  function UpgradeHandler:refine(uid, item)	     if (self.item.level >= 3) then	       return true	     end	 	  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	  doBroadcastMessage(self.message.broadcast:format(getCreatureName(uid), self.item.name, (self.item.level + 1)))	  end	  -- it says if the item's level is greater then 0 (meaning is level equal to 1 or more) if it is add 1 more	  -- if the current level equals 0 add 1 to it	  self:setItemName(self.item.level > 0 and self.nameLv[self.item.level + 1].." "..(self:getItemName():gsub(self.nameLv[self.item.level].." ", "")) or self.nameLv[1].." "..self:getItemName())	  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 item.itemid == 8300 then	  if self.item.level > 0 then	  -- this will remove any number with a + sign in front of it from the string	  self:setItemName(self:getItemName():gsub((self.nameLv[self.item.level].." "), ""))	  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, getItemAttribute(self.item.uid, key) - self.item.level * value)	  end	  end	  end	  else	  doRemoveItem(self.item.uid, 1)	  end	  doPlayerSendTextMessage(uid, MESSAGE_STATUS_CONSOLE_BLUE, item.itemid == 8300 and "Your item level has been reseted." or "You have broken your item while trying to upgrade it.")	  end	  end

agora vc edita ali na chance da tools: 8306 é 1x e 8300 é 2x.

 

 

Não sei o porque, mas o código ta aparecendo pra mim (não sei se é só pra mim)

Com varios  &gt &lt

Troca o código pra PHP que arruma eu acho, pelo menos quando eu posto

Link para o comentário
Compartilhar em outros sites

  • 0
9 horas atrás, maikons disse:

 

 

Não sei o porque, mas o código ta aparecendo pra mim (não sei se é só pra mim)

Com varios  &gt &lt

Troca o código pra PHP que arruma eu acho, pelo menos quando eu posto

editei, desculpe não ter notado..

Link para o comentário
Compartilhar em outros sites

×
×
  • Criar Novo...