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

MoveEvent Teleport to Random Position

megachock

Member
Joined
Mar 12, 2009
Messages
115
Reaction score
7
Well, i have made this script..
This teleport randomly to different positions.

In movements/movements.xml

Lua:
<movevent type="StepIn" actionid="XXXX" event="script" value="RandomTP.lua"/>

XXXX will be the actionid of the teleport in map.

In movements/scripts/
Copy any script and rename it RandomTP.lua
and paste it inside:

Lua:
local t = {
	{x = 1954, y = 879, z = 10},
	{x = 1909, y = 893, z = 10},
	{x = 1859, y = 907, z = 10}
}
function onStepIn(cid, item, position, fromPosition)
	local v = t[math.random(#t)]
	doSendMagicEffect(position, CONST_ME_TELEPORT)
	doTeleportThing(cid, v)
	doSendMagicEffect(v, CONST_ME_TELEPORT)
end

Inside the table "t" you must put the positions or you can edited what i wrote.
 
Lua:
local from = {x=500,y=500}
local to = {x=600,y=600}
local setZ = 7

function onStepIn(cid, item, position, fromPosition)
	local setX = math.random(from.x,to.x)
	local setY = math.random(from.y,to.y)
	
	doSendMagicEffect(position, CONST_ME_TELEPORT)
	doTeleportThing(cid, {x = setX,y = setY,z = setZ})
	return true
end

Also you can set area where player will be teleported.
 
Lua:
local from = {x=500,y=500}
local to = {x=600,y=600}
local setZ = 7

function onStepIn(cid, item, position, fromPosition)
	local setX = math.random(from.x,to.x)
	local setY = math.random(from.y,to.y)
	
	doSendMagicEffect(position, CONST_ME_TELEPORT)
	doTeleportThing(cid, {x = setX,y = setY,z = setZ})
	return true
end

Also you can set area where player will be teleported.

Just make sure you can "walk" on these tiles and dont let the player port into stones, walls or something where he can't move.
 
Lua:
function onStepIn(cid, item, position, fromPosition)
	local from, to, setX, setY, setZ, Pos = { x = 500, y = 500 }, { x = 600, y = 600 }, math.random(from.x,to.x), math.random(from.y,to.y), 7, {x = setX, y = setY, z = setZ}
	
	function isWalkable(cid, pos)
	pos.stackpos = 0
	if getTileThingByPos(pos).uid ~= 0 then
		local n = getTileInfo(pos)
		if n.house == false and getTopCreature(pos).uid == 0 and doTileQueryAdd(cid, pos) == RETURNVALUE_NOERROR then
			return true
		end
	end	end
	if isWalkable(cid, Pos) then
		doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
		doTeleportThing(cid, Pos)
	else
		return doTeleportThing(cid, fromPosition, true) and doPlayerSendCancel(cid, "Try again.")
	end
	return true
end
 
Lua:
function onStepIn(cid, item, position, fromPosition)
    local from, to, setX, setY, setZ, Pos = { x = 500, y = 500 }, { x = 600, y = 600 }, math.random(from.x,to.x), math.random(from.y,to.y), 7, {x = setX, y = setY, z = setZ}
   
    function isWalkable(cid, pos)
    pos.stackpos = 0
    if getTileThingByPos(pos).uid ~= 0 then
        local n = getTileInfo(pos)
        if n.house == false and getTopCreature(pos).uid == 0 and doTileQueryAdd(cid, pos) == RETURNVALUE_NOERROR then
            return true
        end
    end    end
    if isWalkable(cid, Pos) then
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
        doTeleportThing(cid, Pos)
    else
        return doTeleportThing(cid, fromPosition, true) and doPlayerSendCancel(cid, "Try again.")
    end
    return true
end


Sorry for updating, but i have a question, your script random teleports you in the positions inside Pos = { x = 500, y = 500 }, { x = 600, y = 600 } right?
 
Back
Top