GA
pedido

Ajuda a arrumar esses scripts.

Por gabriel28, 23 de mar. de 2016 em Scripts

12
2k
gabriel28G
23 de março de 2016 às 17:43

Estou com esses dois scripts que não estou conseguindo ajeitar. Segue eles:

O problema desse é que não remove de jeito nenhum o item quando ele é usado:

 

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

   local rewarditems = {
      {id = 2492, chance = 5, count = 1}, -- start with the lowest chances
      {id = 2498, chance = 10, count = 1},
      {id = 2488, chance = 15, count = 1},
      {id = 2152, chance = 70, count = math.random(1, 10)}
   }   

   local chance = math.random(1,100)
   for i = 1, #rewarditems, 1 do
      if(chance < rewarditems[i].chance) then
         local info = getItemInfo(rewarditems[i].id)
         if(rewarditems[i].count > 1) then
            text = rewarditems[i].count .. " " .. info.plural
         else
            text = info.article .. " " .. info.name
         end
 
         local item = doCreateItemEx(rewarditems[i].id, rewarditems[i].count)
         if(doPlayerAddItemEx(cid, item, false) ~= RETURNVALUE_NOERROR) then
            doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
            text = "You have failed to open your mystery box. The item is to heavy or you have not enough space to take it."
         else
            text = "You have received " .. text .. "."
            doRemoveItem(item.uid, 1)
         end
         doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, text)
         return true
      else
         chance = chance - rewarditems[i].chance
      end
   end
end

 



Esse eu não estou conseguindo por uma chance individual para cada item e nem estou conseguindo por um math.randon pra vir uma quantidade aleatória dos itens.

 

local stonesMinerar = {
	[5709] = {minerioid = 5944, count = math.random(1, 10)}, -- [id da pedra] = {minerioid = id do item que ganha, count = countidade que ganha}
	[5624] = {minerioid = 6277, count = math.random(1, 5)},
	[8748] = {minerioid = 5880, count = math.random(1, 5)},
	[5619] = {minerioid = 12700, count = math.random(1, 3)}
}
local config = {
	exhaustionMinutes = 60, -- exausted em minutos
	effectChar = 30, -- efeito no char.
	storageUse = 34542 -- storage usado/ não mude caso não entenda.
}
local chance = 50

function onUse(cid, item, fromPosition, itemEx, toPosition)
local a = math.random
if(exhaustion.check(cid, config.storageUse) == TRUE) then
   if (exhaustion.get(cid, config.storageUse) >= 60) then
   doPlayerSendCancel(cid, "Voçê só pode usar após [" .. math.floor(exhaustion.get(cid, config.storageUse) / 60 + 1) .."] minutos.")
   end
	if (exhaustion.get(cid, config.storageUse) <= 60) then
	doPlayerSendCancel(cid, "Voçê só pode usar após [" .. exhaustion.get(cid, config.storageUse).."] segundos.")
	end
return true
end
if stonesMinerar[itemEx.itemid] then
	local a = math.random(1, 100)
    if a < chance then
		doPlayerAddItem(cid, stonesMinerar[itemEx.itemid].minerioid, stonesMinerar[itemEx.itemid].count)
		doPlayerSendTextMessage(cid, 19, "Você recebeu "..(stonesMinerar[itemEx.itemid].count).." "..getItemNameById(stonesMinerar[itemEx.itemid].minerioid).."!")
		doSendMagicEffect(getPlayerPosition(cid), config.effectChar)
		exhaustion.set(cid, config.storageUse, config.exhaustionMinutes*60)
	else
		doPlayerSendCancel(cid, "Você falhou.")
	end
else
	doPlayerSendCancel(cid, "Você não pode minerar isso.")
end
return true
end

 

 

 

Se alguém puder ajudar, agradeço desde já.

DanihcvD
23 de março de 2016 às 18:11

Tenta ae:

 

Primeiro script:

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

   local rewarditems = {
      {id = 2492, chance = 5, count = 1}, -- start with the lowest chances
      {id = 2498, chance = 10, count = 1},
      {id = 2488, chance = 15, count = 1},
      {id = 2152, chance = 70, count = math.random(1, 10)}
   }   

   local chance = math.random(1,100)
   for i = 1, #rewarditems, 1 do
      if(chance < rewarditems[i].chance) then
         local info = getItemInfo(rewarditems[i].id)
         if(rewarditems[i].count > 1) then
            text = rewarditems[i].count .. " " .. info.plural
         else
            text = info.article .. " " .. info.name
         end
 
         local item = doCreateItemEx(rewarditems[i].id, rewarditems[i].count)
         if(doPlayerAddItemEx(cid, item, false) ~= RETURNVALUE_NOERROR) then
            doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
            text = "You have failed to open your mystery box. The item is too heavy or you have not enough space to take it."
         else
            text = "You have received " .. text .. "."
            doRemoveItem(item.itemid, 1)
         end
         doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, text)
         return true
      else
         chance = chance - rewarditems[i].chance
      end
   end
end

 

 

 

Segundo:

 

 

