local exhaust, events = {}, {}
local teleportPos = { x = 0, y = 0, z = 0 }
local exhaustionDelay = 1000
local eventDelay = 1000
function onUse(cid, item, fromPosition, target, toPosition)
if target.itemid == 2160 then
local exhaustTime = exhaust[getPlayerGUID(cid)] or 0
if exhaustTime <= os.time() then
local eventId = addEvent(function(cid)
if isPlayer(cid) then
doTeleportThing(cid, teleportPos, false)
doSendMagicEffect(teleportPos, CONST_ME_TELEPORT)
end
end, eventDelay, cid)
stopEvent(events[getPlayerGUID(cid)] or 0)
events[getPlayerGUID(cid)] = eventId
exhaust[getPlayerGUID(cid)] = os.time() +exhaustionDelay
else
doPlayerSendCancel(cid, "You are exhausted.")
end
end
return true
end
local function delayedTeleport(cid)
if isPlayer(cid) then
doTeleportThing(cid, {x = 1000, y = 1000, z = 7})
end
end
function onUse(cid, item, fromPosition, itemEx, toPosition)
if itemEx.itemid == 11111111111 then
addEvent(delayedTeleport, 3000, cid)
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You will teleport in 3 seconds.")
end
return true
end
function onUse(cid, item, fromPosition, itemEx, toPosition)
if(itemEx.itemid == XXXX) then
doSendMagicEffect(toPosition, CONST_ME_POFF)
addEvent(doTeleportThing, 1000 * 15, cid, {x = 100, y = 100, z = 7})
return true
else
doPlayerSendCancel(cid, "You need to use it on ...")
doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
end
return true
end
anytime you pass userdata using any kind of event you should check that data before doing any action with that info, thats why @Xikini uses "isPlayer" function.Code:function onUse(cid, item, fromPosition, itemEx, toPosition) if(itemEx.itemid == XXXX) then doSendMagicEffect(toPosition, CONST_ME_POFF) addEvent(doTeleportThing, 1000 * 15, cid, {x = 100, y = 100, z = 7}) return true else doPlayerSendCancel(cid, "You need to use it on ...") doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF) end return true end
Edit XXXX to id where it needs to be used
15 to the seconds
x y z to the pos
it on... to where it should be used.
"Use crowbar on fence, then teleport after xx seconds."I need to use the object for another item and then teleport the player.
<action itemid="22222222222" event="script" value="xxxxxxxxxxxxxxxxxx.lua"/>