• 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...
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?
I don't understand what your script is even doing. lol
Lua:
-- 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
This first part is trying to stop them from using the ladder.

But this part..? It's literally doing a bunch of checks, and then does nothing with that information.
and "check = true" -> check is never defined anywhere, so this isn't doing anything.
Lua:
   -- 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
So.. based on that information, it looks like you are forgetting to teleport the player up the ladder. :rolleyes:

But I digress, the things you've put into the code aren't the best way to do this.
U3F5isF.png


Try this instead.
Lua:
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 isPlayer(getThingfromPos(ladder_destination)) then
        return true
    end
   
    -- check for blockable field items
    for i = 1, #blockable_field_items do
        if getTileItemById(ladder_destination, blockable_field_items[i]).uid > 0 then
            return true
        end
    end
   
    -- teleport player
    doTeleportThing(cid, ladder_destination)   
    return true
end
 
I've tried your script:
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 isPlayer(getThingfromPos(ladder_destination)) then
       print("1")
        return true
    end
  
    -- check for blockable field items
    for i = 1, #blockable_field_items do
        if getTileItemById(ladder_destination, blockable_field_items[i]).uid > 0 then
           print("2")
            return true
        end
    end
  
    -- teleport player
    doTeleportThing(cid, ladder_destination)
    print("3")
    return true
end

But when i try to get up in a ladder with a Magic Wall (1497) print only 3
 
I've tried your script:
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 isPlayer(getThingfromPos(ladder_destination)) then
       print("1")
        return true
    end
 
    -- check for blockable field items
    for i = 1, #blockable_field_items do
        if getTileItemById(ladder_destination, blockable_field_items[i]).uid > 0 then
           print("2")
            return true
        end
    end
 
    -- teleport player
    doTeleportThing(cid, ladder_destination)
    print("3")
    return true
end

But when i try to get up in a ladder with a Magic Wall (1497) print only 3
Can you give pictures of what it looks like in-game?
By all rights, it sounds like it's working as intended.
 
Can you give pictures of what it looks like in-game?
By all rights, it sounds like it's working as intended.

What u mean about pictures?
I just press right button on the stair to try to get up, with a fire field on the stair and get up fine and print 3
It was a fire field on the stair
 
My suggestion is to give more information about what you are trying to do.
In multiple posts you claim 'it' isn't working.
What is not working?

You state that it prints 3, and it allows you go up the stair.
But the thread up to this point has been catered, named and scripted for ladders.

You want help?
Explain to me exactly how you want it to work.

If you can't concisely tell me what you want, why should I bother guessing and wasting my time scripting something that isn't going to be used?

If you can't explain yourself with words, then do as I suggested and show me directly with pictures, as I asked you to nearly a month ago.
I don't care how many pictures it takes, or how many words you need to write.
If I can't understand you, it's likely nobody else does either.
 
My suggestion is to give more information about what you are trying to do.
In multiple posts you claim 'it' isn't working.
What is not working?

You state that it prints 3, and it allows you go up the stair.
But the thread up to this point has been catered, named and scripted for ladders.

You want help?
Explain to me exactly how you want it to work.

If you can't concisely tell me what you want, why should I bother guessing and wasting my time scripting something that isn't going to be used?

If you can't explain yourself with words, then do as I suggested and show me directly with pictures, as I asked you to nearly a month ago.
I don't care how many pictures it takes, or how many words you need to write.
If I can't understand you, it's likely nobody else does either.

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 isPlayer(getThingfromPos(ladder_destination)) then
       print("1")
        return true
    end
  
    -- check for blockable field items
    for i = 1, #blockable_field_items do
        if getTileItemById(ladder_destination, blockable_field_items[i]).uid > 0 then
           print("2")
            return true
        end
    end
  
    -- teleport player
    doTeleportThing(cid, ladder_destination)
    print("3")
    return true
end

With this script, when i get up with nothing in stair tile, print:
3

And if i get up with a fire field inside stair or MW
Also print 3
And I'm able to get up
 
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 isPlayer(getThingfromPos(ladder_destination)) then
       print("1")
        return true
    end
 
    -- check for blockable field items
    for i = 1, #blockable_field_items do
        if getTileItemById(ladder_destination, blockable_field_items[i]).uid > 0 then
           print("2")
            return true
        end
    end
 
    -- teleport player
    doTeleportThing(cid, ladder_destination)
    print("3")
    return true
end

With this script, when i get up with nothing in stair tile, print:
3

And if i get up with a fire field inside stair or MW
Also print 3
And I'm able to get up
change
Lua:
if getTileItemById(ladder_destination, blockable_field_items[i]).uid > 0 then
to
Lua:
if getTileItemById(toPosition, blockable_field_items[i]).uid > 0 then
 
