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

Requesting Simple Script

Make all portal to enter trainer have actionid 2000 then use this.

MOVEMENT
Code:
local teleports = {1387, 1397}


function onStepIn(creature, item, position, fromPosition)
    if not isPlayer(creature) or not isInArray(teleports, item.itemid) then return false end
        fromPosition.y = fromPosition.y + 3
        pos = fromPosition
      
        tile = Tile(pos)
        thing = tile:getTopCreature()
      
        if isPlayer(thing) then    return player:sendCancelMessage("This training spot is taken.") end
      
        creature:teleportTo(pos)
        creature:sendTextMessage(MESSAGE_EVENT_ORANGE, "You have entered the trainers.")
return true
end

Movements.xml
Code:
<movevent event="StepIn" actionid="2000" script="trainers.lua" />

Make sure in map you set teleport to enter portal actionid 2000 all of them!
 
Last edited:
Since fromPosition is already a table you can just do this
Code:
fromPosition.y = fromPosition.y + 3

Either use fromPosition directly or store it in pos.
Code:
local pos = fromPosition

If you unpack pos/fromPosition or access anyone of its properties.. e g. x/y/z and even stackpos, you will see that this line of code is not needed
Code:
local pos = {x = fromPosition.x, y = fromPosition.y + 3, z = fromPosition.z}

Basic example
Code:
local f = {x = 1, y = 1, z = 1}
f.y = f.y + 3
local g = f
print(g.x, g.y, g.z)
-- output
1    4    1
 
Last edited:
The only thing is I get confused on whether Tile() accepts this:
Code:
{x = 1, y = 1, z = 1}
or if it accepts
Code:
Position(x = 1, y = 1, z = 7}

I would rather be safe then sorry and just give him a script I know will work.
 
Always check the sources, even if you don't know the language, the luascript.cpp file will give you a general idea of how something works.
Code:
// Position
int LuaScriptInterface::luaPositionCreate(lua_State* L)
{
    // Position([x = 0[, y = 0[, z = 0[, stackpos = 0]]]])
    // Position([position])
    if (lua_gettop(L) <= 1) {
        pushPosition(L, Position());
        return 1;
    }

    int32_t stackpos;
    if (isTable(L, 2)) {
        const Position& position = getPosition(L, 2, stackpos);
        pushPosition(L, position, stackpos);
    } else {
        uint16_t x = getNumber<uint16_t>(L, 2, 0);
        uint16_t y = getNumber<uint16_t>(L, 3, 0);
        uint8_t z = getNumber<uint8_t>(L, 4, 0);
        stackpos = getNumber<int32_t>(L, 5, 0);

        pushPosition(L, Position(x, y, z), stackpos);
    }
    return 1;
}
Anytime you see a [ in front of a parameter, this means this parameter is optional normally from the 1st [ on.
Code:
    // Position([x = 0[, y = 0[, z = 0[, stackpos = 0]]]])
    // Position([position])
So what does this tell us, it tells us we should be able to use both a table of numbers and numbers, the L, 2 - L, 5 are the arguments, x to stackpos, however it doesn't seem to reference it by index but rather by value where as pushPosition does.

If we look at the call to pushPosition, its definition, it too passes an array and a variable and generates fields or properties for the instance of the metatable Position.
Code:
void LuaScriptInterface::pushPosition(lua_State* L, const Position& position, int32_t stackpos/* = 0*/)
{
    lua_createtable(L, 0, 4);

    setField(L, "x", position.x);
    setField(L, "y", position.y);
    setField(L, "z", position.z);
    setField(L, "stackpos", stackpos);

    setMetatable(L, -1, "Position");
}

I am just speculating here as C++ is not strong point :p
 
I'm getting an interesting error when using the first script. It works fine up until this point. If there is a player inside the room and a person outside the room stands directly on the teleporter, the player isn't teleported (which is how it should work), but when the player inside the room exits and the player that was standing on the teleporter steps off and then back on the tp, he is teleported to this location: https://gyazo.com/962e7f6565c98c78726a4558a87fe4dd

Also, the text that is supposed to say "This training spot is taken" does not appear until the error comes up.
 
I'm getting an interesting error when using the first script. It works fine up until this point. If there is a player inside the room and a person outside the room stands directly on the teleporter, the player isn't teleported (which is how it should work), but when the player inside the room exits and the player that was standing on the teleporter steps off and then back on the tp, he is teleported to this location: https://gyazo.com/962e7f6565c98c78726a4558a87fe4dd

Also, the text that is supposed to say "This training spot is taken" does not appear until the error comes up.
The script should use toPosition not fromPosition
 
Back
Top