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

Please Help! >Doors for vocations!< (example: Doors only knights can enter) tfs 1.4.2

SparvenBara

Member
Joined
Jul 28, 2023
Messages
36
Reaction score
16
Location
Sweden
Hello

Can someone help me explain how i can make a door available to enter as each vocation.

i have an area on my ot where there are 4 different buildings in each corner of the area

each building is suppose to be for each vocation. 1 for EK, 1 for RP, 1 for MS and 1 for ED.

How can i make the door at the EK building only be openable by EKs and blocker for MS, RP and EDs?

thanks

and yes, im using TFS 1.4.2. and i could use a full explaination cuz im a rookie at everything that has to do with scripts / coding.
 
Last edited:
Solution
i dont seem to get it to work.. View attachment 77787

i write the ID for druids, but this happens

View attachment 77788
Slight mistake.

Try this.

Lua:
local vocations = {
----[actionId] = {vocations}
    [45001] = {1, 5}, -- insert vocations that you want to be able to pass through
    [45002] = {2, 6},
    [45003] = {3, 7},
    [45004] = {4, 8},
    [45005] = {1, 2, 5, 6} -- example of a 'mages only' (sorc & druid)
}

local vocationCheckTile = MoveEvent()
vocationCheckTile:type("stepin")

function vocationCheckTile.onStepIn(creature, item, position, fromPosition)
    local player = Player(creature:getId())
    if not player then
        position:sendMagicEffect(CONST_ME_MAGIC_RED)
        creature:teleportTo(fromPosition, false)
        return true
    end...
I tested it and it's working fine. You just need to edit the ActionID by the RME on the port. Then add the script in the action. Follow here.

DoorEK.lua
Lua:
function onUse(cid, item, frompos, item2, topos)
    local vocation = getPlayerVocation(cid)
  
    -- Check if the player's vocation is Elite knight (value 8)
    if vocation == 8 then --EK
        pos = getPlayerPosition(cid)
      
        if pos.x == topos.x then
            if pos.y < topos.y then
                pos.y = topos.y + 1
            else
                pos.y = topos.y - 1
            end
        elseif pos.y == topos.y then
            if pos.x < topos.x then
                pos.x = topos.x + 1
            else
                pos.x = topos.x - 1
            end
        else
            doPlayerSendTextMessage(cid, 22, 'Stand in front of the door.')
            return 1
        end
      
        doTeleportThing(cid, pos)
        doSendMagicEffect(topos, 12)
    else
        doPlayerSendTextMessage(cid, 22, 'Only Elder Druids can pass through this door..')
    end
  
    return 1
end

XML
XML:
<action actionid="4549" script="DoorEK.lua"/>



If you want the complete vocations for the door, they are here.

Lua:
function onUse(cid, item, frompos, item2, topos)
    local vocation = getPlayerVocation(cid)
    
    local allowedVocations = {
        [4] = true,  -- Elder Druid
        [8] = true,  -- Master Sorcerer
        [3] = true,  -- Elite Knight
        [7] = true,  -- Royal Paladin
    }
    
    if allowedVocations[vocation] then
        pos = getPlayerPosition(cid)
        
        if pos.x == topos.x then
            if pos.y < topos.y then
                pos.y = topos.y + 1
            else
                pos.y = topos.y - 1
            end
        elseif pos.y == topos.y then
            if pos.x < topos.x then
                pos.x = topos.x + 1
            else
                pos.x = topos.x - 1
            end
        else
            doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, 'Stand in front of the door.')
            return 1
        end
        
        doTeleportThing(cid, pos)
        doSendMagicEffect(topos, 12)
    else
        doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, 'Only certain vocations can pass through this door.')
    end
    
    return 1
end
 
Last edited:
I tested it and it's working fine. You just need to edit the ActionID by the RME on the port. Then add the script in the action. Follow here.

DoorEK.lua
Lua:
function onUse(cid, item, frompos, item2, topos)
    local vocation = getPlayerVocation(cid)
 
    -- Check if the player's vocation is Elite knight (value 8)
    if vocation == 8 then --EK
        pos = getPlayerPosition(cid)
     
        if pos.x == topos.x then
            if pos.y < topos.y then
                pos.y = topos.y + 1
            else
                pos.y = topos.y - 1
            end
        elseif pos.y == topos.y then
            if pos.x < topos.x then
                pos.x = topos.x + 1
            else
                pos.x = topos.x - 1
            end
        else
            doPlayerSendTextMessage(cid, 22, 'Stand in front of the door.')
            return 1
        end
     
        doTeleportThing(cid, pos)
        doSendMagicEffect(topos, 12)
    else
        doPlayerSendTextMessage(cid, 22, 'Only Elder Druids can pass through this door..')
    end
 
    return 1
end

XML
XML:
<action actionid="4549" script="DoorEK.lua"/>



If you want the complete vocations for the door, they are here.