local stonesMinerar = {
	[5709] = {minerioid = 5944, count = math.random(1, 10)}, -- [id da pedra] = {minerioid = id do item que ganha, count = countidade que ganha}
	[5624] = {minerioid = 6277, count = math.random(1, 5)},
	[8748] = {minerioid = 5880, count = math.random(1, 5)},
	[5619] = {minerioid = 12700, count = math.random(1, 3)}
}
local config = {
	exhaustionMinutes = 60, -- exausted em minutos
	effectChar = 30, -- efeito no char.
	storageUse = 34542 -- storage usado/ não mude caso não entenda.
}
local chance = 50

function onUse(cid, item, fromPosition, itemEx, toPosition)
local a = math.random(1, 100)
if(exhaustion.check(cid, config.storageUse) == TRUE) then
   if (exhaustion.get(cid, config.storageUse) >= 60) then
   doPlayerSendCancel(cid, "Voçê só pode usar após [" .. math.floor(exhaustion.get(cid, config.storageUse) / 60 + 1) .."] minutos.")
   end
	if (exhaustion.get(cid, config.storageUse) <= 60) then
	doPlayerSendCancel(cid, "Voçê só pode usar após [" .. exhaustion.get(cid, config.storageUse).."] segundos.")
	end
return true
end
if stonesMinerar[itemEx.itemid] then
    if a < chance then
		doPlayerAddItem(cid, stonesMinerar[itemEx.itemid].minerioid, stonesMinerar[itemEx.itemid].count)
		doPlayerSendTextMessage(cid, 19, "Você recebeu "..(stonesMinerar[itemEx.itemid].count).." "..getItemNameById(stonesMinerar[itemEx.itemid].minerioid).."!")
		doSendMagicEffect(getPlayerPosition(cid), config.effectChar)
		exhaustion.set(cid, config.storageUse, config.exhaustionMinutes*60)
	else
		doPlayerSendCancel(cid, "Você falhou.")
	end
else
	doPlayerSendCancel(cid, "Você não pode minerar isso.")
end
return true
end

 

 

gabriel28G
23 de março de 2016 às 18:38

Tenta ae:

 

Só pra perguntar antes de ir testar. O segundo script está com chances individuais pra cada item? Por exemplo: Esse item dessa linha > [5619] = {minerioid = 12700, count = math.random(1, 4)} < tem 20% de chances de ser obtido. Enquanto o dessa > [5709] = {minerioid = 5944, count = math.random(1, 10)}, < tem 50% de chance. Ou todos ainda estão com os 50%?

DanihcvD
24 de março de 2016 às 02:41

@, acredito que estejam com as counts individuais.

FurabioF
24 de março de 2016 às 09:39

 

Só pra perguntar antes de ir testar. O segundo script está com chances individuais pra cada item? Por exemplo: Esse item dessa linha > [5619] = {minerioid = 12700, count = math.random(1, 4)} < tem 20% de chances de ser obtido. Enquanto o dessa > [5709] = {minerioid = 5944, count = math.random(1, 10)}, < tem 50% de chance.

 

Na verdade esse math.random no count que você está vendo não é a chance de ser obtido e sim a quantidade, ou seja a quantidade pode vir de 1 a 4 dependendo a sua sorte e no outro de 1 a 10.

 

A configuração da chance de cada item está em chance, "chance=10" ele tem 10% de chance de conseguir o item ... modifique a seu gosto.