Solution
Solved! Thank you!
Just a quick update, since that player check won't work properly.
Lua:
local blockable_field_items = {1497, 1499, 1496, 1495, 1492, 1493, 1494}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    -- check for players
    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
                    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Player Found.")
                    return true
                end
            end
        end
    end
  
    -- check for blockable field items
    for i = 1, #blockable_field_items do
        if getTileItemById(toPosition, blockable_field_items[i]).uid > 0 then
            return true
        end
    end
  
    -- teleport player
    doTeleportThing(cid, {x = toPosition.x, y = toPosition.y + 1, z = toPosition.z - 1})
    return true
end
 
Just a quick update, since that player check won't work properly.
Lua:
local blockable_field_items = {1497, 1499, 1496, 1495, 1492, 1493, 1494}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    -- check for players
    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
                    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Player Found.")
                    return true
                end
            end
        end
    end
 
    -- check for blockable field items
    for i = 1, #blockable_field_items do
        if getTileItemById(toPosition, blockable_field_items[i]).uid > 0 then
            return true
        end
    end
 
    -- teleport player
    doTeleportThing(cid, {x = toPosition.x, y = toPosition.y + 1, z = toPosition.z - 1})
    return true
end


Perfect!!!!
Again, thank you so much, i hate stairs pvp, u solved that problem!
Could you help me with a last thing?
Do the same thing to rope holes?

Idk why, but in this try on rope holes, sometimes it's working and sometimes not

actions/scripts/tools/rope.lua
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
   if(toPosition.x == CONTAINER_POSITION) then
       doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
       return true
   end

   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

   toPosition.stackpos = STACKPOS_GROUND
   local itemGround = getThingFromPos(toPosition)
   if(isInArray(SPOTS, itemGround.itemid)) then
       doTeleportThing(cid, {x = toPosition.x, y = toPosition.y + 1, z = toPosition.z - 1}, false)
       return true
   elseif(isInArray(ROPABLE, itemEx.itemid)) then
       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)
       else
           doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
       end

       return true
   end

   return false
end
 
Perfect!!!!
Again, thank you so much, i hate stairs pvp, u solved that problem!
Could you help me with a last thing?
Do the same thing to rope holes?

Idk why, but in this try on rope holes, sometimes it's working and sometimes not

actions/scripts/tools/rope.lua
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
   if(toPosition.x == CONTAINER_POSITION) then
       doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
       return true
   end

   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

   toPosition.stackpos = STACKPOS_GROUND
   local itemGround = getThingFromPos(toPosition)
   if(isInArray(SPOTS, itemGround.itemid)) then
       doTeleportThing(cid, {x = toPosition.x, y = toPosition.y + 1, z = toPosition.z - 1}, false)
       return true
   elseif(isInArray(ROPABLE, itemEx.itemid)) then
       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)
       else
           doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
       end

       return true
   end

   return false
end
Lua:
local blockable_field_items = {1497, 1499, 1496, 1495, 1492, 1493, 1494}

local function checkForPlayerOnPosition(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
                    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Player Found.")
                    return true
                end
            end
        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(toPosition) == true then
            return true
        end
        for i = 1, #blockable_field_items do
            if getTileItemById(toPosition, blockable_field_items[i]).uid > 0 then
                return true
            end
        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(hole_destination) == true then
            return true
        end
        for i = 1, #blockable_field_items do
            if getTileItemById(hole_destination, blockable_field_items[i]).uid > 0 then
                return true
            end
        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
 
Lua:
local blockable_field_items = {1497, 1499, 1496, 1495, 1492, 1493, 1494}

local function checkForPlayerOnPosition(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
                    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Player Found.")
                    return true
                end
            end
        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(toPosition) == true then
            return true
        end
        for i = 1, #blockable_field_items do
            if getTileItemById(toPosition, blockable_field_items[i]).uid > 0 then
                return true
            end
        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(hole_destination) == true then
            return true
        end
        for i = 1, #blockable_field_items do
            if getTileItemById(hole_destination, blockable_field_items[i]).uid > 0 then
                return true
            end
        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


It's working on fire field and mws, but not with players on hole...
If there is a player on hole dont sendplayermsg and print this error
Code:
[8:59:45.961] [Error - Action Interface]
[8:59:45.961] data/actions/scripts/tools/rope.lua:onUse
[8:59:45.962] Description:
[8:59:45.962] (luaDoPlayerSendTextMessage) Player not found
 
It's working on fire field and mws, but not with players on hole...
If there is a player on hole dont sendplayermsg and print this error
Code:
[8:59:45.961] [Error - Action Interface]
[8:59:45.961] data/actions/scripts/tools/rope.lua:onUse
[8:59:45.962] Description:
[8:59:45.962] (luaDoPlayerSendTextMessage) Player not found
sorry.
Just remove this line
It's only in there for testing purposes anyway
Lua:
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Player Found.")
 
Would be more efficient to just change the ladder and rope spot in object builder rather than creating all this mess of code.
 
Would be more efficient to just change the ladder and rope spot in object builder rather than creating all this mess of code.
I always thought object builder was to add different attributes to the items.
I'm not familiar enough with object builder to know what you can do with it.
What options would you enable in there to allow for something like this?
 
Back
Top