Postado Agosto 13, 2015 9 anos Olá tibianos, Estou tentando fazer um script que ao dar use no item X, o player ganhará um item [entre vários que serão editáveis]. Só que ao invéz de ser randomico queria que fosse por %, por exemplo, cada item tivesse uma % de dropar quando o player desse USE. Grato.
Postado Agosto 13, 2015 9 anos local config = { [13670] = { -- item_exemplo chances = { {from = 1, to = 1, itemId = 2238}, {from = 2, to = 50, itemId = 2237}, {from = 51, to = 100, itemId = 2115}, }, effect = CONST_ME_POFF }, } function onUse(cid, item, fromPosition, itemEx, toPosition, isHotkey) local player = Player(cid) local useId = config[item.itemid] if not useId then return false end local chance = math.random(100) for i = 1, #useId.chances do local randomItem = useId.chances[i] if chance >= randomItem.from and chance <= randomItem.to then if randomItem.itemId then local itemId, count = randomItem.itemId, randomItem.count or 1 player:addItem(itemId, count) else player:say('You found nothing useful.', TALKTYPE_MONSTER_SAY) end item:getPosition():sendMagicEffect(useId.effect) item:remove(1) break end end return true end STYLLER OT 2022
Postado Agosto 13, 2015 9 anos Autor Em 13/08/2015 em 16:29, luanluciano93 disse: local config = { [13670] = { -- item_exemplo chances = { {from = 1, to = 1, itemId = 2238}, {from = 2, to = 50, itemId = 2237}, {from = 51, to = 100, itemId = 2115}, }, effect = CONST_ME_POFF }, } function onUse(player, item, fromPosition, target, toPosition, isHotkey) local useId = config[item.itemid] if not useId then return false end local chance = math.random(100) for i = 1, #useId.chances do local randomItem = useId.chances[i] if chance >= randomItem.from and chance <= randomItem.to then if randomItem.itemId then local itemId, count = randomItem.itemId, randomItem.count or 1 player:addItem(itemId, count) else player:say('You found nothing useful.', TALKTYPE_MONSTER_SAY) end item:getPosition():sendMagicEffect(useId.effect) item:remove(1) break end end return true end Isso ficará na pasta actions, certo? @ Vou testar mais tarde e digo o feedback.
Postado Agosto 13, 2015 9 anos Tenho uma versão aqui também: local items = { --[itemid] = {chance, count}, [11395] = {25, 1}, [11446] = {30, 1}, [11437] = {20, 1}, [5957] = {15, 1}, [11407] = {10, 1}, } function onUse(cid, item) local number = math.random(1, 100) local _item = 0 for itemid, chance in pairs(items) do if _item == 0 then _item = itemid else local new_chance = (chance[1] - number) > 0 and chance[1] - number or number - chance[1] local old_chance = (items[_item][1] - number) > 0 and items[_item][1] - number or number - items[_item][1] if new_chance < old_chance then _item = itemid end end end if _item ~= 0 then local count = items[_item][2] if not isItemStackable(_item) then if count > 1 then for i = 1, count do doPlayerAddItem(cid, _item, 1) end else doPlayerAddItem(cid, _item, 1) end else doPlayerAddItem(cid, _item, count) end doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You received: "..count.."x "..getItemNameById(_item)..(count > 1 and "s" or "")..".") doRemoveItem(item.uid, 1) end return true end <action itemid="IDDOBOX" event="script" value="surprisebox.lua"/> Editado Agosto 13, 2015 9 anos por Animal Pak (veja o histórico de edições)
Postado Agosto 13, 2015 9 anos Autor Em 13/08/2015 em 16:33, adrianinho disse: Isso ficará na pasta actions, certo? @ Vou testar mais tarde e digo o feedback. Mostrar conteúdo oculto Lua Script Error: [Action Interface] data/actions/scripts/boxrandom.lua:onUse data/actions/scripts/boxrandom.lua:24: attempt to index local 'player' (a number value) stack traceback: [C]: in function '__index' data/actions/scripts/boxrandom.lua:24: in function Segue o erro em spoiler.
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.