• 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 Check fields ladders to up

zexus

Member
Joined
Oct 1, 2016
Messages
133
Reaction score
18
I wanna make something different in my pvp, i wanna check the ladders before player can get up.
For example, if have fire field, mw the player can not get up on ladders

I've tried it:
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
   -- there is MW or ELEMENTAL FIELDS in pos?
   local tmp = getTileThingByPos({x = toPosition.x, y = toPosition.y, z = toPosition.z, stackpos = 1})
       if ((isPlayer(tmp.uid) and tmp.uid ~= cid)) or (tmp.itemid == 1497 or tmp.itemid == 1499 or tmp.itemid == 1496 or tmp.itemid == 1495 or tmp.itemid == 1492 or tmp.itemid == 1493 or tmp.itemid == 1494) then
       return false
   end
   -- get UP
   fromPosition.z = fromPosition.z - 1
   fromPosition.y = fromPosition.y + 1
   if(doTileQueryAdd(cid, fromPosition, 38, false) ~= RETURNVALUE_NOERROR) then
       local field = getTileItemByType(fromPosition, ITEM_TYPE_MAGICFIELD)
       if(field.uid == 0 or not isInArray(FIELDS, field.itemid)) then
           fromPosition.y = fromPosition.y - 2
       else
           check = true
       end
   end
   return true
end

But using that the players are not upping

What should i change?
 
Solution
I'm sorry if i cant let myself to be understood, English is not my moon language
What i want to prevent that stairs pvp, where player being get up and get down to cant be target is:
If the stair where have the stair has a fire/energy/poison field or magic/wild grow wall the players can not get up

I did 2 prints:
Should can get up:
Yxmeved.png


Shouldn't can get up:
KwtXoin.png


actions/ladders_pvp.lua
Code:
local blockable_field_items = {1497, 1499, 1496, 1495, 1492, 1493, 1494}
function onUse(cid, item, fromPosition, itemEx, toPosition)
    local ladder_destination = {x = toPosition.x, y = toPosition.y + 1, z = toPosition.z - 1}
    -- check for players
    if...
Trying to wrap my head around what those do.

So it changes the position of the item so it appear over/under other items right?

So for the ladder, which is now 'under' the firefields, I understand that.
But how would it solve the player on ladder thing?
You are still using the ladder, right?

For the rope hole.. you are using a rope on the tile that contains that ground tile.
As far as I'm aware, it's already set as the bottom, and everything can go on top of it.

How would changing a ground tiles position upwards or downwards change how a rope works?
How would changing the open hole's graphical placement change what the rope does when you use it?
You can't even throw items onto those, as they fall down the hole?

Can you actually explain this to me?
I really don't understand..
 
The rope hole wouldnt get changed. You are right that would have to be hard coded. When people rope up from a hole. The actual rope spot under the whole and the lasder can have their stack position changed so fields would be on top or you could change the fields themselves. Yea you would still beed to make q code to check if players are stabding on the ladder or rope spot. So changing the stack position of the ladder and rope spot would only removw the need for checking for fields which s still better because pess code will need to be ran in lua. If he wanted to be a real developer he would create a completly new etack position fir the ladder and rope spots and create the code in C++ that wouod do what the lua code does if the stack position is read. Which is much more effective. In teality it fiesnt matter that much but after 900 codes not opitmized you may start seeing some poor performancw of the server.
 
So TLDR...

Item attribute changing method would solve 1/2 problems for the ladder.
Code everything else into the source because it's faster then lua.

Good luck OP.
 
Would be more efficient to just change the ladder and rope spot in object builder rather than creating all this mess of code.
No, rope spot is a ground tile, it's always bottom (under items), every item is on top of it, even ladder AND that's how it is meant to be. This has to be coded not edited in any object builder. Client iterates the tile (items) from the bottom (ground, stackpos 0), not from the top, when you click on the ladder in this case.
 
Last edited:
sorry.
Just remove this line
It's only in there for testing purposes anyway
Lua:
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Player Found.")

If i remove it's stop to show the error (script is working)

But how to add messages like this, that i added on ladder script?
Code:
doPlayerSendCancel(cid, "You have blocked to get up")
doPlayerSendCancel(pid, "You have blocked a player to get up")
 
If i remove it's stop to show the error (script is working)

But how to add messages like this, that i added on ladder script?
Code:
doPlayerSendCancel(cid, "You have blocked to get up")
doPlayerSendCancel(pid, "You have blocked a player to get up")
Can you clarify?

When YOU are on ladder and YOU use ladder -> do what?
When YOU are on ladder and OTHER use ladder -> do what?
When OTHER on ladder and YOU use ladder -> do what?

Same for rope spot..


When YOU are on rope spot and YOU use rope spot -> do what?
When YOU are on rope spot and OTHER use rope spot -> do what?
When OTHER on rope spot and YOU use rope spot -> do what?

---
Just trying to figure out if send to other and you, or just 'you'.
 
Can you clarify?

When YOU are on ladder and YOU use ladder -> do what?
When YOU are on ladder and OTHER use ladder -> do what?
When OTHER on ladder and YOU use ladder -> do what?

Same for rope spot..


