Jump to content
×
×
  • Create New...
  • 0

Ajuda editar script .lua


Go to solution Solved by Yan18,

Question

Versão do Servidor: TFS - 0.3.5
Tipo de Script: actions
Código:
 

    

Boa noite, então eu tenho esse codigo:

 

local STORAGE_SKILL_LEVEL = 10009

local STORAGE_SKILL_TRY = 10007

	local config = {

	 levels = {

		 {level = {0,9}, quant = {1,1}, percent = 5},

		 {level = {10,19}, quant = {1,1}, percent = 10},

		 {level = {20,29}, quant = {1,1}, percent = 15},

		 {level = {30,39}, quant = {1,1}, percent = 20},

		 {level = {40,49}, quant = {1,1}, percent = 25},

		 {level = {50,59}, quant = {1,1}, percent = 30},

		 {level = {60,69}, quant = {1,1}, percent = 30},

		 {level = {70,79}, quant = {1,1}, percent = 35},

		 {level = {80,89}, quant = {1,1}, percent = 35},

		 {level = {90,99}, quant = {1,1}, percent = 40},

		 {level = {100}, quant = {1,1}, percent = 50}

	 },

	 rocks = {5092}, -- Id das rochas que podem ser quebradas
	 rocks2 = {5093},
	 rocks3 = {5094},
	 rocks4 = {5095},
	 
	 stones = {5097},  -- Modelo = {rock_id, rock_id}
	 stones2 = {5099},
	 stones3 = {5100},
	 stones4 = {5098},

	 rock_delay = 60, -- Tempo de volta da rocha (Em segundos)

	 bonus_chance = 3, -- Chance (em porcentagem) de se conseguir um bonus de exp

	 bonus_exp = 1 -- Bonus extra

	}



------------------------------------

-- END Configurations ---

------------------------------------

function getCuttingLevel(cid)

	return getPlayerStorageValue(cid, STORAGE_SKILL_LEVEL)

end

function setPlayerCuttingLevel(cid, n)

	setPlayerStorageValue(cid, STORAGE_SKILL_LEVEL, n)

end

function addCuttingLevel(cid, n)

	setPlayerCuttingLevel(cid, getCuttingLevel(cid) + (isNumber(n) and n or 1))

	setCuttingTry(cid, 0)

end

function getCuttingInfo(cid)

	for i = 1, #config.levels do

		min = config.levels[i].level[1]; max = config.levels[i].level[2]

		if (getCuttingLevel(cid) >= min and getCuttingLevel(cid) <= max) then

			return {quantity = {min = config.levels[i].quant[1], max = config.levels[i].quant[2]}, chance = config.levels[i].percent}

		end

	end

end

function getStoneByRock(rockid)

	for i = 1, #config.stones do

		if (config.stones[2] == rockid) then
			return config.stones[1]
	    elseif (config.stones2[3] == rockid2) then
			return config.stones2[4]
		end

	end

end

function getCuttingTries(cid)

	return getPlayerStorageValue(cid, STORAGE_SKILL_TRY)

end

function setCuttingTry(cid, n)

	setPlayerStorageValue(cid, STORAGE_SKILL_TRY, n)

end

function addCuttingTry(cid, bonus)

	setCuttingTry(cid, getCuttingTries(cid) + 1 + (bonus and config.bonus_exp or 0))


	if (getCuttingTries(cid) >= getCuttingExpTo(getCuttingLevel(cid))) then -- Up

		doPlayerSendTextMessage(cid, 22, "You advanced from level " .. getCuttingLevel(cid) .. " to level ".. (getCuttingLevel(cid) + 1) .." in miner.")


		if ((getCuttingLevel(cid)+1) == getCuttingMaxLevel()) then

			doPlayerSendTextMessage(cid, 22, "Max level reached in miner.")

		end


		addCuttingLevel(cid)

		doSendMagicEffect(getCreaturePosition(cid), math.random(28,30))

		setCuttingTry(cid, 0)

	end

end

function getCuttingExpTo(level)

	return ((level*1.5)+((level+1)*7))

end

