Lua:
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)
break
end
end
if isStoneNearby then
break
end
end
if monsterName:lower() == "dwarf" then
chance = 1
doSendMagicEffect(position, poofEffect)
elseif monsterName:lower() == "dwarf soldier" then
chance = 5
doSendMagicEffect(position, poofEffect)
elseif monsterName:lower() == "dwarf guard" then
doSendMagicEffect(position, poofEffect)
chance = 10
end
if chance > 0 and os.time() - getGlobalStorageValue(20001) >= 300 and isStoneNearby then
local stonePos = {x = tileX, y = tileY, z = tileZ}
local roll = math.random(1, 100)
if roll <= chance then
local newItem = doCreateItem(items[math.random(#items)], 1, stonePos)
if newItem ~= nil then
setGlobalStorageValue(20001, os.time())
end
else
-- Do nothing since the roll was not successful
end
end
return true
end
declare in movements altough thinking about it now maybe creaturescript could have been easier but it would run for EVERY monster instead on selected ActionID tiles like here