When YOU are on rope spot and YOU use rope spot -> do what?
When YOU are on rope spot and OTHER use rope spot -> do what?
When OTHER on rope spot and YOU use rope spot -> do what?

---
Just trying to figure out if send to other and you, or just 'you'.

Srry again
I just want to send a message

To the player who block the rope hole and to the player who is trying to get up in the rope hole, but was blocked, because there is another one blocking.
 
Srry again
I just want to send a message

To the player who block the rope hole and to the player who is trying to get up in the rope hole, but was blocked, because there is another one blocking.
lol, and now I realise that my script would block yourself from going up, if you are standing on the rope hole / ladder. :rolleyes:
But I don't know if you want it like that.. :confused:

So I'll do 2 versions.

Allow SELF to go up holes/ladders if SELF is blocking.
VVVVVVVVVVVVVVVVVVVVVVVV


LADDER
Lua:
local blockable_field_items = {1497, 1499, 1496, 1495, 1492, 1493, 1494}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local spectators = getSpectators(toPosition, 1, 1, false)
    if spectators ~= nil then
        for _, pid in ipairs(spectators) do
            if isPlayer(pid) and cid ~= pid then
                local pos = getThingPosition(pid)
                if pos.x == toPosition.x and pos.y == toPosition.y then
                    doPlayerSendTextMessage(pid, MESSAGE_STATUS_SMALL, "Blocked " .. getCreatureName(cid) .. "'s passage.")
                    doPlayerSendTextMessage(cid, MESSAGE_STATUS_SMALL, .. getCreatureName(pid) .. " is blocking passage.")
                    return true
                end
            end
        end
    end
    for i = 1, #blockable_field_items do
        if getTileItemById(toPosition, blockable_field_items[i]).uid > 0 then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_SMALL, "Passage blocked by field item.")
            return true
        end
    end
    doTeleportThing(cid, {x = toPosition.x, y = toPosition.y + 1, z = toPosition.z - 1})
    return true
end
ROPE
Lua:
local blockable_field_items = {1497, 1499, 1496, 1495, 1492, 1493, 1494}

local function checkForPlayerOnPosition(cid, position)
    local spectators = getSpectators(position, 1, 1, false)
    if spectators ~= nil then
        for _, pid in ipairs(spectators) do
            if isPlayer(pid) and cid ~= pid then
                local pos = getThingPosition(pid)
                if pos.x == position.x and pos.y == position.y then
                    doPlayerSendTextMessage(pid, MESSAGE_STATUS_SMALL, "Blocked " .. getCreatureName(cid) .. "'s passage.")
                    doPlayerSendTextMessage(cid, MESSAGE_STATUS_SMALL, .. getCreatureName(pid) .. " is blocking passage.")
                    return true
                end
            end
        end
    end
    return false
end

local function doesTileHaveFieldItems(position)
    for i = 1, #blockable_field_items do
        if getTileItemById(position, blockable_field_items[i]).uid > 0 then
            return true
        end
    end
    return false
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if(toPosition.x == CONTAINER_POSITION) then
        doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
        return true
    end
    toPosition.stackpos = STACKPOS_GROUND
    local itemGround = getThingFromPos(toPosition)
    if isInArray(SPOTS, itemGround.itemid) then
        if checkForPlayerOnPosition(cid, toPosition) == true then
            return true
        end
        for i = 1, #blockable_field_items do
        if doesTileHaveFieldItems(toPosition) == true then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_SMALL, "Passage blocked by field item.")
            return true
        end
        doTeleportThing(cid, {x = toPosition.x, y = toPosition.y + 1, z = toPosition.z - 1}, false)
    elseif isInArray(ROPABLE, itemEx.itemid) then
        local hole_destination = {x = toPosition.x, y = toPosition.y, z = toPosition.z + 1}
        if checkForPlayerOnPosition(cid, hole_destination) == true then
            return true
        end
        if doesTileHaveFieldItems(hole_destination) == true then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_SMALL, "Action blocked by field item.")
            return true
        end
        local hole = getThingFromPos({x = toPosition.x, y = toPosition.y, z = toPosition.z + 1, stackpos = STACKPOS_TOP_MOVEABLE_ITEM_OR_CREATURE})
        if hole.itemid > 0 then
            doTeleportThing(hole.uid, {x = toPosition.x, y = toPosition.y + 1, z = toPosition.z}, false)
        end
        return true
    end
    return false
end

Don't allow ANYONE to use the hole/ladder if ANYONE is blocking.
VVVVVVVVVVVVVVVVVVVVVVVV


LADDER
Lua:
local blockable_field_items = {1497, 1499, 1496, 1495, 1492, 1493, 1494}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local spectators = getSpectators(toPosition, 1, 1, false)
    if spectators ~= nil then
        for _, pid in ipairs(spectators) do
            if isPlayer(pid) then
                local pos = getThingPosition(pid)
                if pos.x == toPosition.x and pos.y == toPosition.y then
                    if pid == cid then
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_SMALL, "You are blocking passage.")
                    else
                        doPlayerSendTextMessage(pid, MESSAGE_STATUS_SMALL, "Blocked " .. getCreatureName(cid) .. "'s passage.")
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_SMALL, .. getCreatureName(pid) .. " is blocking passage.")
                    end
                    return true
                end
            end
        end
    end
    for i = 1, #blockable_field_items do
        if getTileItemById(toPosition, blockable_field_items[i]).uid > 0 then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_SMALL, "Passage blocked by field item.")
            return true
        end
    end
    doTeleportThing(cid, {x = toPosition.x, y = toPosition.y + 1, z = toPosition.z - 1})
    return true
