local cooldown = 120 -- in seconds
local storage = 7374
local condition = createConditionObject(CONDITION_INFIGHT)
setConditionParam(condition, CONDITION_PARAM_TICKS, (10 * 1000))
local function removePortal(pos)
if getTileItemById(pos,1387).uid > 0 then
doRemoveItem(getTileItemById(pos,1387).uid)
doSendMagicEffect(pos, CONST_ME_POFF)
end
return true
end
local function isWalkable(cid, pos)
pos.stackpos = 253
if (doTileQueryAdd(cid, pos) == 1 and getTilePzInfo(pos) == FALSE and isCreature(getThingFromPos(pos).uid) == FALSE) then
return TRUE
end
return FALSE
end
function onUse(cid, item, fromPosition, itemEx, toPosition)
local portalPos = {x=92, y=114, z=7}
local p = getCreaturePosition(cid)
if(getPlayerStorageValue(cid, storage) > os.time()) then
return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Cool Down --> " .. os.date("%M : %S", (getPlayerStorageValue(cid,storage)-os.time()) ) .."") and doSendMagicEffect(p, CONST_ME_POFF) and doCreatureAddHealth(cid,-500)
end
if (toPosition.x == p.x and toPosition.y == p.y and toPosition.z == p.z) then
return doPlayerSendCancel(cid,"You cant create portal in your place")
end
if itemEx.itemid == 1387 then
return doPlayerSendCancel(cid,"You cant create on another portal.")
end
if (toPosition.x == portalPos.x and toPosition.y == portalPos.y and toPosition.z == portalPos.z) then
return doPlayerSendCancel(cid,"You cannot create a portal in the same place you are going to!")
end
if getThingFromPos({x=toPosition.x,y=toPosition.y,z=toPosition.z,stackpos = 255},false).uid > 0 or not isWalkable(cid, toPosition) then
return doPlayerSendCancel(cid,"You cannot create a portal here!")
end
doCreateTeleport(1387,portalPos,toPosition)
doSendMagicEffect(toPosition, CONST_ME_ENERGYAREA)
doSendDistanceShoot(p, toPosition, CONST_ANI_ENERGY)
doSendMagicEffect(p, CONST_ME_MAGIC_GREEN)
addEvent(removePortal, 5 * 1000, toPosition)
doTargetCombatCondition(0, cid, condition, CONST_ME_NONE)
if getPlayerGroupId(cid) < 3 then --make the cool down to players
setPlayerStorageValue(cid, storage, os.time() + cooldown)
end
return true
end