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

TFS 0.X How... does this check positions?

Xikini

I whore myself out for likes
Senator
Premium User
Joined
Nov 17, 2010
Messages
6,756
Solutions
578
Reaction score
5,305
Posted originally here, but I don't see how it works?

Specifically this portion.
Lua:
for i = 17000, 18015 do
    local pos = getThingPos(i)
    if not isPlayer(getTopCreature(pos).uid) then

I've always used position data like this; {x = 1000, y = 1000, z = 7[, stackpos = 1]}

I just can't wrap my head around how looping through i allows the script to create a position?

Can someone explain how this works?

full script.
Lua:
function onStepIn(cid, item, position, fromPosition)
    for i = 17000, 18015 do
        local pos = getThingPos(i)
        if not isPlayer(getTopCreature(pos).uid) then
            doTeleportThing(cid, pos)
            doCreatureSay(cid, 'Training time!.', TALKTYPE_ORANGE_1, false, cid)
            doSendMagicEffect(position, CONST_ME_TELEPORT)
            doSendMagicEffect(pos, CONST_ME_TELEPORT)
            return true
        end
    end
    doTeleportThing(cid, fromPosition, true)
    doCreatureSay(cid, 'All training slots are taken', TALKTYPE_ORANGE_1, false, cid)
    doSendMagicEffect(fromPosition, CONST_ME_TELEPORT)
end
 
Solution
E
and as this code explains, it does return the position:

Lua:
function getThingPos(uid)
    local thing
    if type(uid) ~= "userdata" then
        if uid >= 0x10000000 then
            thing = Creature(uid)
        else
            thing = Item(uid)
        end
    else
        thing = uid
    end

    if thing == nil then
        return false
    end

    local stackpos = 0
    local tile = thing:getTile()
    if tile then
        stackpos = tile:getThingIndex(thing)
    end

    local position = thing:getPosition()
    position.stackpos = stackpos
    return position
end
in map set uniqueid 17000 for first training slot and last training slot add uniqueid 18015 and script will check empty uniqueid pos and send player to this pos if all taken will send player msg or player will say "All training slots are taken"
 
in map set uniqueid 17000 for first training slot and last training slot add uniqueid 18015 and script will check empty uniqueid pos and send player to this pos if all taken will send player msg or player will say "All training slots are taken"
But it makes no sense..
It's literally saying 'getThingPos(17000)'
What 'thing' is it grabbing?

Lua:
getThingPos = getThingPosition -- compat
//getThingPosition(uid) -- source function

I just don't understand how it can find anything.. lmao
It just looks like broken code to me.

At best - to me - it looks like it's doing this..
Lua:
if not isPlayer(getTopCreature(pos).uid) then
if not isPlayer(getTopCreature(invalid_position).uid) then

Since it can't find a player.. it then teleports them to an invalid position..?
Lua:
doTeleportThing(cid, pos)

How does this not error?

I really don't understand how a single number can get position data.
 
Last edited:
But it makes no sense..
It's literally saying 'getThingPos(17000)'
What 'thing' is it grabbing?

Lua:
getThingPos = getThingPosition -- compat
//getThingPosition(uid) -- source function

I just don't understand how it can find anything.. lmao
It just looks like broken code to me.

At best - to me - it looks like it's doing this..
Lua:
if not isPlayer(getTopCreature(pos).uid) then
if not isPlayer(getTopCreature(invalid_position).uid) then

Since it can't find a player.. it then teleports them to an invalid position..?
Lua:
doTeleportThing(cid, pos)

How does this not error?

I really don't understand how a single number can get position data.
you can use anyone from 2 codes work for check thing uniqueid
getThingPos(uid) = getThingPosition(uid)
 
and as this code explains, it does return the position:

Lua:
function getThingPos(uid)
    local thing
    if type(uid) ~= "userdata" then
        if uid >= 0x10000000 then
            thing = Creature(uid)
        else
            thing = Item(uid)
        end
    else
        thing = uid
    end

    if thing == nil then
        return false
    end

    local stackpos = 0
    local tile = thing:getTile()
    if tile then
        stackpos = tile:getThingIndex(thing)
    end

    local position = thing:getPosition()
    position.stackpos = stackpos
    return position
end
 
Solution
IMO it is getting the position by its uniqueID ((pos).uid) and then teleporting the player there
omg, okay this makes sense.

So you'd literally have to go through every tile and add the uniqueid from 17000 to 18015 on the tiles you want to check.

That literally sounds horrendously tedious.
 
omg, okay this makes sense.

So you'd literally have to go through every tile and add the uniqueid from 17000 to 18015 on the tiles you want to check.

That literally sounds horrendously tedious.

Well not really, you just make a simple loop to check all your trailing tiles. In this case uids from 17000 to 18015 are spaces available to train. It'd be way more tedious getting the pos of all those ids.

Granted you could just make them all the same ID, but then you would still neex to make an x,y loop to loop through all the tiles in the area where the training spots are OR get the positions of all the tiles with the trailing tile into a massive array.

The latter is probably easier, but still making a loop, but all the training spots would need to be in the same rectangle region
 
Well not really, you just make a simple loop to check all your trailing tiles. In this case uids from 17000 to 18015 are spaces available to train. It'd be way more tedious getting the pos of all those ids.

Granted you could just make them all the same ID, but then you would still neex to make an x,y loop to loop through all the tiles in the area where the training spots are OR get the positions of all the tiles with the trailing tile into a massive array.

The latter is probably easier, but still making a loop, but all the training spots would need to be in the same rectangle region
If using that specific script, you need to manually set every tiles uniqueID by hand.

There are certainly better and easier ways to script this, like you inferred, but that wasn't the question. ;)
 
Back
Top