Ir para conteúdo

Featured Replies

  • Respostas 18
  • Visualizações 2.4k
  • Created
  • Última resposta

Top Posters In This Topic

Postado
  • Autor

Bom dia, poderia dar uma olhada pra mim se tem algo errado por favor?

Nao consegui achar a função de alterar item, coloquei de adicionar, mas acho que esta errado e nao vai dar certo.

 

Citar

local forge = Action()

local count = 1
local item = 24963
local porcentagem = 100 -- porcentagem de chance de forjar
local chance = { -- cada id significa 10% de chance de acerto
    { id = 10},
    { id = 20},
    { id = 30},
    { id = 40},
    { id = 50},
    { id = 60},
    { id = 70},
    { id = 80},
    { id = 90},
    { id = 100}  
}

    
function forge.onUse(player, item, fromPosition, target, toPosition, isHotkey)
   local randId = math.random(1, #chance)
   local rewardItem = chance[randId]


        if item:getCount(item) < (count) then                        
            player:sendTextMessage(MESSAGE_STATUS_SMALL, "Voce nao tem a quantidade de items necessaria para forjar")
            player:getPosition():sendMagicEffect(CONST_ME_POFF)
            return
        end
          
   local split = param:split(",")
   local itemType = ItemType(split[1])


    if target.itemType:getId() == 0 then
        porcentagem = 100
    else
    if target.itemType:getId() == 1 then
        porcentagem = 90
    else
    if target.itemType:getId() == 2 then
        porcentagem = 80
    else
    if target.itemType:getId() == 3 then
        porcentagem = 70
    else
    if target.itemType:getId() == 4 then
        porcentagem = 60
    else
    if target.itemType:getId() == 5 then
        porcentagem = 50
    else
    if target.itemType:getId() == 6 then
        porcentagem = 40
    else
    if target.itemType:getId() == 7 then
        porcentagem = 30
    else
    if target.itemType:getId() == 8 then
        porcentagem = 20
    else
    if target.itemType:getId() == 9 then
        porcentagem = 10
    else
    if target.itemType:getId() == nil  then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "Este nao e um item Forjavel.")
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        return
    end
    end    
    end
    end
    end
    end
    end
    end
    end
    end
    end

   
    
    if chance.id <= (porcentagem) then
        itemType:remove(count)
        player:addItem(target.itemType:getId(), 1):setTier(tier)
        player:sendTextMessage(MESSAGE_STATUS_DEFAULT, "Parabens, o item foi forjado.")
        player:getPosition():sendMagicEffect(50)
    else
        itemType:remove(count)
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "Sua forja falhou. Voce perdeu os items de forja.")
        player:getPosition():sendMagicEffect(CONST_ME_POFF)

                return
    end    
                
                


    
end


forge:id(24963)
forge:register()


 

 

Editado por Pacera (veja o histórico de edições)

Postado
local forge = Action()

local count = 1
local porcentagem = 100 -- porcentagem de chance de forjar
local chance = { -- cada id significa 10% de chance de acerto
	[1] = 100,
	[2] = 90,
    [3] = 80,
    [4] = 70,
    [5] = 60,
    [6] = 50,
    [7] = 40,
    [8] = 30,
    [9] = 20,
    [10] = 10  
}
    
function forge.onUse(player, item, fromPosition, target, toPosition, isHotkey)
	if not target or not target:isItem() then
		return false
	end

	local targetId = target:getId()

	local targetTier = target:getTier()
	if not targetTier then
		player:sendTextMessage(MESSAGE_STATUS_SMALL, "Este nao e um item Forjavel.")
		player:getPosition():sendMagicEffect(CONST_ME_POFF)
		return true
	end

	if not target:remove(count) then
		player:sendTextMessage(MESSAGE_STATUS_SMALL, "Voce nao tem a quantidade de items necessaria para forjar")
		player:getPosition():sendMagicEffect(CONST_ME_POFF)
		return true
	end

	local rand = math.random(100)
	local chanceTier = target:getTier() and target:getTier() or 0
	if rand > chance[chanceTier] then
		player:sendTextMessage(MESSAGE_STATUS_SMALL, "Voce forja falhou")
		player:getPosition():sendMagicEffect(CONST_ME_POFF)
		return true
	end	

	if target:setTier(targetTier + 1) then
		player:sendTextMessage(MESSAGE_STATUS_DEFAULT, "Parabens, o item foi forjado.")
		player:getPosition():sendMagicEffect(50)
	end
	
	return true
end


forge:id(24963)
forge:register()

 

Postado
  • Autor

Obrigado

Ola, estou tendo erro na source ao usar em items como: potions, runas, gold coin ou items nao forjaveis. qd o item é tier 0 da o mesmo erro.

[error] Lua script error:
scriptInterface: [Scripts Interface]
scriptId: [C:\Program Files (x86)\canary-global-windows-x64-full\data\scripts\custom\forja.lua:callback]
timerEvent: []
 callbackId:[]
function: []
error [...ry-global-windows-x64-full\data\scripts\custom\forja.lua:49: attempt to compare nil with number
stack traceback:
        [C]: in function '__lt'
        ...ry-global-windows-x64-full\data\scripts\custom\forja.lua:49: in function <...ry-global-windows-x64-full\data\scripts\custom\forja.lua:18>]

Editado por Pacera (veja o histórico de edições)

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.

Visitante
Responder

Quem Está Navegando 0

  • Nenhum usuário registrado visualizando esta página.

Conteúdo Similar

Estatísticas dos Fóruns

  • Tópicos 96.9k
  • Posts 519.6k

Informação Importante

Confirmação de Termo