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

Can anyone add a quick line?

FenX

Advanced OT User
Joined
Jul 8, 2019
Messages
360
Solutions
1
Reaction score
159
Hi guys,
Lua:
local exitPosition = Position(32308, 32267, 7)

function onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if not player then
        return true
    end

    if player:getVocation():getBase():getId() == 1 then
        return true
    end

    player:teleportTo(exitPosition)
    player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
    return true
end
Can anyone add a line so that when player has vocation base 2, message is sent that he cannot enter and isn't allowed through.

Tried to edit this myself in multiple ways but I couldn't get it working -_-"...smh.
 
Solution
You both are sort of misunderstanding what I have in mind.

If the player has vocation baseid of 1 or 2 they are teleported to exitposition. If they have vocation baseid of 3 or 4 they are teleported to (fromPosition) so they are not allowed to pass through the teleport so a message pops up. So ONLY vocation 1 and 2 can pass (druid/sorcerer) and if they player is a knight/paladin (3/4) they can't.
Lua:
local exitPosition = Position(32308, 32267, 7)

function onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if not player then
        return true
    end

    local playerVocationId = player:getVocation():getBase():getId()
    if playerVocationId == 1 or playerVocationId == 2 then...
This is incredibly easy, you already have the line to check for a specific id. Copy that over and check for id 2, inside there teleport to fromPosition and use player:sendTextMessage(MESSAGE_INFO_DESCR, "your message") and make sure to return.
 
This is incredibly easy, you already have the line to check for a specific id. Copy that over and check for id 2, inside there teleport to fromPosition and use player:sendTextMessage(MESSAGE_INFO_DESCR, "your message") and make sure to return.
That I know but I'm not sure on which line to put this so it doesn't return errors in console >.<
 
Do you want this message to show up for both vocation 1 and 2?

Nope. It will only show up for the vocation that isn't allowed through so e.g.

vocation 1 is allowed to pass = no message
vocation 2 is not allowed to pass = with message
 
Nope. It will only show up for the vocation that isn't allowed through so e.g.

vocation 1 is allowed to pass = no message
vocation 2 is not allowed to pass = with message
Code:
local exitPosition = Position(32308, 32267, 7)

function onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if not player then
        return true
    end

    if player:getVocation():getId() == 2 then
        player:teleportTo(fromPosition, false)
        player:sendTextMessage(22, "Your vocation cant pass!")
        return true
    end

    player:teleportTo(exitPosition)
    player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
    return true
end
 
Code:
local exitPosition = Position(32308, 32267, 7)

function onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if not player then
        return true
    end

    if player:getVocation():getId() == 2 then
        player:teleportTo(fromPosition, false)
        player:sendTextMessage(22, "Your vocation cant pass!")
        return true
    end

    player:teleportTo(exitPosition)
    player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
    return true
end

That wont work for his purposes?

Try this maybe
Lua:
local exitPosition = Position(32308, 32267, 7)

function onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if not player then
        return true
    end

    if player:getVocation():getBase():getId() == 1 then
        return true
    end

    player:sendTextMessage(MESSAGE_INFO_DESCR, "message here boi")
    player:teleportTo(exitPosition)
    player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
    return true
end
 
That wont work for his purposes?

Try this maybe
Lua:
local exitPosition = Position(32308, 32267, 7)

function onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if not player then
        return true
    end

    if player:getVocation():getBase():getId() == 1 then
        return true
    end

    player:sendTextMessage(MESSAGE_INFO_DESCR, "message here boi")
    player:teleportTo(exitPosition)
    player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
    return true
end

Code:
local exitPosition = Position(32308, 32267, 7)

function onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if not player then
        return true
    end

    if player:getVocation():getId() == 2 then
        player:teleportTo(fromPosition, false)
        player:sendTextMessage(22, "Your vocation cant pass!")
        return true
    end

    player:teleportTo(exitPosition)
    player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
    return true
end

You both are sort of misunderstanding what I have in mind.

If the player has vocation baseid of 1 or 2 they are teleported to exitposition. If they have vocation baseid of 3 or 4 they are teleported to (fromPosition) so they are not allowed to pass through the teleport so a message pops up. So ONLY vocation 1 and 2 can pass (druid/sorcerer) and if they player is a knight/paladin (3/4) they can't.
 
You both are sort of misunderstanding what I have in mind.

If the player has vocation baseid of 1 or 2 they are teleported to exitposition. If they have vocation baseid of 3 or 4 they are teleported to (fromPosition) so they are not allowed to pass through the teleport so a message pops up. So ONLY vocation 1 and 2 can pass (druid/sorcerer) and if they player is a knight/paladin (3/4) they can't.
Lua:
local exitPosition = Position(32308, 32267, 7)

function onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if not player then
        return true
    end

    local playerVocationId = player:getVocation():getBase():getId()
    if playerVocationId == 1 or playerVocationId == 2 then
        player:teleportTo(exitPosition)
        player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
    else
        player:teleportTo(fromPosition)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Your message")
    end

    return true
end
I guess this is exactly what you said
 
Last edited:
Solution
Lua:
local exitPosition = Position(32308, 32267, 7)

function onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if not player then
        return true
    end

    local playerVocationId = player:getVocation():getBase():getId()
    if playerVocationId == 1 or playerVocationId == 2 then
        player:teleportTo(exitPosition)
        player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
    else
        player:teleportTo(fromPosition)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Your message")
    end

    return true
end
I guess this is exactly what you said

Perfect, thanks buddy. Just wondering why my edit didn't work I had exactly the same but
Lua:
if playerVocationId == {1, 2} then
but anyways, works perfectly thank you again.
 
Perfect, thanks buddy. Just wondering why my edit didn't work I had exactly the same but
Lua:
if playerVocationId == {1, 2} then
but anyways, works perfectly thank you again.
Because Lua (and pretty much every other language) compares by value, you're trying to compare an integer to a table which doesn't work. You can do table.contains({1, 2}, playerVocationId) instead.
 
Back
Top