• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Solved Create tp with item, based on player pos

Caduceus

Unknown Member
Joined
May 10, 2010
Messages
321
Solutions
2
Reaction score
24
I am trying to create a teleport with an item, example with a rune. that will teleport a player to the set pos. However I keep getting this error: data/actions/scripts/portal.lua:6: 'end' expected (to close 'function' at line 3) near 'doPlayerSendCancel' Please do not bash my scripting or tabbing, I know it is sub par.

LUA:
local pos = {x = 1013, y = 971, z = 4} 

function onUse(cid, item, fromPosition, itemEx, toPosition)
return
getCreatureCondition(cid, CONDITION_INFIGHT)
	doPlayerSendCancel(cid, "Sorry, you are in a fight.")
	else
      doCreateTeleport(5023, pos, getPlayerPosition(cid))
      end
        else
      doPlayerSendCancel(cid, "You cannot use this item.")
        end
    return TRUE
end
 
Last edited:
Sorry, bad your function was very bad and with tons of syntax errors :P
LUA:
local pos = {x = 1013, y = 971, z = 4} 
 
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if getCreatureCondition(cid, CONDITION_INFIGHT) == TRUE then
	doPlayerSendCancel(cid, "Sorry, you are in a fight.")
    else
	doCreateTeleport(5023, pos, getPlayerPosition(cid))
    end
    return TRUE
end
 
Sorry, bad your function was very bad and with tons of syntax errors :P
LUA:
local pos = {x = 1013, y = 971, z = 4} 
 
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if getCreatureCondition(cid, CONDITION_INFIGHT) == TRUE then
	doPlayerSendCancel(cid, "Sorry, you are in a fight.")
    else
	doCreateTeleport(5023, pos, getPlayerPosition(cid))
    end
    return TRUE
end

Thank you, told you my scripting was sub par, at best. Script worked, but how can i set a duration on the teleport? So that it disappears after a 1 minute?
 
Last edited:
Here you are :)
LUA:
local config =
{
	pos = {x = 1013, y = 971, z = 4},
	delay = 1 -- Delay for removing teleporter in seconds
}

local function removeTeleport(item)
	doRemoveItem(item.uid)
	return TRUE
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if getCreatureCondition(cid, CONDITION_INFIGHT) == TRUE then
		doPlayerSendCancel(cid, "Sorry, you are in a fight.")
    else
		doCreateTeleport(5023, config.pos, getPlayerPosition(cid))
		addEvent(removeTeleport, config.delay*1000, getThingfromPos(config.pos))
    end
    return TRUE
end
 
Code:
[27/05/2013 07:48:50] Lua Script Error: [Action Interface] 
[27/05/2013 07:48:50] in a timer event called from: 
[27/05/2013 07:48:50] data/actions/scripts/portal.lua:onUse
[27/05/2013 07:48:50] LuaScriptInterface::luaDoRemoveItem(). Item not found
[27/05/2013 07:48:50] stack traceback:
[27/05/2013 07:48:50] 	[C]: in function 'doRemoveItem'
[27/05/2013 07:48:50] 	data/actions/scripts/portal.lua:8: in function <data/actions/scripts/portal.lua:7>

I can remove portal with a movement,but need a way to use with crosshair. Not playerpos
 
Last edited:
try this

LUA:
local cfg = {
	time = 15, -- Time the teleport is open.
	exhausted = 60, -- Time you are exhausted.
	storage = 1337, -- Storage used for "exhaust."
	to = { x = 100, y = 100, z = 7 } -- Where the teleport takes you.
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
	if(getPlayerStorageValue(cid, cfg.storage) > os.time()) then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "You must wait another " .. getPlayerStorageValue(cid, cfg.storage) - os.time() .. ' second' .. ((getPlayerStorageValue(cid, cfg.storage) - os.time()) == 1 and "" or "s") .. " to create another teleport.")
	elseif(getTilePzInfo(getCreaturePosition(cid)) == true) then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "You cannot create a teleport in a protection zone.")
	elseif(getCreatureCondition(cid, CONDITION_INFIGHT) == true) then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "You may not create a teleport while fighting.")
	elseif(hasProperty(getThingFromPos(toPosition).uid, CONST_PROP_BLOCKSOLID) == true) then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "You cannot create a teleport here.")
	else
		local function deleteTeleport()
			local teleport = getTileItemById(toPosition, 1387).uid
			if(teleport > 0) then
				doRemoveItem(teleport)
				doSendMagicEffect(toPosition, CONST_ME_POFF)
				doSendAnimatedText(toPosition, "Closed", TEXTCOLOR_RED)
			end
			return true
		end
		for x = 1, cfg.time do
		local n = cfg.time - x
			addEvent(doSendAnimatedText, x * 1000, toPosition, n > 0 and tostring(n), TEXTCOLOR_WHITE)
		end
		doCreateTeleport(1387, cfg.to, toPosition)
		doSendMagicEffect(toPosition, CONST_ME_ENERGYAREA)
		addEvent(deleteTeleport, cfg.time * 1000)
		setPlayerStorageValue(cid, cfg.storage, os.time() + cfg.exhausted)
	end
	return true
end
 
LUA:
local config =
{
	pos = {x = 1013, y = 971, z = 4},
	delay = 3 -- Delay for removing teleporter in seconds
}
 

local function removeTeleport(position)
	local teleport = getTileItemById(position,5023).uid
	if teleport > 0 then
		doRemoveItem(teleport,1)
		doSendMagicEffect(position, CONST_ME_POFF)
	end
	return true
end 
 
function onUse(cid, item, fromPosition, itemEx, toPosition)
    	if getCreatureCondition(cid, CONDITION_INFIGHT) == TRUE then
		doPlayerSendCancel(cid, "Sorry, you are in a fight.")
    	else
		doCreateTeleport(5023, config.pos, toPosition)
		addEvent(removeTeleport, config.delay*1000, toPosition)
    	end
    	return true
end
 
Back
Top