local stonesMinerar = {
-- [id da pedra] = {minerioid = id do item que ganha, chance= a % de chance que ele tem conseguir ou não o item, count = countidade que ganha}
    [5709] = {minerioid = 5944, chance= 10, count = math.random(1, 10)}, 
    [5624] = {minerioid = 6277, chance= 10, count = math.random(1, 5)},
    [8748] = {minerioid = 5880, chance= 10, count = math.random(1, 5)},
    [5619] = {minerioid = 12700, chance= 10, count = math.random(1, 3)}
}
local config = {
    exhaustionMinutes = 60, -- exausted em minutos
    effectChar = 30, -- efeito no char.
    storageUse = 34542 -- storage usado/ não mude caso não entenda.
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if exhaustion.check(cid, config.storageUse) then
        if exhaustion.get(cid, config.storageUse >= 60 then
            doPlayerSendCancel(cid, "Voçê só pode usar após [" .. math.floor(exhaustion.get(cid, config.storageUse) / 60 + 1) .."] minutos.")
        end
        if exhaustion.get(cid, config.storageUse <= 60 then
            doPlayerSendCancel(cid, "Voçê só pode usar após [" .. exhaustion.get(cid, config.storageUse).."] segundos.")
        end
        return true
    end
    local random = math.random(1, 100)
    local itemMinerar = stonesMinerar[itemEx.itemid]
    if itemMinerar then
        if random <= itemMinerar.chance then
            doPlayerAddItem(cid, itemMinerar.minerioid, itemMinerar.count)
            doPlayerSendTextMessage(cid, 19, "Você recebeu "..(itemMinerar.count).." "..getItemNameById(itemMinerar.minerioid).."!")
            doSendMagicEffect(getPlayerPosition(cid), config.effectChar)
            exhaustion.set(cid, config.storageUse, config.exhaustionMinutes*60)
        else
            doPlayerSendCancel(cid, "Você falhou.")
        end
    else
        doPlayerSendCancel(cid, "Você não pode minerar isso.")
    end
    return true
end
gabriel28G
24 de março de 2016 às 10:49

O math.randon no count eu já sabia pra o que era, só que não funcionava, sempre vinha uma quantidade exata.
Vou testar os scripts aqui e já darei o feedback.

 

 

EDIT: O primeiro script continua com o mesmo problema, esse erro: lua:26 attempt to index local 'item' <a number value>

E no segundo script, o math.randon pra gerar uma quantidade aleatória de itens para o player ainda não funciona, sempre dá a mesma quantidade.

Editado Março 24 por gabrielvs

FurabioF
24 de março de 2016 às 11:28

O math.random ta fora do callback por isso sempre da a mesma quantidade hahaha, tenta agora :

local config = {
    exhaustionMinutes = 60, -- exausted em minutos
    effectChar = 30, -- efeito no char.
    storageUse = 34542 -- storage usado/ não mude caso não entenda.
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
    local stonesMinerar = {
    -- [id da pedra] = {minerioid = id do item que ganha, chance= a % de chance que ele tem conseguir ou não o item, count = countidade que ganha}
        [5709] = {minerioid = 5944, chance= 10, count = math.random(1, 10)}, 
        [5624] = {minerioid = 6277, chance= 10, count = math.random(1, 5)},
        [8748] = {minerioid = 5880, chance= 10, count = math.random(1, 5)},
        [5619] = {minerioid = 12700, chance= 10, count = math.random(1, 3)}
    }
    if exhaustion.check(cid, config.storageUse) then
        if exhaustion.get(cid, config.storageUse >= 60 then
            doPlayerSendCancel(cid, "Voçê só pode usar após [" .. math.floor(exhaustion.get(cid, config.storageUse) / 60 + 1) .."] minutos.")
        end
        if exhaustion.get(cid, config.storageUse <= 60 then
            doPlayerSendCancel(cid, "Voçê só pode usar após [" .. exhaustion.get(cid, config.storageUse).."] segundos.")
        end
        return true
    end
    local random = math.random(1, 100)
    local itemMinerar = stonesMinerar[itemEx.itemid]
    if itemMinerar then
        if random <= itemMinerar.chance then
            doPlayerAddItem(cid, itemMinerar.minerioid, itemMinerar.count)
            doPlayerSendTextMessage(cid, 19, "Você recebeu "..(itemMinerar.count).." "..getItemNameById(itemMinerar.minerioid).."!")
            doSendMagicEffect(getPlayerPosition(cid), config.effectChar)
            exhaustion.set(cid, config.storageUse, config.exhaustionMinutes*60)
        else
            doPlayerSendCancel(cid, "Você falhou.")
        end
    else
        doPlayerSendCancel(cid, "Você não pode minerar isso.")
    end
    return true
end
gabriel28G
24 de março de 2016 às 11:44

Funcionou, muito obrigado. Agora só falta o primeiro script que não consigo resolver de jeito nenhum.
Já tentei: doRemoveItem(item.itemid, 1) , doRemoveItem(8110, 1) , doRemoveItem(itemEx.item, 1) , doRemoveItem(item.uid, 1) e nada de funcionar.

FurabioF
24 de março de 2016 às 12:19

Esse primeiro script é tipo uma surprisebox, onde você usa o item e recebe um item aleatório ou recebe todos os itens da tabela de acordo com a sorte ?

Editado Março 24 por TheSumm

gabriel28G
24 de março de 2016 às 12:49

Sim.

 

FurabioF
24 de março de 2016 às 13:04

Tenta :

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local rewarditems = {
        {id = 2492, chance = 5, count = 1}, -- start with the lowest chances
        {id = 2498, chance = 10, count = 1},
        {id = 2488, chance = 15, count = 1},
        {id = 2152, chance = 70, count = math.random(1, 10)}
    }   
    local chance = math.random(1,100)
    for i = 1, #rewarditems, 1 do
        if(chance < rewarditems[i].chance) then
            local info = getItemInfo(rewarditems[i].id)
            if(rewarditems[i].count > 1) then
                text = rewarditems[i].count .. " " .. info.plural
            else
                text = info.article .. " " .. info.name
            end
        local item = doCreateItemEx(rewarditems[i].id, rewarditems[i].count)
            if(doPlayerAddItemEx(cid, item, false) ~= RETURNVALUE_NOERROR) then
                doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
                text = "You have failed to open your mystery box. The item is to heavy or you have not enough space to take it."
            else
                text = "You have received " .. text .. "."
                doPlayerRemoveItem(cid, 8110, 1)
            end
            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, text)
        else
            chance = chance - rewarditems[i].chance
        end
    end
    return true
end
gabriel28G
27 de março de 2016 às 14:48

 

Tenta :

 

 

Funcionou, o item ta sumindo ao dar use agora. Só que as vezes ganha mais de um item.