• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua Transform Monster to Item

hasbro

Member
Joined
Feb 15, 2009
Messages
287
Reaction score
6
How i Can transform one monster in item, and after i back the item to a monster? I can do with create a function and removeCreature and after createitem , and make the inverse? Anyone can help me?
 
So if i use an rune on an demon etc, he transform to an Dragon scale mail(etc) ?? and after 1 min he transform back to an demon
 
XML:
	<action itemid="xxxx" event="script" value="scriptName.lua"/>

Lua:
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
 
Thanks Summ.

- - - Updated - - -

Summ, i make some changes and can you help me after i use item in mosnter he change the place..
Lua:
local config = {
    duration = 5 * 1000,
    toId = 15468,
 
    ignore = {"hive pore"}
}
 
local function transformBack(pos, monster, health)
    local spark = getTileItemById(pos, config.spark)
    local item = getTileItemById(pos, config.toId)
 
    if item.uid > 0 then
        local monster = doCreateMonster(monster, pos)
        doRemoveItem(item.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
	if getPlayerStorageValue(cid,10054) == 1 then
 
    local targetPos = getThingPos(itemEx.uid)
    local health = getCreatureHealth(itemEx.uid)
    doRemoveCreature(itemEx.uid)
	setPlayerStorageValue(cid,getPlayerStorageValue(cid,10055) +1)
    doCreateItem(config.toId, 1, targetPos)
 
    addEvent(transformBack, config.duration, targetPos, targetName, health)
	return true
end
end
end
 
Back
Top