• 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 lever, player not found console error

Emky

Not Active Member
Joined
May 15, 2015
Messages
345
Reaction score
49
When using the lever and no player is on the position i get player not found, need a better way to check it, otherwise my console gets spammed with this error message:
LuaScriptInterface::internalGetPlayerInfo(). Player not found.

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

    leverUID = 1337
    playerPos = {x = 10, y = 20, z = 30, stackpos = 253}
    getPlayerPos = getThingFromPos(playerPos)

    newPos = {x = 30, y = 50, z = 100}

    if item.uid == leverUID then
        if item.itemid == 1945 then
            if getPlayerPos.itemid > 0 then
                doTeleportThing(getPlayerPos.uid, newPos)
                doSendMagicEffect(playerPos, CONST_ME_TELEPORT)
            else
                doPlayerSendCancel(cid, "test123")
            end
        elseif item.itemid == 1946 then
            doTransformItem(item.uid, item.itemid-1)
        else
            return false
        end
    else
        print("wrong uid")
    end

    return true
end
 
When using the lever and no player is on the position i get player not found, need a better way to check it, otherwise my console gets spammed with this error message:
LuaScriptInterface::internalGetPlayerInfo(). Player not found.

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

    leverUID = 1337
    playerPos = {x = 10, y = 20, z = 30, stackpos = 253}
    getPlayerPos = getThingFromPos(playerPos)

    newPos = {x = 30, y = 50, z = 100}

    if item.uid == leverUID then
        if item.itemid == 1945 then
            if getPlayerPos.itemid > 0 then
                doTeleportThing(getPlayerPos.uid, newPos)
                doSendMagicEffect(playerPos, CONST_ME_TELEPORT)
            else
                doPlayerSendCancel(cid, "test123")
            end
        elseif item.itemid == 1946 then
            doTransformItem(item.uid, item.itemid-1)
        else
            return false
        end
    else
        print("wrong uid")
    end

    return true
end

Maybe the error is related in the way you check that getPlayerPos variable is a Player.
I don't really know if getThingFromPos(playerPos) returns a Player everytime because i don't know where playerPos leads to; but if i'm right when you check:
if getPlayerPos.itemid > 0 then

You are really doing nothing, because getPlayerPos is a variable who contains a Thing (I suppose because of the getThingFromPos(pos) method); and every "thing" have an id > 0 so that if isn't really doing a thing there.

I think you should change that check for a atribute that objects of type Thing has, but i don't really know the API of TFS. With attribute i refer to the thing."attribute" like thing.itemid or thing.uid.
(It could be helpful if someone else knows where to get this info)

i hope this helped something heh
 
My guess is that the problem is that you're doing a check on something that is returning nil. Quick solution is to add a check to see if its nil or not.

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

    leverUID = 1337
    playerPos = {x = 10, y = 20, z = 30, stackpos = 253}
    getPlayerPos = getThingFromPos(playerPos)

    newPos = {x = 30, y = 50, z = 100}

if getPlayerPos ~= nil then
    if item.uid == leverUID then
        if item.itemid == 1945 then
            if getPlayerPos.itemid > 0 then
                doTeleportThing(getPlayerPos.uid, newPos)
                doSendMagicEffect(playerPos, CONST_ME_TELEPORT)
            else
                doPlayerSendCancel(cid, "test123")
            end
        elseif item.itemid == 1946 then
            doTransformItem(item.uid, item.itemid-1)
        else
            return false
        end
    else
        print("wrong uid")
    end
else
doPlayerSendCancel(cid, "Hey, nobody is here!")
    return true
end

Best solution is to use a better function to check if there's a player there (Depends on if tfs 1.1 or not..)

Code:
local topPlayer = Tile(pos):getTopCreature()
if topPlayer ~= nil then
 
Last edited:
When using the lever and no player is on the position i get player not found, need a better way to check it, otherwise my console gets spammed with this error message:
LuaScriptInterface::internalGetPlayerInfo(). Player not found.

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

    leverUID = 1337
    playerPos = {x = 10, y = 20, z = 30, stackpos = 253}
    getPlayerPos = getThingFromPos(playerPos)

    newPos = {x = 30, y = 50, z = 100}

    if item.uid == leverUID then
        if item.itemid == 1945 then
            if getPlayerPos.itemid > 0 then
                doTeleportThing(getPlayerPos.uid, newPos)
                doSendMagicEffect(playerPos, CONST_ME_TELEPORT)
            else
                doPlayerSendCancel(cid, "test123")
            end
        elseif item.itemid == 1946 then
            doTransformItem(item.uid, item.itemid-1)
        else
            return false
        end
    else
        print("wrong uid")
    end

    return true
end
Code:
thing = getThingfromPos(position)
if isPlayer(thing.uid) == true then
 
Back
Top