I have a script that dont allows me to use rope on another player or items or monsters (from the hole), how to add this ?
local holes = {468, 481, 483, 7932}
local holeId = {
294, 369, 370, 383, 392, 408, 409, 427, 428,
430, 462, 469, 470, 482, 484, 485, 489,
924, 3135, 3136
}
local JAM_CHANCE = 60 -- 1 / JAM_CHANCE
-- good -> broken
local jamMap = {
[7852] = 7853,
[7854] = 7855,
[7856] = 7857
}
-- zacięte
local jammed = {
[7853] = true,
[7855] = true,
[7857] = true
}
-- =========================
-- SCARABS
-- =========================
local function countScarabsAround(position, radius)
local spectators = Game.getSpectators(
position,
false,
false,
radius, radius, radius, radius
)
local count = 0
for _, creature in ipairs(spectators) do
if creature:isMonster() and creature:getName():lower() == "scarab" then
count = count + 1
end
end
return count
end
-- =========================
-- ON USE
-- =========================
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
-- =================================
-- BROKEN → BLOCK
-- =================================
if jammed[item:getId()] then
local duration = item:getAttribute(ITEM_ATTRIBUTE_DURATION) or 0
local seconds = math.max(1, math.ceil(duration / 1000))
player:say(
"The tool jammed. Please wait " .. seconds .. " seconds before using it again.",
TALKTYPE_MONSTER_SAY
)
return true
end
-- ===================================
-- BROKEN
-- ===================================
local jammedId = jamMap[item:getId()]
if jammedId and math.random(1, JAM_CHANCE) == 1 then
item:transform(jammedId)
item:decay() -- start duration items.xml
player:say(
"Your tool jammed and is now temporarily disabled!",
TALKTYPE_MONSTER_SAY
)
player:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
end
-- ======================
-- SHOVEL
-- ======================
if target and isInArray(holes, target.itemid) then
target:transform(target.itemid + 1)
target:decay()
return false
end
-- ======================
-- SCARAB(231, 9059)
-- ======================
if target and (target.itemid == 231 or target.itemid == 9059) then
local rand = math.random(200)
if target.actionid == 100 and rand <= 20 then
target:transform(489)
target:decay()
elseif rand == 1 then
local reward = player:addItem(2159, 1)
if not reward then
Game.createItem(2159, 1, toPosition)
end
elseif rand > 97 and rand < 100 then
if countScarabsAround(toPosition, 5) < 2 then
Game.createMonster("Scarab", toPosition)
toPosition:sendMagicEffect(CONST_ME_TELEPORT)
else
toPosition:sendMagicEffect(CONST_ME_POFF)
end
else
toPosition:sendMagicEffect(CONST_ME_POFF)
end
return true
end
-- ======================
-- ROPE (yourself)
-- ======================
local tile = Tile(toPosition)
if tile then
local ground = tile:getGround()
if ground and (ground:getId() == 384 or ground:getId() == 418) then
player:teleportTo(
Position(toPosition.x, toPosition.y + 1, toPosition.z - 1),
false
)
return true
end
end
-- ======================
-- PICK
-- ======================
if target and target.actionid > 0
and (target.itemid == 354 or target.itemid == 355) then
target:transform(392)
target:decay()
return true
end
-- ======================
-- MACHETE
-- ======================
if target and target.itemid == 2782 then
target:transform(2781)
target:decay()
return true
end
if target and target.itemid == 3985 then
target:transform(3984)
target:decay()
return true
end
-- ======================
-- SCYTHE
-- ======================
if target and target.itemid == 2739 then
target:transform(2737)
Game.createItem(2694, 1, toPosition)
target:decay()
return true
end
return true
end