• 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!

teleport (twice) script

Gsp

RP
Joined
Jan 3, 2008
Messages
250
Solutions
1
Reaction score
4
guys i'm trying to make a script that will teleport the player who pulls the lever (or just clicks on the item) and 30 seconds later the player will be teleported again but this time to a different location
i tried something but did not work. (im a noob by the way)

Lua:
local level = 0
local seconds = 30
local event = 0
local event2 = 0

 
local function reset(leverPos)
        local lever = getTileItemById(leverPos, 1946).uid
	doTransformItem(lever, 1945)
end
 
function onUse(cid, item, fromPosition, itemEx, toPosition)
  
          if item.itemid == 1945 and getPlayerLevel(cid) >= level then
	doTeleportThing(cid, {x = 349, y = 171, z = 13})
    event = addEvent(reset, seconds * 1000, getThingPos(item.uid))
	end
		doTeleportThing(cid, {x = 385, y = 171, z = 13})
	event2 = addEvent(reset, seconds * 1000, getThingPos(item.uid))

	doTransformItem(item.uid,item.itemid+1)
		
	elseif item.itemid == 1946 and getPlayerLevel(cid) >= level then
		stopEvent(event)
		doTransformItem(item.uid,item.itemid-1)
end
return true
end
 
Lua:
local config = {
	level = 0, --level to use the lever
	time = 30, --how long until getting tped to next location
	pos1 = {x = 349, y = 171, z = 13}, --first place
	pos2 = {x = 385, y = 171, z = 13} --second place (30seconds)
}

function onUse(cid, item, fromPosition, itemEx, toPosition)

function Event1()
	if isPlayer(cid) then
		doTeleportThing(cid, config.pos2)
	end
end

	if item.itemid == 1945 then
        if getPlayerLevel(cid) >= config.level then
		doTeleportThing(cid, config.pos1)
		event = addEvent(Event1, config.time*1000, cid)
	elseif item.itemid == 1946 and getPlayerLevel(cid) >= config.level then
		stopEvent(event)
	end
        else
                doPlayerSendCancel(cid,"You need "..config.level.." to use this lever.")
        end
	return true
end
 
Last edited:
thanks man. i tested it, it teleported me to pos1 but then i got this error

[Error - Action Interface]
data/actions/scripts/teleport.lua:eek:nUse
Description:
<luaAddEvent> Callback parameter should be a function.
 
Lua:
local config = {
	level = 0,		-- level for use the lever
	tps = {{x = 1000, y = 1000, z = 7}, {x = 1000, y = 986, z = 7}},
		-- {{position where you will be teleported}, {after event (stop event), where you will be teleported}}
	event = 0,		-- dont edit
	seconds = 30	-- time in seconds
} 

function onUse(cid, item, fromPosition, itemEx, toPosition)

	local function reset()
		doTransformItem(item.uid, item.itemid == 1946 and (item.itemid - 1) or item.itemid)
		doTeleportThing(cid, config.tps[2])
		config.event = 0
	end
	
	if getPlayerLevel(cid) < config.level then return FALSE and doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE) end
	if item.itemid == 1945 then
		doTeleportThing(cid, config.tps[1])
		config.event = addEvent(reset, config.seconds * 1000)
		doTransformItem(item.uid, item.itemid + 1)
	elseif item.itemid == 1946 then
		stopEvent(config.event)
		doTeleportThing(cid, config.tps[2])
		doTransformItem(item.uid, item.itemid - 1)
		config.event = 0
	end
	return TRUE
end

works.
 
Back
Top