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

Lua magic door (toPosition)

darkmu

Well-Known Member
Joined
Aug 26, 2007
Messages
274
Solutions
1
Reaction score
50
Location
Paraná,Brazil
Lua:
local storage = 15312
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if(item.uid == 37994) then       
        if(player:getStorageValue(storage) > 0) then
            if(item.itemid == 5105) then           
                player:teleportTo(toPosition, true)
                item:transform(item.itemid + 1)
                
            end
        else
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "The door seems to be sealed against unwanted intruders.")
        end
    end
    return true
end



This way makes it possible for a player who has already made a search to open a door for others to enter, how can I make the character walk 2 sqm?
1593297049197.png
 
Solution
E
why are you doing it that way? tfs already have these system by default, delete this script that you are using and add actionID 15312 to the door, and the default script will take care of everything else:


you could also add a tile check if you want to:

just add the needed storage to walk over it as an actionID
Lua:
local storage = 15312
local pPos = getPlayerPosition(cid)
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if(item.uid == 37994) then      
        if(player:getStorageValue(storage) > 0) then
            if(item.itemid == 5105) then        
     if pPos.x < toPosition.x then
            pos = {x = toPosition.x + 1, y = toPosition.y, z = toPosition.z}
        elseif pPos.x > toPosition.x then
            pos = {x = toPosition.x - 1, y = toPosition.y, z = toPosition.z}
        end
                player:teleportTo(pos, true)
               
            end
        else
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "The door seems to be sealed against unwanted intruders.")
        end
    end
    return true
end
Post automatically merged:

Had a typo, corrected it, If you already tested re-copy and test again.
 
Last edited:
Lua:
local storage = 15312
local pPos = getPlayerPosition(cid)
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if(item.uid == 37994) then     
        if(player:getStorageValue(storage) > 0) then
            if(item.itemid == 5105) then       
     if pPos.x < toPosition.x then
            pos = {x = toPosition.x + 1, y = toPosition.y, z = toPosition.z}
        elseif pPos.x > toPosition.x then
            pos = {x = toPosition.x - 1, y = toPosition.y, z = toPosition.z}
        end
                player:teleportTo(pos, true)
              
            end
        else
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "The door seems to be sealed against unwanted intruders.")
        end
    end
    return true
end
Post automatically merged:

Had a typo, corrected it, If you already tested re-copy and test again.


1593301917516.png

it is returning me as these positions there or after you are going to null, but by default as the doors were not to close when clicking, this is getting weird.
 
Lua:
local storage = 15312
local pPos = getPlayerPosition(cid)
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if(item.uid == 37994) then    
        if(player:getStorageValue(storage) > 0) then
            if(item.itemid == 5105) then      
     if pPos.x < toPosition.x then
            pos = {x = toPosition.x + 1, y = toPosition.y, z = toPosition.z}
        elseif pPos.x > toPosition.x then
            pos = {x = toPosition.x - 1, y = toPosition.y, z = toPosition.z}
        end
                player:teleportTo(pos, true)
             
            end
        else
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "The door seems to be sealed against unwanted intruders.")
        end
    end
    return true
end
Post automatically merged:

Had a typo, corrected it, If you already tested re-copy and test again.
You have the right idea, but you need to use the y axis, not x axis.
Lua:
local storage = 15312
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if(item.uid == 37994) then      
        if(player:getStorageValue(storage) > 0) then
            if(item.itemid == 5105) then          
                player:teleportTo(toPosition, true)
                item:transform(item.itemid + 1)
               
            end
        else
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "The door seems to be sealed against unwanted intruders.")
        end
    end
    return true
end



This way makes it possible for a player who has already made a search to open a door for others to enter, how can I make the character walk 2 sqm?
View attachment 46938
Try this.
Lua:
local storage = 15312

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if(item.uid == 37994) then       
        if(player:getStorageValue(storage) > 0) then
            if(item.itemid == 5105) then
                local player_pos = player:getPosition()
                if player_pos.y <= toPosition.y then
                    player:teleportTo((toPosition.x, toPosition.y + 1, toPosition.z), true)
                else
                    player:teleportTo((toPosition.x, toPosition.y - 1, toPosition.z), true)
                end
                --item:transform(item.itemid + 1) -- I guess this isn't needed anymore, since the doorway should never have a player occupy it.
            end
        else
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "The door seems to be sealed against unwanted intruders.")
        end
    end
    return true
end
 
why are you doing it that way? tfs already have these system by default, delete this script that you are using and add actionID 15312 to the door, and the default script will take care of everything else:


you could also add a tile check if you want to:

just add the needed storage to walk over it as an actionID
 
Solution
why are you doing it that way? tfs already have these system by default, delete this script that you are using and add actionID 15312 to the door, and the default script will take care of everything else:


you could also add a tile check if you want to:

just add the needed storage to walk over it as an actionID


so i did it by triggering the doors even so they stay open allowing other players who did not make a search to pass, in this case do i need to add a movement on the floor?
 
Back
Top