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

Lua Problem with scripts OTX 2 based tfs 0.3.7.

CipsoftStinks

www.relicaria.com
Joined
Oct 1, 2016
Messages
946
Solutions
3
Reaction score
138
Location
Argentina
Hello otland

well researching on this forum i found a solution to a trouble related to teleport players to temple if they're over an unwalkable item
the scripts works good the problem its that if the player its on PZ ZONE the script teleport the player to its temple even when it only should work on unwalkable items like table etc
and i don't see anything related to Pz in the code

can anyone tell me where the error is?or how to solve this via source code?
lib/funtions.lua
Code:
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
creaturescripts.lua
Code:
function isPathable(pos)
     pos.stackpos = 0
     local tile = getThingfromPos(pos).uid
     if tile > 0 then
       return not hasProperty(tile, CONST_PROP_BLOCKSOLID)
     end
     return false
end
local function isWalkable(cid, pos)
   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
creaturescripts.xml
Code:
 <event type="death" name="demonOakDeath" event="script" value="demonOakDeath.lua"/>
    <event type="attack" name="demonOakAttack" event="script" value="demonOakAttack.lua"/>
    <event type="login" name="TpPlayers" event="script" value="tpplayers.lua"/>

login.lua
Code:
 registerCreatureEvent(cid, "KillingInTheNameOf")
    registerCreatureEvent(cid, "TpPlayers")
tpplayers.lua
Code:
function isPathable(pos)
     pos.stackpos = 0
     local tile = getThingfromPos(pos).uid
     if tile > 0 then
       return not hasProperty(tile, CONST_PROP_BLOCKSOLID)
     end
     return false
end
local function isWalkable(cid, pos)
   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

please help
 
if isPathable(position) == false or isWalkable(cid, position) == false then
doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
[/code]

Might be something related to isPathable, if someone is PZ locked, they cannot walk into PZ, which means it's not pathable... right?
 
i don't know
but it doesn't matter if the player its pzlocked or not the problems happens when the players is standing over pztiles (he's teleported even when it shouldn't happen)
the script should do the action only with unwalkable paths
 
I don't use OTX 2, but I do use 0.3.7

I rewrote that function awhile ago because it was buggy.

Try using mine.
(Main difference is using functions that require a 'cid'.)
LUA:
function isPathable(cid, pos, ignoreCreatures)
    pos.stackpos = 0
    if getTileThingByPos(pos).uid ~= 0 then
        pos.stackpos = 253
        if ignoreCreatures == true then
            if doTileQueryAdd(cid, pos, 4) == RETURNVALUE_NOERROR then
                return true
            end
        else
            if getTopCreature(pos).uid == 0 and doTileQueryAdd(cid, pos) == RETURNVALUE_NOERROR then
                return true
            end
        end
    end
    return false
end
LUA:
isPathable(cid, {x = 1000, y = 1000, z = 7}, false)
isPathable(cid, getThingPosition(cid), true)
 
Thanks you a lot
shouldn't i edit ispathable cid last code? becuase some items are moveable
could you tell me if i should edit something in your script or i just need to copy paste?
anyway thanks for your time and code xikini im gonna test it right now
*: muack
 
i have errors man i got it registred at login.lua
[Error - Event::checkScript] Event onLogin not found (data/creaturescripts/scripts/tpplayers.lua)
 
ah yes i did xdd
but now i got these errors
Code:
data/creaturescripts/scripts/tpplayers.lua:2: attempt to index local 'pos' (a nil value)
stack traceback:
        data/creaturescripts/scripts/tpplayers.lua:2: in function 'isPathable'
        data/creaturescripts/scripts/tpplayers.lua:23: in function <data/creaturescripts/scripts/tpplayers.lua:21>
GM Pasturry has logged out.

Code:
function isPathable(cid, pos, ignoreCreatures)
    pos.stackpos = 0
    if getTileThingByPos(pos).uid ~= 0 then
        pos.stackpos = 253
        if ignoreCreatures == true then
            if doTileQueryAdd(cid, pos, 4) == RETURNVALUE_NOERROR then
                return true
            end
        else
            if getTopCreature(pos).uid == 0 and doTileQueryAdd(cid, pos) == RETURNVALUE_NOERROR then
                return true
            end
        end
    end
    return false
end
local function isWalkable(cid, pos)
   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
 
ah yes i did xdd
but now i got these errors
Code:
data/creaturescripts/scripts/tpplayers.lua:2: attempt to index local 'pos' (a nil value)
stack traceback:
        data/creaturescripts/scripts/tpplayers.lua:2: in function 'isPathable'
        data/creaturescripts/scripts/tpplayers.lua:23: in function <data/creaturescripts/scripts/tpplayers.lua:21>
GM Pasturry has logged out.

Code:
function isPathable(cid, pos, ignoreCreatures)
    pos.stackpos = 0
    if getTileThingByPos(pos).uid ~= 0 then
        pos.stackpos = 253
        if ignoreCreatures == true then
            if doTileQueryAdd(cid, pos, 4) == RETURNVALUE_NOERROR then
                return true
            end
        else
            if getTopCreature(pos).uid == 0 and doTileQueryAdd(cid, pos) == RETURNVALUE_NOERROR then
                return true
            end
        end
    end
    return false
end
local function isWalkable(cid, pos)
   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 don't use OTX 2, but I do use 0.3.7

I rewrote that function awhile ago because it was buggy.

Try using mine.
(Main difference is using functions that require a 'cid'.)
LUA:
isPathable(cid, {x = 1000, y = 1000, z = 7}, false)
isPathable(cid, getThingPosition(cid), true)
change ur isPathable(position) to isPathable(cid, position)
 
Back
Top