Itutorial
Excellent OT User
- Joined
- Dec 23, 2014
- Messages
- 2,307
- Solutions
- 68
- Reaction score
- 981
For some reason I tell the code which item on the tile should be transformed but it still targets the top item on the tile. Is there something I am forgetting?
*NOTE: Its transforming the sign. Not the bush.
Lua:
local trees = {
[2768] = {chance = 5, level = 0, logs = 2148, respawn = 5, skillTries = 25},
[5376] = {chance = 5, level = 0, logs = 2148, respawn = 5, skillTries = 25},
[8313] = {chance = 10, level = 0, logs = 2148, respawn = 5, skillTries = 50},
[2708] = {chance = 10, level = 0, logs = 2148, respawn = 5, skillTries = 50},
[2707] = {chance = 10, level = 0, logs = 2148, respawn = 5, skillTries = 50},
[2705] = {chance = 10, level = 0, logs = 2148, respawn = 5, skillTries = 50},
[2703] = {chance = 10, level = 0, logs = 2148, respawn = 5, skillTries = 50},
[2702] = {chance = 10, level = 0, logs = 2148, respawn = 5, skillTries = 50},
[2701] = {chance = 10, level = 0, logs = 2148, respawn = 5, skillTries = 50},
[2700] = {chance = 10, level = 0, logs = 2148, respawn = 5, skillTries = 50},
[2711] = {chance = 10, level = 0, logs = 2148, respawn = 5, skillTries = 50},
[2712] = {chance = 10, level = 0, logs = 2148, respawn = 5, skillTries = 50},
[2700] = {chance = 10, level = 0, logs = 2148, respawn = 5, skillTries = 50},
[2700] = {chance = 10, level = 0, logs = 2148, respawn = 5, skillTries = 50}
}
local chopped = {8785, 8788, 8786}
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local tile = Tile(toPosition)
if not tile then return false end
local TREECHECK = nil
for i, v in pairs(trees) do
local foundTree = tile:getItemById(i)
if foundTree then
TREECHECK = tile:getItemById(i)
break
end
end
if not TREECHECK then return false end
local TREE = trees[TREECHECK.itemid]
if not TREE then return false end
local skill = player:getSkillLevel(SKILL_WOODCUTTING) + 1
if math.random(TREE.chance) <= skill then
local treeId = TREECHECK.itemid
TREECHECK:transform(chopped[math.random(#chopped)])
local stumpId = TREECHECK.itemid
player:addItem(TREE.logs, 1)
toPosition:sendMagicEffect(CONST_ME_BLOCKHIT)
player:addSkillTries(SKILL_WOODCUTTING, TREE.skillTries * 2)
addEvent(replaceTree, TREE.respawn * 1000, treeId, stumpId, toPosition)
else
toPosition:sendMagicEffect(CONST_ME_POFF)
player:addSkillTries(SKILL_WOODCUTTING, 10)
end
return true
end
function replaceTree(treeId, stumpId, position)
local target = Tile(position):getItemById(stumpId)
if not target then return true end
target:transform(treeId)
return true
end
*NOTE: Its transforming the sign. Not the bush.
Attachments
-
show.png1.3 MB · Views: 22 · VirusTotal