function getCuttingMaxLevel()

	return config.levels[#config.levels].level[#config.levels[#config.levels].level]

end

---------------------------


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

	rock = { id = itemEx.itemid, uid = itemEx.uid, position = toPosition }

	player = { position = getCreaturePosition(cid) }


	if (getCuttingLevel(cid) < 0) then

		setPlayerCuttingLevel(cid, 0)

	end


	if (isInArray(config.rocks, rocks2, rocks3, rocks4, rock.id, rock.id2, rock.id3, rock.id4)) then

		addCuttingTry(cid)


		if (math.random(1,100) <= getCuttingInfo(cid).chance) then

			local collected = math.random(getCuttingInfo(cid).quantity.min, getCuttingInfo(cid).quantity.max)

			doPlayerAddItem(cid, getStoneByRock(rock.id), collected)

			doPlayerSendTextMessage(cid, 22, "You got " .. collected .. " brass" .. (collected > 1 and "s" or "") .. " ore.")


			if (math.random(1,100) <= config.bonus_chance) then -- Bonus calc

				addCuttingTry(cid, true)

				doSendAnimatedText(player.position, "Bonus!", COLOR_ORANGE)

			end


			event_rockCut(rock)

		else

			if (math.random(0,100) <= (0-getCuttingInfo(cid).chance/0)) then

				doPlayerSendTextMessage(cid, 22, "You got nothing.")

				event_rockCut(rock)

			else

				doSendMagicEffect(rock.position, 3)

				doSendAnimatedText(rock.position, "Poff!", COLOR_GREEN)

			end

		end

	else

		doPlayerSendCancel(cid, "This can't be cut.")

	end

end

function event_rockCut(rock)

	addEvent(event_rockGrow, config.rock_delay * 1000, rock.position, rock.id)


	doTransformItem(rock.uid, 5104)

	doSendMagicEffect(rock.position, 3)

	doSendAnimatedText(rock.position, "Tack!", COLOR_GREEN)

	doItemSetAttribute(rock.uid, "name", "A trunk of " .. getItemNameById(rock.id))

end

function event_rockGrow(rockPos, old_id)

	local rock = getThingFromPos(rockPos).uid

	doTransformItem(rock, old_id)

	doItemSetAttribute(rock, "name", getItemNameById(old_id))

	doSendMagicEffect(rockPos, 3)

end

 

eu estou tentando editar para que dependendo da pedra, exemplo, 5092, venha o minerio 5097 e somente ele, eu tentei:

 

		if (config.stones[2] == rockid) then
			return config.stones[1]
	    elseif (config.stones2[3] == rockid2) then
			return config.stones2[4]
		end

mas não estou tendo resultado nenhum, nem erro, alguem poderia me dar uma luz?

Edited by shanden4502
Link to post
Share on other sites

9 answers to this question

Recommended Posts

  • 0
  • Solution
Posted (edited)
1 hora atrás, shanden4502 disse:

vou testar irmão, super obrigado, jaja lhe dou a resposta.

@Yan18Deu esse erro irmão:

 



[Error - Action Interface]
data/actions/scripts/mining.lua:onUse
Description:
data/lib/050-function.lua:10: bad argument #1 to 'ipairs' (table expected, got nil)
stack traceback:
        [C]: in function 'ipairs'
        data/lib/050-function.lua:10: in function 'isInArray'
        data/actions/scripts/mining.lua:115: in function <data/actions/scripts/mining.lua:107>

 

Tinha esquecido de adicionar a nova tabela no array, pois, como criei uma tabela nova, ai faltou passar para o isInArray.

 

local STORAGE_SKILL_LEVEL = 10009
local STORAGE_SKILL_TRY = 10007

local config = {

levels = {
	{level = {0,9}, quant = {1,1}, percent = 5},
	{level = {10,19}, quant = {1,1}, percent = 10},
	{level = {20,29}, quant = {1,1}, percent = 15},
	{level = {30,39}, quant = {1,1}, percent = 20},
	{level = {40,49}, quant = {1,1}, percent = 25},
	{level = {50,59}, quant = {1,1}, percent = 30},
	{level = {60,69}, quant = {1,1}, percent = 30},
	{level = {70,79}, quant = {1,1}, percent = 35},
	{level = {80,89}, quant = {1,1}, percent = 35},
	{level = {90,99}, quant = {1,1}, percent = 40},
	{level = {100}, quant = {1,1}, percent = 50}
},

-- Rocks = Id das rochas que podem ser quebradas || -- Stone = Modelo {rock_id, rock_id} --
stones = {
	{rock = 5092, ore = 5097},
	{rock = 5093, ore = 5099},
	{rock = 5094, ore = 5100},
	{rock = 5095, ore = 5098},
}
	   
	rock_delay = 60, -- Tempo de volta da rocha (Em segundos)
	bonus_chance = 3, -- Chance (em porcentagem) de se conseguir um bonus de exp
	bonus_exp = 1 -- Bonus extra
}

------------------------------------

-- END Configurations ---

------------------------------------

function getCuttingLevel(cid)
	return getPlayerStorageValue(cid, STORAGE_SKILL_LEVEL)
end

function setPlayerCuttingLevel(cid, n)
	setPlayerStorageValue(cid, STORAGE_SKILL_LEVEL, n)
end

function addCuttingLevel(cid, n)
	setPlayerCuttingLevel(cid, getCuttingLevel(cid) + (isNumber(n) and n or 1))
	setCuttingTry(cid, 0)
end

function getCuttingInfo(cid)
	for i = 1, #config.levels do
		min = config.levels[i].level[1]; max = config.levels[i].level[2]

		if (getCuttingLevel(cid) >= min and getCuttingLevel(cid) <= max) then
			return {quantity = {min = config.levels[i].quant[1], max = config.levels[i].quant[2]}, chance = config.levels[i].percent}
		end
	end

end

-- RETORNA O MINÉRIO DE ACORDO COM A ROCHA DESTRUIDA --
function getOreByRock(rock_target)
	for i = 1, #config.stones do
		if config.stones[i].rock == rock_target then
			return config.stones[i].ore	
		end	
	end
end

function getCuttingTries(cid)
	return getPlayerStorageValue(cid, STORAGE_SKILL_TRY)
end

function setCuttingTry(cid, n)
	setPlayerStorageValue(cid, STORAGE_SKILL_TRY, n)
end

function addCuttingTry(cid, bonus)
	setCuttingTry(cid, getCuttingTries(cid) + 1 + (bonus and config.bonus_exp or 0))

	if (getCuttingTries(cid) >= getCuttingExpTo(getCuttingLevel(cid))) then -- Up
		doPlayerSendTextMessage(cid, 22, "You advanced from level " .. getCuttingLevel(cid) .. " to level ".. (getCuttingLevel(cid) + 1) .." in miner.")

		if ((getCuttingLevel(cid)+1) == getCuttingMaxLevel()) then
			doPlayerSendTextMessage(cid, 22, "Max level reached in miner.")
		end

		addCuttingLevel(cid)
		doSendMagicEffect(getCreaturePosition(cid), math.random(28,30))
		setCuttingTry(cid, 0)
	end
end

function getCuttingExpTo(level)
	return ((level*1.5)+((level+1)*7))
end

function getCuttingMaxLevel()
	return config.levels[#config.levels].level[#config.levels[#config.levels].level]
end

------------------------------------------------------------------------------------------------------

function onUse(cid, item, fromPosition, itemEx, toPosition)
local rock = { id = itemEx.itemid, uid = itemEx.uid, position = toPosition }
local player = { position = getCreaturePosition(cid) }

	if (getCuttingLevel(cid) < 0) then
		setPlayerCuttingLevel(cid, 0)
	end

	if isInArray({config.stones[1].rock, config.stones[2].rock, config.stones[3].rock, config.stones[4].rock}, rock.id) then
		addCuttingTry(cid)

		if (math.random(1,100) <= getCuttingInfo(cid).chance) then
			local collected = math.random(getCuttingInfo(cid).quantity.min, getCuttingInfo(cid).quantity.max)
			
			doPlayerAddItem(cid, getOreByRock(rock.id), collected)
			doSendAnimatedText(getThingPos(cid), collected .. " ore", math.random(1, 255))
			doPlayerSendTextMessage(cid, 22, "You got " .. collected .. " brass" .. (collected > 1 and "s" or "") .. " ore.")


			if (math.random(1,100) <= config.bonus_chance) then -- Bonus calc
				addCuttingTry(cid, true)
				doSendAnimatedText(player.position, "Bonus!", COLOR_ORANGE)

			end

			event_rockCut(rock)

		else

			if (math.random(0,100) <= (0-getCuttingInfo(cid).chance/0)) then
				doPlayerSendTextMessage(cid, 22, "You got nothing.")
				event_rockCut(rock)

			else
				doSendMagicEffect(rock.position, 3)
				doSendAnimatedText(rock.position, "Poff!", COLOR_GREEN)
			end
		end

	else
		doPlayerSendCancel(cid, "This can't be cut.")
	end

end

function event_rockCut(rock)
	addEvent(event_rockGrow, config.rock_delay * 1000, rock.position, rock.id)
	doTransformItem(rock.uid, 5104)
	doSendMagicEffect(rock.position, 3)
	doSendAnimatedText(rock.position, "Tack!", COLOR_GREEN)
	doItemSetAttribute(rock.uid, "name", "A trunk of " .. getItemNameById(rock.id))

end

function event_rockGrow(rockPos, old_id)
	local rock = getThingFromPos(rockPos).uid
	doTransformItem(rock, old_id)
	doItemSetAttribute(rock, "name", getItemNameById(old_id))
	doSendMagicEffect(rockPos, 3)

end

Teste e veja se continuo com erro.

Edited by Yan18
Link to post
Share on other sites
  • 0
4 horas atrás, shanden4502 disse:
Versão do Servidor: TFS - 0.3.5
Tipo de Script: actions
Código:
  Mostrar conteúdo oculto



 

Boa noite, então eu tenho esse codigo:

 


local STORAGE_SKILL_LEVEL = 10009

local STORAGE_SKILL_TRY = 10007

	local config = {

	 levels = {

		 {level = {0,9}, quant = {1,1}, percent = 5},

		 {level = {10,19}, quant = {1,1}, percent = 10},

		 {level = {20,29}, quant = {1,1}, percent = 15},

		 {level = {30,39}, quant = {1,1}, percent = 20},

		 {level = {40,49}, quant = {1,1}, percent = 25},

		 {level = {50,59}, quant = {1,1}, percent = 30},

		 {level = {60,69}, quant = {1,1}, percent = 30},

		 {level = {70,79}, quant = {1,1}, percent = 35},

		 {level = {80,89}, quant = {1,1}, percent = 35},

		 {level = {90,99}, quant = {1,1}, percent = 40},

		 {level = {100}, quant = {1,1}, percent = 50}

	 },

	 rocks = {5092}, -- Id das rochas que podem ser quebradas
	 rocks2 = {5093},
	 rocks3 = {5094},
	 rocks4 = {5095},
	 
	 stones = {5097},  -- Modelo = {rock_id, rock_id}
	 stones2 = {5099},
	 stones3 = {5100},
	 stones4 = {5098},

	 rock_delay = 60, -- Tempo de volta da rocha (Em segundos)

	 bonus_chance = 3, -- Chance (em porcentagem) de se conseguir um bonus de exp

	 bonus_exp = 1 -- Bonus extra

	}



------------------------------------

-- END Configurations ---

------------------------------------

function getCuttingLevel(cid)

	return getPlayerStorageValue(cid, STORAGE_SKILL_LEVEL)

end

function setPlayerCuttingLevel(cid, n)

	setPlayerStorageValue(cid, STORAGE_SKILL_LEVEL, n)

end

function addCuttingLevel(cid, n)

	setPlayerCuttingLevel(cid, getCuttingLevel(cid) + (isNumber(n) and n or 1))

	setCuttingTry(cid, 0)

end

function getCuttingInfo(cid)

	for i = 1, #config.levels do

		min = config.levels[i].level[1]; max = config.levels[i].level[2]

		if (getCuttingLevel(cid) >= min and getCuttingLevel(cid) <= max) then

			return {quantity = {min = config.levels[i].quant[1], max = config.levels[i].quant[2]}, chance = config.levels[i].percent}

		end

	end

end

function getStoneByRock(rockid)

	for i = 1, #config.stones do

		if (config.stones[2] == rockid) then
			return config.stones[1]
	    elseif (config.stones2[3] == rockid2) then
			return config.stones2[4]
		end

	end

end

function getCuttingTries(cid)

	return getPlayerStorageValue(cid, STORAGE_SKILL_TRY)

end

function setCuttingTry(cid, n)

	setPlayerStorageValue(cid, STORAGE_SKILL_TRY, n)

end

function addCuttingTry(cid, bonus)

	setCuttingTry(cid, getCuttingTries(cid) + 1 + (bonus and config.bonus_exp or 0))


	if (getCuttingTries(cid) >= getCuttingExpTo(getCuttingLevel(cid))) then -- Up

		doPlayerSendTextMessage(cid, 22, "You advanced from level " .. getCuttingLevel(cid) .. " to level ".. (getCuttingLevel(cid) + 1) .." in miner.")


		if ((getCuttingLevel(cid)+1) == getCuttingMaxLevel()) then

			doPlayerSendTextMessage(cid, 22, "Max level reached in miner.")

		end


		addCuttingLevel(cid)

		doSendMagicEffect(getCreaturePosition(cid), math.random(28,30))

		setCuttingTry(cid, 0)

	end

end

function getCuttingExpTo(level)

	return ((level*1.5)+((level+1)*7))

end

function getCuttingMaxLevel()

	return config.levels[#config.levels].level[#config.levels[#config.levels].level]

end

---------------------------


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

	rock = { id = itemEx.itemid, uid = itemEx.uid, position = toPosition }

	player = { position = getCreaturePosition(cid) }


	if (getCuttingLevel(cid) < 0) then

		setPlayerCuttingLevel(cid, 0)

	end


	if (isInArray(config.rocks, rocks2, rocks3, rocks4, rock.id, rock.id2, rock.id3, rock.id4)) then

		addCuttingTry(cid)


		if (math.random(1,100) <= getCuttingInfo(cid).chance) then

			local collected = math.random(getCuttingInfo(cid).quantity.min, getCuttingInfo(cid).quantity.max)

			doPlayerAddItem(cid, getStoneByRock(rock.id), collected)

			doPlayerSendTextMessage(cid, 22, "You got " .. collected .. " brass" .. (collected > 1 and "s" or "") .. " ore.")


			if (math.random(1,100) <= config.bonus_chance) then -- Bonus calc

				addCuttingTry(cid, true)

				doSendAnimatedText(player.position, "Bonus!", COLOR_ORANGE)

			end


			event_rockCut(rock)

		else

			if (math.random(0,100) <= (0-getCuttingInfo(cid).chance/0)) then

				doPlayerSendTextMessage(cid, 22, "You got nothing.")

				event_rockCut(rock)

			else

				doSendMagicEffect(rock.position, 3)

				doSendAnimatedText(rock.position, "Poff!", COLOR_GREEN)

			end

		end

	else

		doPlayerSendCancel(cid, "This can't be cut.")

	end

end

function event_rockCut(rock)

	addEvent(event_rockGrow, config.rock_delay * 1000, rock.position, rock.id)


	doTransformItem(rock.uid, 5104)

	doSendMagicEffect(rock.position, 3)

	doSendAnimatedText(rock.position, "Tack!", COLOR_GREEN)

	doItemSetAttribute(rock.uid, "name", "A trunk of " .. getItemNameById(rock.id))

end

function event_rockGrow(rockPos, old_id)

	local rock = getThingFromPos(rockPos).uid

	doTransformItem(rock, old_id)

	doItemSetAttribute(rock, "name", getItemNameById(old_id))

	doSendMagicEffect(rockPos, 3)

end

 

eu estou tentando editar para que dependendo da pedra, exemplo, 5092, venha o minerio 5097 e somente ele, eu tentei:

 


		if (config.stones[2] == rockid) then
			 doTransformItem(config.stones[2], config.stones[1])
	    elseif (config.stones2[3] == rockid2) then
			 doTransformItem(config.stones[3], config.stones[4])
		end

mas não estou tendo resultado nenhum, nem erro, alguem poderia me dar uma luz?

Testa assim

Link to post
Share on other sites
  • 0

não acontece nada amigo, o script original era assim antes de eu editar

 

local STORAGE_SKILL_LEVEL = 10002

local STORAGE_SKILL_TRY = 10003

	local config = {

	 levels = {

		 {level = {0,9}, quant = {1,2}, percent = 5},

		 {level = {10,19}, quant = {2,4}, percent = 10},

		 {level = {20,29}, quant = {3,6}, percent = 15},

		 {level = {30,39}, quant = {4,8}, percent = 20},

		 {level = {40,49}, quant = {5,10}, percent = 25},

		 {level = {50,59}, quant = {6,12}, percent = 30},

		 {level = {60,69}, quant = {7,14}, percent = 30},

		 {level = {70,79}, quant = {8,16}, percent = 35},

		 {level = {80,89}, quant = {9,18}, percent = 35},

		 {level = {90,99}, quant = {10,20}, percent = 40},

		 {level = {100}, quant = {11,22}, percent = 50}

	 },

	 rocks = {1356, 1285, 3607, 3616}, -- Id das rochas que podem ser quebradas

	 stones = {},  -- Modelo = {rock_id, rock_id}

	 default_stone = 2157, -- pedra padrão

	 rock_delay = 480, -- Tempo de volta da rocha (Em segundos)

	 bonus_chance = 3, -- Chance (em porcentagem) de se conseguir um bonus de exp

	 bonus_exp = 1 -- Bonus extra

	}



------------------------------------

-- END Configurations ---

------------------------------------

function getMiningLevel(cid)

	return getPlayerStorageValue(cid, STORAGE_SKILL_LEVEL)

end

function setPlayerMiningLevel(cid, n)

	setPlayerStorageValue(cid, STORAGE_SKILL_LEVEL, n)

end

function addMiningLevel(cid, n)

	setPlayerMiningLevel(cid, getMiningLevel(cid) + (isNumber(n) and n or 1))

	setMiningTry(cid, 0)

end

function getMiningInfo(cid)

	for i = 1, #config.levels do

		min = config.levels[i].level[1]; max = config.levels[i].level[2]

		if (getMiningLevel(cid) >= min and getMiningLevel(cid) <= max) then

			return {quantity = {min = config.levels[i].quant[1], max = config.levels[i].quant[2]}, chance = config.levels[i].percent}

		end

	end

end

function getStoneByRock(rockid)

	for i = 1, #config.stones do

		if (config.stones[2] == rockid) then

			return config.stones[1]

		end

	end

	return config.default_stone

end

function getMiningTries(cid)

	return getPlayerStorageValue(cid, STORAGE_SKILL_TRY)

end

function setMiningTry(cid, n)

	setPlayerStorageValue(cid, STORAGE_SKILL_TRY, n)

end

function addMiningTry(cid, bonus)

	setMiningTry(cid, getMiningTries(cid) + 1 + (bonus and config.bonus_exp or 0))


	if (getMiningTries(cid) >= getMiningExpTo(getMiningLevel(cid))) then -- Up

		doPlayerSendTextMessage(cid, 22, "You advanced from level " .. getMiningLevel(cid) .. " to level ".. (getMiningLevel(cid) + 1) .." in mining.")


		if ((getMiningLevel(cid)+1) == getMiningMaxLevel()) then

			doPlayerSendTextMessage(cid, 22, "Max level reached in mining.")

		end


		addMiningLevel(cid)

		doSendMagicEffect(getCreaturePosition(cid), math.random(28,30))

		setMiningTry(cid, 0)

	end

end

function getMiningExpTo(level)

	return ((level*1.5)+((level+1)*7))

end

function getMiningMaxLevel()

	return config.levels[#config.levels].level[#config.levels[#config.levels].level]

end

---------------------------


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

	rock = { id = itemEx.itemid, uid = itemEx.uid, position = toPosition }

	player = { position = getCreaturePosition(cid) }


	if (getMiningLevel(cid) < 0) then

		setPlayerMiningLevel(cid, 0)

	end


	if (isInArray(config.rocks, rock.id)) then

		addMiningTry(cid)


		if (math.random(1,100) <= getMiningInfo(cid).chance) then

			local collected = math.random(getMiningInfo(cid).quantity.min, getMiningInfo(cid).quantity.max)

			doPlayerAddItem(cid, getStoneByRock(rock.id), collected)

			doPlayerSendTextMessage(cid, 22, "You got " .. collected .. " gold" .. (collected > 1 and "s" or "") .. " nuggets.")


			if (math.random(1,100) <= config.bonus_chance) then -- Bonus calc

				addMiningTry(cid, true)

				doSendAnimatedText(player.position, "Bonus!", COLOR_ORANGE)

			end


			event_rockCut(rock)

		else

			if (math.random(1,100) <= (10-getMiningInfo(cid).chance/10)) then

				doPlayerSendTextMessage(cid, 22, "You got nothing.")

				event_rockCut(rock)

			else

				doSendMagicEffect(rock.position, 3)

				doSendAnimatedText(rock.position, "Poff!", COLOR_GREEN)

			end

		end

	else

		doPlayerSendCancel(cid, "This can't be cut.")

	end

end

function event_rockCut(rock)

	addEvent(event_rockGrow, config.rock_delay * 1000, rock.position, rock.id)


	doTransformItem(rock.uid, 3610)

	doSendMagicEffect(rock.position, 3)

	doSendAnimatedText(rock.position, "Tack!", COLOR_GREEN)

	doItemSetAttribute(rock.uid, "name", "A trunk of " .. getItemNameById(rock.id))

end

function event_rockGrow(rockPos, old_id)

	local rock = getThingFromPos(rockPos).uid

	doTransformItem(rock, old_id)

	doItemSetAttribute(rock, "name", getItemNameById(old_id))

	doSendMagicEffect(rockPos, 3)

end

 

talvez com meu edit tenha complicado algo, eu so queria que ao bater na pedra "x", vinhesse o item "y", e na outra pedra "n", vinhesse o item "k"

Link to post
Share on other sites
  • 0
Em 10/08/2020 em 13:32, shanden4502 disse:

não acontece nada amigo, o script original era assim antes de eu editar

 


local STORAGE_SKILL_LEVEL = 10002

local STORAGE_SKILL_TRY = 10003

	local config = {

	 levels = {

		 {level = {0,9}, quant = {1,2}, percent = 5},

		 {level = {10,19}, quant = {2,4}, percent = 10},

		 {level = {20,29}, quant = {3,6}, percent = 15},

		 {level = {30,39}, quant = {4,8}, percent = 20},

		 {level = {40,49}, quant = {5,10}, percent = 25},

		 {level = {50,59}, quant = {6,12}, percent = 30},

		 {level = {60,69}, quant = {7,14}, percent = 30},

		 {level = {70,79}, quant = {8,16}, percent = 35},

		 {level = {80,89}, quant = {9,18}, percent = 35},

		 {level = {90,99}, quant = {10,20}, percent = 40},

		 {level = {100}, quant = {11,22}, percent = 50}

	 },

	 rocks = {1356, 1285, 3607, 3616}, -- Id das rochas que podem ser quebradas

	 stones = {},  -- Modelo = {rock_id, rock_id}

	 default_stone = 2157, -- pedra padrão

	 rock_delay = 480, -- Tempo de volta da rocha (Em segundos)

	 bonus_chance = 3, -- Chance (em porcentagem) de se conseguir um bonus de exp

	 bonus_exp = 1 -- Bonus extra

	}



------------------------------------

-- END Configurations ---

------------------------------------

function getMiningLevel(cid)

	return getPlayerStorageValue(cid, STORAGE_SKILL_LEVEL)

end

function setPlayerMiningLevel(cid, n)

	setPlayerStorageValue(cid, STORAGE_SKILL_LEVEL, n)

end

function addMiningLevel(cid, n)

	setPlayerMiningLevel(cid, getMiningLevel(cid) + (isNumber(n) and n or 1))

	setMiningTry(cid, 0)

end

function getMiningInfo(cid)

	for i = 1, #config.levels do

		min = config.levels[i].level[1]; max = config.levels[i].level[2]

		if (getMiningLevel(cid) >= min and getMiningLevel(cid) <= max) then

			return {quantity = {min = config.levels[i].quant[1], max = config.levels[i].quant[2]}, chance = config.levels[i].percent}

		end

	end

end

function getStoneByRock(rockid)

	for i = 1, #config.stones do

		if (config.stones[2] == rockid) then

			return config.stones[1]

		end

	end

	return config.default_stone

end

function getMiningTries(cid)

	return getPlayerStorageValue(cid, STORAGE_SKILL_TRY)

end

function setMiningTry(cid, n)

	setPlayerStorageValue(cid, STORAGE_SKILL_TRY, n)

end

function addMiningTry(cid, bonus)

	setMiningTry(cid, getMiningTries(cid) + 1 + (bonus and config.bonus_exp or 0))


	if (getMiningTries(cid) >= getMiningExpTo(getMiningLevel(cid))) then -- Up

		doPlayerSendTextMessage(cid, 22, "You advanced from level " .. getMiningLevel(cid) .. " to level ".. (getMiningLevel(cid) + 1) .." in mining.")


		if ((getMiningLevel(cid)+1) == getMiningMaxLevel()) then

			doPlayerSendTextMessage(cid, 22, "Max level reached in mining.")

		end


		addMiningLevel(cid)

		doSendMagicEffect(getCreaturePosition(cid), math.random(28,30))

		setMiningTry(cid, 0)

	end

end

function getMiningExpTo(level)

	return ((level*1.5)+((level+1)*7))

end

function getMiningMaxLevel()

	return config.levels[#config.levels].level[#config.levels[#config.levels].level]

end

---------------------------


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

	rock = { id = itemEx.itemid, uid = itemEx.uid, position = toPosition }

	player = { position = getCreaturePosition(cid) }


	if (getMiningLevel(cid) < 0) then

		setPlayerMiningLevel(cid, 0)

	end


	if (isInArray(config.rocks, rock.id)) then

		addMiningTry(cid)


		if (math.random(1,100) <= getMiningInfo(cid).chance) then

			local collected = math.random(getMiningInfo(cid).quantity.min, getMiningInfo(cid).quantity.max)

			doPlayerAddItem(cid, getStoneByRock(rock.id), collected)

			doPlayerSendTextMessage(cid, 22, "You got " .. collected .. " gold" .. (collected > 1 and "s" or "") .. " nuggets.")


			if (math.random(1,100) <= config.bonus_chance) then -- Bonus calc

				addMiningTry(cid, true)

				doSendAnimatedText(player.position, "Bonus!", COLOR_ORANGE)

			end


			event_rockCut(rock)

		else

			if (math.random(1,100) <= (10-getMiningInfo(cid).chance/10)) then

				doPlayerSendTextMessage(cid, 22, "You got nothing.")

				event_rockCut(rock)

			else

				doSendMagicEffect(rock.position, 3)

				doSendAnimatedText(rock.position, "Poff!", COLOR_GREEN)

			end

		end

	else

		doPlayerSendCancel(cid, "This can't be cut.")

	end

end

function event_rockCut(rock)

	addEvent(event_rockGrow, config.rock_delay * 1000, rock.position, rock.id)


	doTransformItem(rock.uid, 3610)

	doSendMagicEffect(rock.position, 3)

	doSendAnimatedText(rock.position, "Tack!", COLOR_GREEN)

	doItemSetAttribute(rock.uid, "name", "A trunk of " .. getItemNameById(rock.id))

end

function event_rockGrow(rockPos, old_id)

	local rock = getThingFromPos(rockPos).uid

	doTransformItem(rock, old_id)

	doItemSetAttribute(rock, "name", getItemNameById(old_id))

	doSendMagicEffect(rockPos, 3)

end

 

talvez com meu edit tenha complicado algo, eu so queria que ao bater na pedra "x", vinhesse o item "y", e na outra pedra "n", vinhesse o item "k"

Os id dos minérios já estão no script? E quer que saia qual minério para cada pedra quebrada?

Link to post
Share on other sites
  • 0
20 horas atrás, Yan18 disse:

Os id dos minérios já estão no script? E quer que saia qual minério para cada pedra quebrada?

Estão no Script de cima, mas isso eu edito, só queria conseguir fazer funcionar

se poder me ajudar ficarei mt grato

Link to post
Share on other sites
  • 0
Em 12/08/2020 em 17:08, shanden4502 disse:

Estão no Script de cima, mas isso eu edito, só queria conseguir fazer funcionar

se poder me ajudar ficarei mt grato

Eu refiz a função que você fez, e também criei uma tabela com a rocha destruída e o minério equivalente que vem de acordo com tal rocha, para ficar mais fácil de verificar. Substitua o código por:

local STORAGE_SKILL_LEVEL = 10009
local STORAGE_SKILL_TRY = 10007

local config = {

levels = {
	{level = {0,9}, quant = {1,1}, percent = 5},
	{level = {10,19}, quant = {1,1}, percent = 10},
	{level = {20,29}, quant = {1,1}, percent = 15},
	{level = {30,39}, quant = {1,1}, percent = 20},
	{level = {40,49}, quant = {1,1}, percent = 25},
	{level = {50,59}, quant = {1,1}, percent = 30},
	{level = {60,69}, quant = {1,1}, percent = 30},
	{level = {70,79}, quant = {1,1}, percent = 35},
	{level = {80,89}, quant = {1,1}, percent = 35},
	{level = {90,99}, quant = {1,1}, percent = 40},
	{level = {100}, quant = {1,1}, percent = 50}
},

-- Rocks = Id das rochas que podem ser quebradas || -- Stone = Modelo {rock_id, rock_id} --
stones = {
	{rock = 5092, ore = 5097},
	{rock = 5093, ore = 5099},
	{rock = 5094, ore = 5100},
	{rock = 5095, ore = 5098},
}
	   
	rock_delay = 60, -- Tempo de volta da rocha (Em segundos)
	bonus_chance = 3, -- Chance (em porcentagem) de se conseguir um bonus de exp
	bonus_exp = 1 -- Bonus extra
}

------------------------------------

-- END Configurations ---

------------------------------------

function getCuttingLevel(cid)
	return getPlayerStorageValue(cid, STORAGE_SKILL_LEVEL)
end

function setPlayerCuttingLevel(cid, n)
	setPlayerStorageValue(cid, STORAGE_SKILL_LEVEL, n)
end

function addCuttingLevel(cid, n)
	setPlayerCuttingLevel(cid, getCuttingLevel(cid) + (isNumber(n) and n or 1))
	setCuttingTry(cid, 0)
end

function getCuttingInfo(cid)
	for i = 1, #config.levels do
		min = config.levels[i].level[1]; max = config.levels[i].level[2]

		if (getCuttingLevel(cid) >= min and getCuttingLevel(cid) <= max) then
			return {quantity = {min = config.levels[i].quant[1], max = config.levels[i].quant[2]}, chance = config.levels[i].percent}
		end
	end

end

-- RETORNA O MINÉRIO DE ACORDO COM A ROCHA DESTRUIDA --
function getOreByRock(rock_target)
	for i = 1, #config.stones do
		if config.stones.rock[i] == rock_target then
			return config.stones.ore[i]	
		end	
	end
end

function getCuttingTries(cid)
	return getPlayerStorageValue(cid, STORAGE_SKILL_TRY)
end

function setCuttingTry(cid, n)
	setPlayerStorageValue(cid, STORAGE_SKILL_TRY, n)
end

function addCuttingTry(cid, bonus)
	setCuttingTry(cid, getCuttingTries(cid) + 1 + (bonus and config.bonus_exp or 0))

	if (getCuttingTries(cid) >= getCuttingExpTo(getCuttingLevel(cid))) then -- Up
		doPlayerSendTextMessage(cid, 22, "You advanced from level " .. getCuttingLevel(cid) .. " to level ".. (getCuttingLevel(cid) + 1) .." in miner.")

		if ((getCuttingLevel(cid)+1) == getCuttingMaxLevel()) then
			doPlayerSendTextMessage(cid, 22, "Max level reached in miner.")
		end

		addCuttingLevel(cid)
		doSendMagicEffect(getCreaturePosition(cid), math.random(28,30))
		setCuttingTry(cid, 0)
	end
end

function getCuttingExpTo(level)
	return ((level*1.5)+((level+1)*7))
end

function getCuttingMaxLevel()
	return config.levels[#config.levels].level[#config.levels[#config.levels].level]
end

------------------------------------------------------------------------------------------------------

function onUse(cid, item, fromPosition, itemEx, toPosition)
local rock = { id = itemEx.itemid, uid = itemEx.uid, position = toPosition }
local player = { position = getCreaturePosition(cid) }

	if (getCuttingLevel(cid) < 0) then
		setPlayerCuttingLevel(cid, 0)
	end

	if (isInArray(config.rocks, rocks2, rocks3, rocks4, rock.id, rock.id2, rock.id3, rock.id4)) then
		addCuttingTry(cid)

		if (math.random(1,100) <= getCuttingInfo(cid).chance) then
			local collected = math.random(getCuttingInfo(cid).quantity.min, getCuttingInfo(cid).quantity.max)
			
			doPlayerAddItem(cid, getOreByRock(rock.id), collected)
			doSendAnimatedText(getThingPos(cid), collected .. " ore", math.random(1, 255))
			doPlayerSendTextMessage(cid, 22, "You got " .. collected .. " brass" .. (collected > 1 and "s" or "") .. " ore.")


			if (math.random(1,100) <= config.bonus_chance) then -- Bonus calc
				addCuttingTry(cid, true)
				doSendAnimatedText(player.position, "Bonus!", COLOR_ORANGE)

			end

			event_rockCut(rock)

		else

			if (math.random(0,100) <= (0-getCuttingInfo(cid).chance/0)) then
				doPlayerSendTextMessage(cid, 22, "You got nothing.")
				event_rockCut(rock)

			else
				doSendMagicEffect(rock.position, 3)
				doSendAnimatedText(rock.position, "Poff!", COLOR_GREEN)
			end
		end

	else
		doPlayerSendCancel(cid, "This can't be cut.")
	end

end

function event_rockCut(rock)
	addEvent(event_rockGrow, config.rock_delay * 1000, rock.position, rock.id)
	doTransformItem(rock.uid, 5104)
	doSendMagicEffect(rock.position, 3)
	doSendAnimatedText(rock.position, "Tack!", COLOR_GREEN)
	doItemSetAttribute(rock.uid, "name", "A trunk of " .. getItemNameById(rock.id))

end

function event_rockGrow(rockPos, old_id)
	local rock = getThingFromPos(rockPos).uid
	doTransformItem(rock, old_id)
	doItemSetAttribute(rock, "name", getItemNameById(old_id))
	doSendMagicEffect(rockPos, 3)

end

Coloquei um mensagem com efeito (animated text) falando a quantidade de ore que recebeu, caso não queira só remover a linha:

doSendAnimatedText(getThingPos(cid), collected .. " ore", math.random(1, 255))

 

Teste e veja se da algum erro.

Edited by Yan18
Link to post
Share on other sites
  • 0

vou testar irmão, super obrigado, jaja lhe dou a resposta.

@Yan18Deu esse erro irmão:

 


[Error - Action Interface]
data/actions/scripts/mining.lua:onUse
Description:
data/lib/050-function.lua:10: bad argument #1 to 'ipairs' (table expected, got nil)
stack traceback:
        [C]: in function 'ipairs'
        data/lib/050-function.lua:10: in function 'isInArray'
        data/actions/scripts/mining.lua:115: in function <data/actions/scripts/mining.lua:107>

 

Link to post
Share on other sites
  • 0
Em 16/08/2020 em 10:17, shanden4502 disse:

Super obrigado amigo, deu certo, muito obrigado mesmo.

Que bom que deu certo! De nada.

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now