Lua:
function onUse(cid, item, frompos, item2, topos)
    local vocation = getPlayerVocation(cid)
   
    local allowedVocations = {
        [4] = true,  -- Elder Druid
        [8] = true,  -- Master Sorcerer
        [3] = true,  -- Elite Knight
        [7] = true,  -- Royal Paladin
    }
   
    if allowedVocations[vocation] then
        pos = getPlayerPosition(cid)
       
        if pos.x == topos.x then
            if pos.y < topos.y then
                pos.y = topos.y + 1
            else
                pos.y = topos.y - 1
            end
        elseif pos.y == topos.y then
            if pos.x < topos.x then
                pos.x = topos.x + 1
            else
                pos.x = topos.x - 1
            end
        else
            doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, 'Stand in front of the door.')
            return 1
        end
       
        doTeleportThing(cid, pos)
        doSendMagicEffect(topos, 12)
    else
        doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, 'Only certain vocations can pass through this door.')
    end
   
    return 1
end

Thanks Alot! i really appriciate it!

Where do i put the doorEK.lua file and in what actionID-file do i put this? " <action actionid="4549" script="DoorEK.lua"/> "

Sorry, as i said, totally rookie at this..
 
Thanks Alot! i really appriciate it!

Where do i put the doorEK.lua file and in what actionID-file do i put this? " <action actionid="4549" script="DoorEK.lua"/> "

Sorry, as i said, totally rookie at this..
Sorry, I forgot to include the information. Yes, it's in data/actions.
 
Gonna jump in and say that adding it to actions isn't a good idea for this one.

Doors is a fairly complex system, and I don't think an action script by itself will cover all cases.

I'd suggest using an actionId on the tile below a door.

data/scripts
Lua:
local vocations = {
----[actionId] = {vocations}
    [45001] = {1, 5}, -- insert vocations that you want to be able to pass through
    [45002] = {2, 6},
    [45003] = {3, 7},
    [45004] = {4, 8},
    [45005] = {1, 2, 5, 6} -- example of a 'mages only' (sorc & druid)
}

local vocationCheckTile = MoveEvent()
vocationCheckTile:type("stepin")

function vocationCheckTile.onStepIn(creature, item, position, fromPosition)
    local player = Player(creature:getId())
    if not player then
        position:sendMagicEffect(CONST_ME_MAGIC_RED)
        creature:teleportTo(fromPosition, false)
        return true
    end
  
    local vocations = vocations[item:getActionId()]
    local vocationId = player:getVocation():getId()
  
    if not table.contains(vocations, vocationId) then
        position:sendMagicEffect(CONST_ME_MAGIC_RED)
        player:teleportTo(fromPosition, false)
        return true
    end

    position:sendMagicEffect(CONST_ME_MAGIC_BLUE)
    return true
end

for _, actionId in pairs(vocations) do
    vocationCheckTile:aid(actionId)
end
vocationCheckTile:register()
 
Gonna jump in and say that adding it to actions isn't a good idea for this one.

Doors is a fairly complex system, and I don't think an action script by itself will cover all cases.

I'd suggest using an actionId on the tile below a door.

data/scripts
Lua:
local vocations = {
----[actionId] = {vocations}
    [45001] = {1, 5}, -- insert vocations that you want to be able to pass through
    [45002] = {2, 6},
    [45003] = {3, 7},
    [45004] = {4, 8},
    [45005] = {1, 2, 5, 6} -- example of a 'mages only' (sorc & druid)
}

local vocationCheckTile = MoveEvent()
vocationCheckTile:type("stepin")

function vocationCheckTile.onStepIn(creature, item, position, fromPosition)
    local player = Player(creature:getId())
    if not player then
        position:sendMagicEffect(CONST_ME_MAGIC_RED)
        creature:teleportTo(fromPosition, false)
        return true
    end
 
    local vocations = vocations[item:getActionId()]
    local vocationId = player:getVocation():getId()
 
    if not table.contains(vocations, vocationId) then
        position:sendMagicEffect(CONST_ME_MAGIC_RED)
        player:teleportTo(fromPosition, false)
        return true
    end

    position:sendMagicEffect(CONST_ME_MAGIC_BLUE)
    return true
end

for _, actionId in pairs(vocations) do
    vocationCheckTile:aid(actionId)
end
vocationCheckTile:register()
Alright!

is it directly into this folder im gonna put this .lua?


1692646332123.png
 
i dont seem to get it to work.. View attachment 77787

i write the ID for druids, but this happens

View attachment 77788
Slight mistake.

Try this.

Lua:
local vocations = {
----[actionId] = {vocations}
    [45001] = {1, 5}, -- insert vocations that you want to be able to pass through
    [45002] = {2, 6},
    [45003] = {3, 7},
    [45004] = {4, 8},
    [45005] = {1, 2, 5, 6} -- example of a 'mages only' (sorc & druid)
}

local vocationCheckTile = MoveEvent()
vocationCheckTile:type("stepin")

function vocationCheckTile.onStepIn(creature, item, position, fromPosition)
    local player = Player(creature:getId())
    if not player then
        position:sendMagicEffect(CONST_ME_MAGIC_RED)
        creature:teleportTo(fromPosition, false)
        return true
    end
    
    local vocations = vocations[item:getActionId()]
    local vocationId = player:getVocation():getId()
    
    if not table.contains(vocations, vocationId) then
        position:sendMagicEffect(CONST_ME_MAGIC_RED)
        player:teleportTo(fromPosition, false)
        return true
    end
    
    position:sendMagicEffect(CONST_ME_MAGIC_BLUE)
    return true
end

for actionId , _ in pairs(vocations) do
    vocationCheckTile:aid(actionId)
end
vocationCheckTile:register()
 
Solution
Back
Top