Kod:
function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition)
local monsterName = getCreatureName(cid)
local items = {2145, 2146, 2147, 2149, 2150}
local poofEffect = CONST_ME_POFF
local chance = 0
local tileX, tileY, tileZ = position.x, position.y, position.z
local isStoneNearby = false
if not isMonster(cid) then
return false
end
-- Check if there is a stone nearby
for x = tileX - 1, tileX + 1 do
for y = tileY - 1, tileY + 1 do
local tile = getTileItemById({x = x, y = y, z = tileZ}, 1285)
if tile and tile.uid > 0 then
isStoneNearby = true
doSendMagicEffect({x = x, y = y, z = tileZ}, 4)
local stonePos = {x = x, y = y, z = tileZ} -- update stone position
if monsterName:lower() == "dwarf" then
chance = 1
doSendMagicEffect(position, poofEffect)
cid:say("<click clang>", TALKTYPE_MONSTER_SAY, false, nil, stonePos) -- send creature message on stone tile
elseif monsterName:lower() == "dwarf soldier" then
chance = 5
doSendMagicEffect(position, poofEffect)
cid:say("<click clang>", TALKTYPE_MONSTER_SAY, false, nil, stonePos) -- send creature message on stone tile
elseif monsterName:lower() == "dwarf guard" then
doSendMagicEffect(position, poofEffect)
chance = 10
cid:say("<click clang>", TALKTYPE_MONSTER_SAY, false, nil, stonePos) -- send creature message on stone tile
end
if chance > 0 and os.time() - getGlobalStorageValue(20001) >= 300 then
local roll = math.random(1, 100)
if roll <= chance then
local newItem = doCreateItem(items[math.random(#items)], 1, stonePos) -- create item on stone tile
if newItem ~= nil then
setGlobalStorageValue(20001, os.time())
end
else
-- Do nothing since the roll was not successful
end
end
break
end
end
if isStoneNearby then
break
end
end
return true
end
Zakładki