You start here..
XML:
<action actionid="47777" event="script" value="zz_test_script.lua"/>
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
return true
end
and keep adding stuff that you want it to do.
So let's transform the rock to 5001
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
doTransformItem(item.uid, 5001)
return true
end
Now let's get the rock to transform back into 5000 after 1 second.
Because the UID of the item changes when you transform it, you have to re-find the item.
Let's make a small function to do that, since we know the itemID's and position of the object.
Lua:
local function resetStone(position, current_item, new_item)
doTransformItem(getTileItemById(position, current_item).uid, new_item)
end
function onUse(cid, item, fromPosition, itemEx, toPosition)
doTransformItem(item.uid, 5001)
addEvent(resetStone, 1000, toPosition, 5001, 5000)
return true
end
Now, let's add in a small check, to make sure someone doesn't click multiple times and have the rock transform a whole bunch.
Since we know the rock starts at itemID 5000, and will become 5000 again after we 'reset it', we can just check for that,
and send the player some information to let them know we don't want them to keep clicking on the rock.
Lua:
local function resetStone(position, current_item, new_item)
doTransformItem(getTileItemById(position, current_item).uid, new_item)
end
function onUse(cid, item, fromPosition, itemEx, toPosition)
if item.itemid ~= 5000 then
doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
doPlayerSendCancel(cid, "Sorry not possible.")
return true
end
doTransformItem(item.uid, 5001)
addEvent(resetStone, 1000, toPosition, 5001, 5000)
return true
end
Okay, so now we start start adding the actual functionality that we wanted this rock to do
Let's add in the chance to summon a creature, or gain an item.
Lua:
local function resetStone(position, current_item, new_item)
doTransformItem(getTileItemById(position, current_item).uid, new_item)
end
function onUse(cid, item, fromPosition, itemEx, toPosition)
if item.itemid ~= 5000 then
doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
doPlayerSendCancel(cid, "Sorry not possible.")
return true
end
doTransformItem(item.uid, 5001)
addEvent(resetStone, 1000, toPosition, 5001, 5000)
local rand = math.random(100)
if rand <= 50 then
doCreateMonster("rat", fromPosition)
else
doPlayerAddItem(cid, 2148, 1, true)
end
return true
end
Now, we know that a creature cannot be summoned in a pz zone, so let's restrict the usage of the item, to outside of pz zones,
and finally change the transform item timer to 5 minutes, because we are done testing and can make the timer the proper time now.
Lua:
local function resetStone(position, current_item, new_item)
doTransformItem(getTileItemById(position, current_item).uid, new_item)
end
function onUse(cid, item, fromPosition, itemEx, toPosition)
if item.itemid ~= 5000 then
doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
doPlayerSendCancel(cid, "Sorry not possible.")
return true
end
if getTilePzInfo(getThingPosition(cid)) == true then
doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
doPlayerSendCancel(cid, "Item cannot be used inside of protection zones.")
return true
end
doTransformItem(item.uid, 5001)
addEvent(resetStone, 1000 * 60 * 5, toPosition, 5001, 5000)
local rand = math.random(100)
if rand <= 50 then
doCreateMonster("rat", fromPosition)
else
doPlayerAddItem(cid, 2148, 1, true)
end
return true
end
And there we go, a completed script. (untested. xP)