ROPE_SPOT = {384, 418}
OPENED_HOLE = {294, 383, 392, 469, 470, 482, 484, 485, 489}
CLOSED_HOLE = {468, 481, 483}
OPENED_TRAP = {462}
DOWN_LADDER = {369, 370, 408, 409, 427, 428, 430, 924, 3135, 3136}
JUNGLE_GRASS_TRANSFORM = {2782, 3985}
JUNGLE_GRASS_REMOVE = {1499}
POOLS = {2016, 2017, 2018, 2019, 2020, 2021, 2025, 2026, 2027, 2028, 2029, 2030}
WATER = {490, 4608, 491, 492, 493, 618, 619, 620, 621, 622, 623, 624, 625, 626, 627,
628, 629, 4609, 4610, 4611, 4612, 4613, 4614, 4615, 4616, 4617, 4618, 4619, 4620, 4621,
4622, 4623, 4624, 4625, 4664, 4665, 4666, 4820, 4821, 4822, 4823, 4824, 4825}
SWAMP = {602, 603, 604, 605, 4691, 4692, 4693, 4694, 4695, 4696, 4697, 4698, 4699, 4700, 4701, 4702, 4703, 4704, 4705, 4706, 4707, 4708, 4709, 4710, 4711, 4712, 4749, 4750, 4751, 4752, 4753, 4754, 4755, 4758}
OVEN_ON = {1786, 1788, 1790, 1792}
LADDER = {1386, 3678}
DECAYTO_ITEM_INCREMENT = {2041, 2044, 2047, 2050, 2052, 2054, 2162}
--LOCKED_DOORS = {1209, 1212, 1231, 1234, 1249, 1252, 3535, 3544, 4913, 4916, 5098, 3545, 3545, 3542}
CONSTRUCTIONS = {
[3901] = 1666, [3902] = 1670, [3903] = 1652, [3904] = 1674, [3905] = 1658,
[3906] = 3813, [3907] = 3817, [3908] = 1619, [3909] = 1615, [3910] = 2105,
[3911] = 1614, [3912] = 3806, [3913] = 3807, [3914] = 3809, [3915] = 1716,
[3916] = 1724, [3917] = 1732, [3918] = 1775, [3919] = 1774, [3920] = 1750,
[3921] = 3832, [3922] = 2095, [3923] = 2098, [3924] = 2064, [3925] = 2582,
[3926] = 2117, [3927] = 1728, [3928] = 1442, [3929] = 1446, [3930] = 1447,
[3931] = 2034, [3932] = 2604, [3933] = 2080, [3934] = 2084, [3935] = 3821,
[3936] = 3811, [3937] = 2101, [3938] = 3812, [5086] = 5046, [5087] = 5055,
[5088] = 5056,
}
FOODS = {
[2328] = {84, "Gulp."}, [2362] = {48, "Yum."}, [2666] = {180, "Munch."}, [2667] = {144, "Munch."},
[2668] = {120, "Mmmm."}, [2669] = {204, "Munch."}, [2670] = {48, "Gulp."}, [2671] = {360, "Chomp."},
[2672] = {720, "Chomp."}, [2673] = {60, "Yum."}, [2674] = {72, "Yum."}, [2675] = {156, "Yum."},
[2676] = {96, "Yum."}, [2677] = {12, "Yum."}, [2678] = {216, "Slurp."}, [2679] = {12, "Yum."},
[2680] = {24, "Yum."}, [2681] = {108, "Yum."}, [2682] = {240, "Yum."}, [2683] = {204, "Munch."},
[2684] = {60, "Crunch."}, [2685] = {72, "Munch."}, [2686] = {108, "Crunch."}, [2687] = {24, "Crunch."},
[2688] = {24, "Mmmm."}, [2689] = {120, "Crunch."}, [2690] = {72, "Crunch."}, [2691] = {96, "Crunch."},
[2695] = {72, "Gulp."}, [2696] = {108, "Smack."}, [2769] = {60, "Crunch."}, [2787] = {108, "Crunch."},
[2788] = {48, "Crunch."}, [2789] = {264, "Munch."}, [2790] = {360, "Crunch."}, [2791] = {108, "Crunch."},
[2792] = {72, "Crunch."}, [2793] = {144, "Crunch."}, [2794] = {36, "Crunch."}, [2795] = {432, "Crunch."},
[2796] = {300, "Crunch."}
}
SMALL_SAPPHIRE = 2146
SMALL_RUBY = 2147
SMALL_EMERALD = 2149
SMALL_AMETHYST = 2150
MUSICAL_INSTRUMENTS = {2070, 2071, 2072, 2073, 2074, 2075, 2076, 2077, 2078, 2079, 2080, 2081, 2082, 2083, 2084, 2085, 2332, 2364, 2367, 2368, 2370, 2371, 2372, 2373, 2374, 3951, 3953, 3957}
NORTH_BEDS = {1754, 1758, 1762, 1766, 3836, 3840}
SOUTH_BEDS = {1755, 1759, 1763, 1767, 3837, 3841}
WEST_BEDS = {1756, 1760, 1764, 1768, 3838, 3842}
EAST_BEDS = {1757, 1761, 1765, 1769, 3839, 3843}
BREAKABLE_BY_WEAPONS = {
[1619] = { remainings = 2255, chance = 15 },
[1650] = { remainings = 2253, chance = 20 },
[1651] = { remainings = 2253, chance = 20 },
[1652] = { remainings = 2253, chance = 20 },
[1653] = { remainings = 2253, chance = 20 },
[3798] = { remainings = 3959, chance = 20 },
[3799] = { remainings = 3958, chance = 20 },
}
function destroyItem(player, target, toPosition)
if type(target) ~= "userdata" or not target:isItem() then
return false
end
if target:hasAttribute(ITEM_ATTRIBUTE_UNIQUEID) or target:hasAttribute(ITEM_ATTRIBUTE_ACTIONID) then
return false
end
if toPosition.x == CONTAINER_POSITION then
player:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
return true
end
local destroyId = ItemType(target.itemid):getDestroyId()
if destroyId == 0 then
return false
end
if math.random(7) == 1 then
local item = Game.createItem(destroyId, 1, toPosition)
if item then
item:decay()
end
-- Move items outside the container
if target:isContainer() then
for i = target:getSize() - 1, 0, -1 do
local containerItem = target:getItem(i)
if containerItem then
containerItem:moveTo(toPosition)
end
end
end
target:remove(1)
end
toPosition:sendMagicEffect(CONST_ME_POFF)
return true
end
function onUseMachete(player, item, fromPosition, target, toPosition, isHotkey)
local targetId = target.itemid
if not targetId then
return true
end
if table.contains(wildGrowth, targetId) then
toPosition:sendMagicEffect(CONST_ME_POFF)
target:remove()
return true
end
local grass = jungleGrass[targetId]
if grass then
target:transform(grass)
target:decay()
player:addAchievementProgress("Nothing Can Stop Me", 100)
return true
end
return destroyItem(player, target, toPosition)
end
function onUsePick(player, item, fromPosition, target, toPosition, isHotkey)
if target.itemid == 11227 then -- shiny stone refining
local chance = math.random(1, 100)
if chance == 1 then
player:addItem(ITEM_CRYSTAL_COIN) -- 1% chance of getting crystal coin
elseif chance <= 6 then
player:addItem(ITEM_GOLD_COIN) -- 5% chance of getting gold coin
elseif chance <= 51 then
player:addItem(ITEM_PLATINUM_COIN) -- 45% chance of getting platinum coin
else
player:addItem(2145) -- 49% chance of getting small diamond
end
player:addAchievementProgress("Petrologist", 100)
target:getPosition():sendMagicEffect(CONST_ME_BLOCKHIT)
target:remove(1)
return true
end
local tile = Tile(toPosition)
if not tile then
return false
end
local ground = tile:getGround()
if not ground then
return false
end
if table.contains(groundIds, ground.itemid) and ground.actionid == actionIds.pickHole then
ground:transform(392)
ground:decay()
toPosition:sendMagicEffect(CONST_ME_POFF)
toPosition.z = toPosition.z + 1
tile:relocateTo(toPosition)
return true
end
-- Ice fishing hole
if ground.itemid == 7200 then
ground:transform(7236)
ground:decay()
toPosition:sendMagicEffect(CONST_ME_HITAREA)
return true
end
return false
end
function onUseRope(player, item, fromPosition, target, toPosition, isHotkey)
local tile = Tile(toPosition)
if not tile then
return false
end
local ground = tile:getGround()
if ground and table.contains(ropeSpots, ground:getId()) then
tile = Tile(toPosition:moveUpstairs())
if not tile then
return false
end
if tile:hasFlag(TILESTATE_PROTECTIONZONE) and player:isPzLocked() then
player:sendCancelMessage(RETURNVALUE_PLAYERISPZLOCKED)
return true
end
player:teleportTo(toPosition, false)
return true
end
if table.contains(holeId, target.itemid) then
toPosition.z = toPosition.z + 1
tile = Tile(toPosition)
if not tile then
return false
end
local thing = tile:getTopVisibleThing()
if not thing then
return true
end
--if thing:isPlayer() then
if thing:isPlayer() or thing:isMonster() then --agregado rope monster
if Tile(toPosition:moveUpstairs()):queryAdd(thing) ~= RETURNVALUE_NOERROR then
return false
end
return thing:teleportTo(toPosition, false)
elseif thing:isItem() and thing:getType():isMovable() then
return thing:moveTo(toPosition:moveUpstairs())
end
return true
end
return false
end
function onUseShovel(player, item, fromPosition, target, toPosition, isHotkey)
local tile = Tile(toPosition)
if not tile then
return false
end
local ground = tile:getGround()
if not ground then
return false
end
local groundId = ground:getId()
if table.contains(holes, groundId) then
ground:transform(groundId + 1)
ground:decay()
toPosition.z = toPosition.z + 1
tile:relocateTo(toPosition)
player:addAchievementProgress("The Undertaker", 500)
elseif target.itemid == 7932 then -- large hole
target:transform(7933)
target:decay()
player:addAchievementProgress("The Undertaker", 500)
elseif target.itemid == 20230 then -- swamp digging
if (player:getStorageValue(PlayerStorageKeys.swampDigging)) <= os.time() then
local chance = math.random(100)
if chance >= 1 and chance <= 42 then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You dug up a dead snake.")
player:addItem(3077)
elseif chance >= 43 and chance <= 79 then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You dug up a small diamond.")
player:addItem(2145)
elseif chance >= 80 then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You dug up a leech.")
player:addItem(20138)
end
player:setStorageValue(PlayerStorageKeys.swampDigging, os.time() + 7 * 24 * 60 * 60)
player:getPosition():sendMagicEffect(CONST_ME_GREEN_RINGS)
end
elseif table.contains(sandIds, groundId) then
local posSand = {
fromPos = Position(32957,32347, 7), --{x = 32957, y = 32347, z = 7}
toPos = Position(33345, 32908, 7) --{x = 33345, y = 32908, z = 7}
}
local randomValue = math.random(1, 100)
if target.actionid == actionIds.sandHole and randomValue <= 20 then
ground:transform(489)
ground:decay()
elseif randomValue <= 3 and player:getPosition():isInRange(posSand.fromPos, posSand.toPos) then
Game.createItem(2159, 1, toPosition)
player:addAchievementProgress("Gold Digger", 100)
elseif randomValue > 95 and player:getPosition():isInRange(posSand.fromPos, posSand.toPos) then
Game.createMonster("Scarab", toPosition)
--elseif randomValue == 1 then
-- Game.createItem(2159, 1, toPosition)
-- player:addAchievementProgress("Gold Digger", 100)
--elseif randomValue > 95 then
-- Game.createMonster("Scarab", toPosition)
end
toPosition:sendMagicEffect(CONST_ME_POFF)
else
return false
end
return true
end
function onUseScythe(player, item, fromPosition, target, toPosition, isHotkey)
if not table.contains({2550, 10513}, item.itemid) then
return false
end
if target.itemid == 2739 then -- wheat
target:transform(2737)
target:decay()
Game.createItem(2694, 1, toPosition) -- bunch of wheat
player:addAchievementProgress("Happy Farmer", 200)
return true
end
if target.itemid == 5465 then -- burning sugar cane
target:transform(5464)
target:decay()
Game.createItem(5467, 1, toPosition) -- bunch of sugar cane
player:addAchievementProgress("Natural Sweetener", 50)
return true
end
return destroyItem(player, target, toPosition)
end
function onUseCrowbar(player, item, fromPosition, target, toPosition, isHotkey)
if not table.contains({2416, 10515}, item.itemid) then
return false
end
return destroyItem(player, target, toPosition)
end
function onUseKitchenKnife(player, item, fromPosition, target, toPosition, isHotkey)
if not table.contains({2566, 10511, 10515}, item.itemid) then
return false
end
if table.contains(fruits, target.itemid) and player:removeItem(6278, 1) then
target:remove(1)
player:addItem(6279, 1)
player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
return true
end
return false
end