• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

Action Vocation door

Nerkoerko

Banned User
Joined
Feb 28, 2009
Messages
402
Reaction score
5
Location
Polska
Hi this is my first code I wrote learning function. I'm sure that someone will need it.
Sorry for the construction of sentences, do not know English ...

Code:
<action actionid="[COLOR="#FF8C00"]1001[/COLOR]" event="script" value="[COLOR="#FF8C00"]rookgaard/door/sorcerer.lua[/COLOR]"/>

Code:
[COLOR="#0000CD"]function [/COLOR]onUse(cid, item)

[COLOR="#0000CD"]local [/COLOR]sqm = getPlayerPosition(cid)
[COLOR="#0000CD"]local [/COLOR]leave = {x=[COLOR="#FF8C00"]578[/COLOR], y=[COLOR="#FF8C00"]495[/COLOR], z=[COLOR="#FF8C00"]7[/COLOR]}
[COLOR="#0000CD"]local [/COLOR]entrance = {x=[COLOR="#FF8C00"]578[/COLOR], y=[COLOR="#FF8C00"]496[/COLOR], z=[COLOR="#FF8C00"]7[/COLOR]}

[COLOR="#0000CD"]if[/COLOR] getPlayerVocation(cid) == [COLOR="#FF0000"]1[/COLOR] then
[COLOR="#0000CD"]if[/COLOR] sqm.x == [COLOR="#FF8C00"]578[/COLOR] and sqm.y == [COLOR="#FF8C00"]496[/COLOR] and sqm.z == [COLOR="#FF8C00"]7[/COLOR] then
doTeleportThing(cid, leave)
[COLOR="#0000CD"]else[/COLOR]
doTeleportThing(cid, entrance)
doTransformItem(item.uid, [COLOR="#FF8C00"]1258[/COLOR])
[COLOR="#0000CD"]end[/COLOR]
[COLOR="#0000CD"]else[/COLOR]
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR , "Sorry, you are not a Druid.")
[COLOR="#0000CD"]end[/COLOR]

[COLOR="#0000CD"]end[/COLOR]

Configurations
Vocation ID​
Code:
[COLOR="#0000CD"]if[/COLOR] getPlayerVocation(cid) == 1 then
Position where we throw out (the door)​
Code:
[COLOR="#0000CD"]local[/COLOR] leave = {x=578, y=495, z=7}
Position of the door​
Code:
[COLOR="#0000CD"]local[/COLOR] entrance = {x=578, y=496, z=7}
Then position position of the door (the function checks to see if you are standing at the door, if so click on the door and throw you out before or not depends on how you set ...)​
Code:
[COLOR="#0000CD"]if[/COLOR] sqm.x == 578 and sqm.y == 496 and sqm.z == 7
Open door id​
Code:
doTransformItem(item.uid, 1258)

Photo's
6h6bms.png

1hyumt.png
 
Last edited:
It's great that you're contributing to the community and practicing to write scripts.
However, there is a much simpler method to create a vocation door.

In mapeditor:
- Place quest door
- Set actionID as 100 + vocation ID. (eg. knight = 104)

Done.
 
Tested on TFS 1.0? On My Server the "104" Try AND your Script dont work :eek:

Code:
function onUse(cid, item)
local sqm = getPlayerPosition(cid)
local leave = {x=137, y=690, z=8}
local entrance = {x=137, y=691, z=8}
if getPlayerVocation(cid) == 4 then
if sqm.x == 578 and sqm.y == 496 and sqm.z == 7 then
doTeleportThing(cid, leave)
        else
doTeleportThing(cid, entrance)
doTransformItem(item.uid, 1226)
    end
        else
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR , "Sorry, you are not a Knight.")
    end
end

For leave i select the Position SQM AFTEr the Door.. is that wrong? and i always selected the open door for doTransformItem

Greets,
 
Might be abit long buts its working. :)