end
ROPE
Lua:
local blockable_field_items = {1497, 1499, 1496, 1495, 1492, 1493, 1494}

local function checkForPlayerOnPosition(cid, position)
    local spectators = getSpectators(position, 1, 1, false)
    if spectators ~= nil then
        for _, pid in ipairs(spectators) do
            if isPlayer(pid) then
                local pos = getThingPosition(pid)
                if pos.x == position.x and pos.y == position.y then
                    if pid == cid then
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_SMALL, "You are blocking passage.")
                    else
                        doPlayerSendTextMessage(pid, MESSAGE_STATUS_SMALL, "Blocked " .. getCreatureName(cid) .. "'s passage.")
                        doPlayerSendTextMessage(cid, MESSAGE_STATUS_SMALL, .. getCreatureName(pid) .. " is blocking passage.")
                    end
                    return true
                end
            end
        end
    end
    return false
end

local function doesTileHaveFieldItems(position)
    for i = 1, #blockable_field_items do
        if getTileItemById(position, blockable_field_items[i]).uid > 0 then
            return true
        end
    end
    return false
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if(toPosition.x == CONTAINER_POSITION) then
        doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
        return true
    end
    toPosition.stackpos = STACKPOS_GROUND
    local itemGround = getThingFromPos(toPosition)
    if isInArray(SPOTS, itemGround.itemid) then
        if checkForPlayerOnPosition(cid, toPosition) == true then
            return true
        end
        for i = 1, #blockable_field_items do
        if doesTileHaveFieldItems(toPosition) == true then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_SMALL, "Passage blocked by field item.")
            return true
        end
        doTeleportThing(cid, {x = toPosition.x, y = toPosition.y + 1, z = toPosition.z - 1}, false)
    elseif isInArray(ROPABLE, itemEx.itemid) then
        local hole_destination = {x = toPosition.x, y = toPosition.y, z = toPosition.z + 1}
        if checkForPlayerOnPosition(cid, hole_destination) == true then
            return true
        end
        if doesTileHaveFieldItems(hole_destination) == true then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_SMALL, "Action blocked by field item.")
            return true
        end
        local hole = getThingFromPos({x = toPosition.x, y = toPosition.y, z = toPosition.z + 1, stackpos = STACKPOS_TOP_MOVEABLE_ITEM_OR_CREATURE})
        if hole.itemid > 0 then
            doTeleportThing(hole.uid, {x = toPosition.x, y = toPosition.y + 1, z = toPosition.z}, false)
        end
        return true
    end
    return false
end
 
Last edited:
I think checkForFieldItems is left...

Code:
[12:36:33.158] [Error - Action Interface]
[12:36:33.158] data/actions/scripts/tools/rope.lua:onUse
[12:36:33.158] Description:
[12:36:33.158] data/actions/scripts/tools/rope.lua:43: attempt to call global 'checkForFieldItems' (a nil value)
[12:36:33.158] stack traceback:
[12:36:33.158]    data/actions/scripts/tools/rope.lua:43: in function <data/actions/scripts/tools/rope.lua:31>
 
I think checkForFieldItems is left...

Code:
[12:36:33.158] [Error - Action Interface]
[12:36:33.158] data/actions/scripts/tools/rope.lua:onUse
[12:36:33.158] Description:
[12:36:33.158] data/actions/scripts/tools/rope.lua:43: attempt to call global 'checkForFieldItems' (a nil value)
[12:36:33.158] stack traceback:
[12:36:33.158]    data/actions/scripts/tools/rope.lua:43: in function <data/actions/scripts/tools/rope.lua:31>
Edited script up.
Recopy.
 
Edited script up.
Recopy.

Thank you again...

---

One last problem, i think so :D

In my server there is a lot caves where you use rope and go up to a teleport to set you to another position...

And with this rope script when i try to get up there it lag a lot, player get freezed

Images to example:
7mvYknU.png


M27wIvS.png







edit:

I think the error may be here:
When can get up, get up normal with the rope, shows this message:
First go downstairs
 
Last edited:
Thank you again...

---

One last problem, i think so :D

In my server there is a lot caves where you use rope and go up to a teleport to set you to another position...

And with this rope script when i try to get up there it lag a lot, player get freezed

Images to example:
7mvYknU.png


M27wIvS.png







edit:

I think the error may be here:
When can get up, get up normal with the rope, shows this message:
First go downstairs
Not sure why you'd lag when getting teleported two times in a row.
There's no real fix for this, unless you do a source edit.
(so you can find the destination of the magic forvefield. There is no function that I know that does this)

You'll just have to move the magic forcefields like this.. or something.
N8pvstR.png
 
Back
Top