Postado Outubro 18, 2019 5 anos E ai pessoal do TK! Ando tentando fazer umas paradas diferentes/inovadoras pro meu server recentemente, e entre elas está o uso do Lucky Clover Amulet. Gostaria de saber se é possível fazer um script que faça com que, quando o player matar um monstro tendo este colar equipado, ele tenha uma chance de loot aumentada em, digamos, 10%. Agradeço antecipadamente qualquer ajuda ou esclarecimento que puderem dar.
Postado Outubro 18, 2019 5 anos Em data/events/scripts/player.lua, procure essa função: function Player:onGainExperience(sourc e, exp, rawExp) Agora ache o fim dela: return exp end end Spoiler if getPlayerStorageValue(cid, stor) >= 0 then local stor = 12345 -- storage -- Apply rarity chance to corpse contents find_loot_Container(corpse:getPosition()) -- Print loot list to Server Log if owner then local loot_msg = "Loot of " .. self:getNameDescription() .. ": " .. corpse:getContentDescription() if owner:getParty() then owner:getParty():broadcastLoot(loot_msg) owner:getParty():broadcastChannelLoot(loot_msg) else owner:sendTextMessage(MESSAGE_INFO_DESCR, loot_msg) -- Loot channel un-used on my server. -- owner:channelSay(nil, TALKTYPE_CHANNEL_O, loot_msg, 10) end end else local loot_msg = "Loot of " .. self:getNameDescription() .. ": nothing (due to low stamina)" if owner:getParty() then owner:getParty():broadcastLoot(loot_msg) owner:getParty():broadcastChannelLoot(loot_msg) else owner:sendTextMessage(MESSAGE_INFO_DESCR, loot_msg) end local corpse:decay() = corpse:decay() function MonsterType.createLootItem(self, lootBlock, modifier) local lootTable = {} local itemCount = 0 local randvalue = math.random(0, 100000) / (configManager.getNumber(configKeys.RATE_LOOT) * modifier); if randvalue < lootBlock.chance then if (ItemType(lootBlock.itemId):isStackable()) then itemCount = randvalue % lootBlock.maxCount + 1; else itemCount = 1; while (itemCount > 0) do local n = math.min(itemCount, 100) itemCount = itemCount - n local item = Game.createItem(lootBlock.itemId, n) if item then if lootBlock.subType ~= -1 then item:transform(lootBlock.itemId, lootBlock.subType) end if lootBlock.actionId ~= -1 then item:setActionId(lootBlock.actionId) end if lootBlock.text and lootBlock.text ~= "" then item:setAttribute(ITEM_ATTRIBUTE_TEXT, lootBlock.text) end table.insert(lootTable, item) end return #lootTable == 0 and nil or lootTable function MonsterType.createLootContainer(self, parent, lootBlock, modifier) if #lootBlock.childLoot == 0 then return true for _, v in pairs(lootBlock.childLoot) do if parent:getSize() < parent:getCapacity() then local itemList = self:createLootItem(v, modifier) if itemList then for _, item in ipairs(itemList) do if item:isContainer() then local lootContainer = self:createLootContainer(item, v, modifier) if lootContainer then parent:addItemEx(item) end else parent:addItem(item, 1) end end end end return #parent > 0 end return true end end end end end end end Movement script Spoiler local stor = 12345 -- storage function onEquip(cid, item, slot) setPlayerStorageValue(cid, stor, 1) -- já que é no callback de equipar, ele recebe o valor de ID 1 ( player:sendTextMessage(MESSAGE_INFO_DESCR, "TESTE.") return true end function onDeEquip(cid, item, slot) setPlayerStorageValue(cid, stor, -1) -- ao remover o item, ele recebe o valor de ID -1 (como sendo negativo para a checagem do callback -1) return true end Não testei assim que chegar em casa eu testo vlw. Editado Outubro 18, 2019 5 anos por underewarr (veja o histórico de edições)
Postado Outubro 18, 2019 5 anos não esquece de alterar a chance local randvalue = math.random(0, 100000) @MatCollier
Postado Outubro 18, 2019 5 anos Autor @underewarr Uma dúvida: No player lua, eu vou colocar o script dentro do onGainExperience? No caso depois do return exp, antes do end? Ou depois do end? Ta assim aqui: -- Outras coisas antes function Player:onGainExperience(source, exp, rawExp) ... --script inteiro do onGainExperience ... return exp end function Player:onLoseExperience(exp) return exp end function Player:onGainSkillTries(skill, tries) if APPLY_SKILL_MULTIPLIER == false then return tries end if skill == SKILL_MAGLEVEL then return tries * configManager.getNumber(configKeys.RATE_MAGIC) end return tries * configManager.getNumber(configKeys.RATE_SKILL) end
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.