Code:
function onUse(cid, item, frompos, item2, topos)

   if item.uid == 10091 then
      if getPlayerVocation(cid) == 1 then
         doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You may pass, you are a Knight.")
         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_INFO_DESCR,'Please stand in front of the door.')
    return 1
    end

       doTeleportThing(cid,pos)
       doSendMagicEffect(topos,12)
    else
       doPlayerSendTextMessage(cid,MESSAGE_INFO_DESCR,'You can\'t pass, you aren\'t a Knight.')
    end

        return 1
             else
        return 0
    end
end

Works on TFS 1.0.
(Sorry for the fast tab)

Kind Regards,
Eldin.
 
It checks the position of the item you click use on (the door) in that script, so adding positions isn't needed indeed.

You can also add this to doors.lua
Code:
local vocation = item.actionid - 100
if vocation >= 1 and vocation <= 8 then
     if isInArray({vocation, vocation + 4}, player:getVocation():getId()) then
         Item(item.uid):transform(item.itemid + 1)
         player:teleportTo(toPosition, true)
     else
         player:sendTextMessage(MESSAGE_INFO_DESCR, "Only the worthy may pass.")
     end
     return true
end

Under
Code:
  elseif isInArray(levelDoors, item.itemid) then
     local player = Player(cid)

Then actionid 101 will be sorcerer, 102 druid, 103 paladin, 104 knight.
105, 106, 107 and 108 will be for promoted vocs only.
 
Thanks ! :)

but the doors.lua is not the same as your post.. :/

Code:
function onUse(player, item, fromPosition, itemEx, toPosition, isHotkey)
    if isInArray(questDoors, item.itemid) then
        if player:getStorageValue(item.actionid) ~= -1 then
            Item(item.uid):transform(item.itemid + 1)
            player:teleportTo(toPosition, true)
        else
            player:sendTextMessage(MESSAGE_INFO_DESCR, "The door seems to be sealed against unwanted intruders.")
        end
        return true
    elseif isInArray(levelDoors, item.itemid) then
        if item.actionid > 0 and player:getLevel() >= item.actionid - 1000 then
            Item(item.uid):transform(item.itemid + 1)
            player:teleportTo(toPosition, true)
        else
            player:sendTextMessage(MESSAGE_INFO_DESCR, "Only the worthy may pass.")
        end
        return true
    elseif isInArray(keys, item.itemid) then
        if itemEx.actionid > 0 then
            if item.actionid == itemEx.actionid then
                if doors[itemEx.itemid] then
                    Item(itemEx.uid):transform(doors[itemEx.itemid])
                    return true
                end
            end
            player:sendTextMessage(MESSAGE_STATUS_SMALL, "The key does not match.")
            return true
        end
        return false
    end

    local tileToPos = toPosition:getTile()
    local thing = tileToPos:getThing(STACKPOS_TOP_MOVEABLE_ITEM_OR_CREATURE)
    if thing and item.uid ~= thing:getUniqueId() and fromPosition:getTile():getItemByType(ITEM_TYPE_MAGICFIELD) then
        return false
    end

    if isInArray(horizontalOpenDoors, item.itemid) or isInArray(verticalOpenDoors, item.itemid) then
        local doorCreature = tileToPos:getTopCreature()
        if doorCreature ~= nil then
            toPosition.x = toPosition.x + 1
            local query = toPosition:getTile():queryAdd(doorCreature, 20)
            if query ~= RETURNVALUE_NOERROR then
                toPosition.x = toPosition.x - 1
                toPosition.y = toPosition.y + 1
                query = toPosition:getTile():queryAdd(doorCreature, 20)
            end

            if query ~= RETURNVALUE_NOERROR then
                player:sendTextMessage(MESSAGE_STATUS_SMALL, query)
                return true
            end

            doorCreature:teleportTo(toPosition, true)
        end
        if not isInArray(openSpecialDoors, item.itemid) then
            Item(item.uid):transform(item.itemid - 1)
        end
        return true
    end

    if doors[item.itemid] then
        if item.actionid == 0 then
            Item(item.uid):transform(doors[item.itemid])
        else
            player:sendTextMessage(MESSAGE_INFO_DESCR, "It is locked.")
        end
        return true
    end
    return false
end
 
Back
Top