local config = {
duration = 5 * 1000,
toId = 2222,
spark = 8047,
ignore = {"demon"}
}
local function transformBack(pos, monster, health)
local spark = getTileItemById(pos, config.spark)
local item = getTileItemById(pos, config.toId)
if item.uid > 0 and spark.uid > 0 then
local monster = doCreateMonster(monster, pos)
doRemoveItem(item.uid)
doRemoveItem(spark.uid)
doCreatureAddHealth(monster, -(getCreatureMaxHealth(monster) - health))
end
end
function onUse(cid, maglvl, toPosition, itemEx, fromPosition)
if not isMonster(itemEx.uid) then
doPlayerSendCancel(cid, "Only monsters")
return true
end
local targetName = getCreatureName(itemEx.uid)
if isInArray(config.ignore, targetName:lower()) then
doPlayerSendCancel(cid, "Can't use on " .. targetName)
return true
end
local targetPos = getThingPos(itemEx.uid)
local health = getCreatureHealth(itemEx.uid)
doRemoveCreature(itemEx.uid)
doCreateItem(config.toId, 1, targetPos)
doCreateItem(config.spark, 1, targetPos)
addEvent(transformBack, config.duration, targetPos, targetName, health)
return true
end