• 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 Stair Cannot use if above item

Shackal

Alien Project
Joined
Feb 7, 2009
Messages
211
Reaction score
17
Location
Brazil
Hello Guys,

If I try to use the stairs when it has a body on it, returns false. Follow Screenshot:
mxOyJwD.png


Follow script:
Code:
local upFloorIds = {1386, 3678, 5543}
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if isInArray(upFloorIds, item.itemid) then
        fromPosition:moveUpstairs()
    else
        fromPosition.z = fromPosition.z + 1
    end
    player:teleportTo(fromPosition, false)
    return true
end

I'm Using TFS 1.2
Sorry my bad english
Thank you in advance
 
Hello Guys,

If I try to use the stairs when it has a body on it, returns false. Follow Screenshot:
Follow script:
Code:
local upFloorIds = {1386, 3678, 5543}
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if isInArray(upFloorIds, item.itemid) then
        fromPosition:moveUpstairs()
    else
        fromPosition.z = fromPosition.z + 1
    end
    player:teleportTo(fromPosition, false)
    return true
end

I'm Using TFS 1.2
Sorry my bad english
Thank you in advance

You edited your items.otb? Probably fucked up "ForceUse" tag on ladder item.
 
PHP:
table = {"First", "Second", "Third"}
check = isInArray(table, "Second")
check2 = isInArray(table, "NotIn")
print(check, check2)

Try that piece of code :p
It simply returns 1 if that is in the array, but if it's not in the array, I think it returns -1, check the script and see by yourself...

Although, it doesn't take spaces, if you'd check like "Hello mr", I THINK it'd only check "Hello", or nothing at all, not sure. But you could make your own function for this:
PHP:
-- Function by Colandus
function isInArray(t, v, c)
    v = (c ~= nil and string.lower(v)) or v
    if type(t) == "table" and v ~= nil then
        for key, value in pairs(t) do
            value = (c ~= nil and string.lower(value)) or value
            if v == value then
                return 1
            end
        end
    end
    return -1
end

This one works exactly the same, but only that in NORMAL isInArray, it's case-sensetive, which means:
PHP:
table = {"First", "Second", "Third"}
check = isInArray(table, "Second")
check2 = isInArray(table, "THIRD")
print(check, check2)
Would print -1 -1, even though Third is in the array, but THIRD is not in. But my function, will allow incase-sensetivity if you just write something at the last parameter:
PHP:
-- Using my isInArray (in global.lua)
table = {"First", "Second", "Third", "4th Fourth"}
check = isInArray(table, "4th Fourth")
check2 = isInArray(table, "THIRD", true)
print(check, check2)
This will print 1 1, because spaces does work and incase-sensitivity was on at the second check.

Regards,
Colandus


Colandus had a great reply to this. If you find that it didn't have anything to do with the ForceUse tag, but instead tried to add a teleport.lua to TFS1.2 from a different data build, this is probably relevant.
I'm currently recompiling before attempting to determine if it's the solution to my problem, but my global.lua didn't have isInArray after moving over to a new datapack.

Edit: I ended up using Limos' suggestion, and added it to the /forgottenserver/lib/compat/compat.lua file. I can finally use ladders and sewer grates now:
function isInArray(array, value, caseSensitive)
if(caseSensitive == nil or caseSensitive == false) and type(value) == "string" then
local lowerValue = value:lower()
for _, _value in ipairs(array) do
if type(_value) == "string" and lowerValue == _value:lower() then
return true
end
end
else
for _, _value in ipairs(array) do
if (value == _value) then return true end
end
end
return false
end
 
Last edited:
Back
Top