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

Script teleport player TFS 0.3.7

armyman

Member
Joined
Feb 15, 2014
Messages
318
Reaction score
14
Hello, i'm looking for script that when a player is going to login in surrounded by objects or players in ur place and he got teleported to ur cityhomeTown temple.


1 Example Picture.
Imgur: The most awesome images on the Internet

In the picture If i logout now, after I do not want to connect on top of objects or in other tile near... i want go be "teleported to my hometown city temple.

i want the same with player in depot, if me logout "depot tile" and two player go there on depot tile, if a connect i get teleported to my hometown.

summing up
Be teleported if your logout location exact x,y,z is busy for players or objects that cannot walk.
 
zzzzz
I have no way to test this.

data/creaturescripts/creaturescripts.xml

XML:
<event type="login" name="teleport_to_temple_if_area_is_blocked" event="script" value="teleport_to_temple_if_area_is_blocked.lua"/>
data/creaturescripts/scripts/login.lua [somewhere near the bottom with the rest of the registered events]
LUA:
registerCreatureEvent(cid, "teleport_to_temple_if_area_is_blocked")
data/creaturescripts/scripts/teleport_to_temple_if_area_is_blocked.lua
LUA:
local function isPathable(pos)
   if getTileThingByPos(pos).itemid ~= 0 then
       local tile = getThingfromPos(pos).uid  
       if hasProperty(tile, CONST_PROP_BLOCKSOLID) then
           return false
       end
       return true
   end
   return false
end

local function isWalkable(cid, pos) -- DOES NOT WORK WITH ACCESS 3+
   local closest = getClosestFreeTile(cid, pos)
   return type(closest) == "table" and doComparePositions(closest, pos)
end

function onLogin(cid)
   local position = getThingPos(cid)
   if isPathable(position) == false or isWalkable(cid, position) == false then
       doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
   end
   return true
end
 
I did test, don't work when i connect i got this error in console now, trapped and no trapped i got this error.

Code:
[Error - CreatureScript Interface]
data/creaturescripts/scripts/teleport_to_temple_if_area_is_blocked.lua:onLogin
Description:
(LuaInterface::luaHasItemProperty) Item not found
 
try this
LUA:
local function isPathable(pos, cid)
   if getTileThingByPos(pos).itemid ~= 0 then
       for i = 1, 256 do
           local thing = getThingfromPos({x = pos.x, y = pos.y, z = pos.z, stackpos = i - 1}).itemid
           if thing > 0 then
               if hasProperty(getTileItemById(pos, thing).uid, CONST_PROP_BLOCKSOLID) then
                   return false
               end
           else
               break
           end
       end
       return true
   end
   return false
end

local function isWalkable(cid, pos) -- DOES NOT WORK WITH ACCESS 3+
   local closest = getClosestFreeTile(cid, pos)
   return type(closest) == "table" and doComparePositions(closest, pos)
end

function onLogin(cid)
   local position = getThingPos(cid)
   local xyz = {
       {x = position.x - 1, y = position.y - 1, z = position.z},
       {x = position.x - 1, y = position.y, z = position.z},
       {x = position.x - 1, y = position.y + 1, z = position.z},
       {x = position.x + 1, y = position.y - 1, z = position.z},
       {x = position.x + 1, y = position.y, z = position.z},
       {x = position.x + 1, y = position.y + 1, z = position.z},
       {x = position.x, y = position.y - 1, z = position.z},
       {x = position.x, y = position.y + 1, z = position.z}
   }
   if isPathable(position) == false or isWalkable(cid, position) == false then
       for i = 1, 8 do
           if isPathable(xyz[i]) == true or isWalkable(cid, xyz[i]) == true then
               doTeleportThing(cid, xyz[i])
               return true
           end
       end
       doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
       return true
   end
   return true
end
 
I continue with error in console when i connect without "objects" under me... but now if i have objects like tables,chest,trough,drawers under me and i logout, when i connect my character automatically move to one sqm left, and if i logout under wooden flooring tile, when i connect my character move automatically to north west
 
idk I give up.

My original script works great as long as your checking a tile without a player on it. T.T

I can't figure out how to get the UID of an item on a tile, without it finding the flippin creature standing on the tile and throwing an error, because the player isn't an item.
 
idk I give up.

My original script works great as long as your checking a tile without a player on it. T.T

I can't figure out how to get the UID of an item on a tile, without it finding the flippin creature standing on the tile and throwing an error, because the player isn't an item.

try the second script I posted.. but replace with this
Code:
local function isPathable(pos)
   if getTileThingByPos(pos).itemid ~= 0 then
       local tile = getThingfromPos(pos).uid
       if isCreature(tile) then
          return false
       end
       if hasProperty(tile, CONST_PROP_BLOCKSOLID) then
           return false
       end
       return true
   end
   return false
end
 
try the second script I posted.. but replace with this
Code:
local function isPathable(pos)
   if getTileThingByPos(pos).itemid ~= 0 then
       local tile = getThingfromPos(pos).uid
       if isCreature(tile) then
          return false
       end
       if hasProperty(tile, CONST_PROP_BLOCKSOLID) then
           return false
       end
       return true
   end
   return false
end
omg nevermind.
I didn't do this in the first place because YOU are a player and it's going to return false every time and teleport you to stupid places.
I am actually giving up now. lmfao
 
Back
Top