Can anyone add a quick line?

FenX

Active Member
Joined
Jul 8, 2019
Messages
107
Best answers
0
Reaction score
27
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.
 

Delusion

Divine Intellect
Support Team
Joined
Feb 14, 2015
Messages
5,046
Best answers
471
Reaction score
2,677
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.
 
OP
F

FenX

Active Member
Joined
Jul 8, 2019
Messages
107
Best answers
0
Reaction score
27
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 >.<
 

Tobben321

Excellent OT User
Joined
Mar 1, 2009
Messages
142
Best answers
10
Reaction score
54
Location
Norway
Do you want this message to show up for both vocation 1 and 2?
 
OP
F

FenX

Active Member
Joined
Jul 8, 2019
Messages
107
Best answers
0
Reaction score
27
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
 

roriscrave

Intermediate OT User
Joined
Dec 7, 2011
Messages
700
Best answers
17
Reaction score
82
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
 

Tobben321

Excellent OT User
Joined
Mar 1, 2009
Messages
142
Best answers
10
Reaction score
54
Location
Norway
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
 
OP
F

FenX

Active Member
Joined
Jul 8, 2019
Messages
107
Best answers
0
Reaction score
27
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.
 

leleco95

Excellent OT User
Joined
May 6, 2009
Messages
23
Best answers
4
Reaction score
24
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:
OP
F

FenX

Active Member
Joined
Jul 8, 2019
Messages
107
Best answers
0
Reaction score
27
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.
 

Delusion

Divine Intellect
Support Team
Joined
Feb 14, 2015
Messages
5,046
Best answers
471
Reaction score
2,677
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.
 
OP
F

FenX

Active Member
Joined
Jul 8, 2019
Messages
107
Best answers
0
Reaction score
27
Ahhh noted, ty.
 
Top