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

C++ Look ignore tile

Huntre

Member
Joined
Mar 22, 2011
Messages
70
Solutions
1
Reaction score
8
I have a question and it is possible to ignore an item in a look.
ex: I'm on floor 4 and look at item in floot 7 but between that item has the item x and possible to ignore this item x and get the item below?
If it is possible how I should do it until I changed the event of the look, the most I could do was not show.


C++:
if (Creature* creature = thing->getCreature()) {
    LuaScriptInterfacePushUserdata<Creature>(L, creature);
    LuaScriptInterface::setCreatureMetatable(L, -1, creature);
} else if (Item* item = thing->getItem()) {
    Tile* tile = g_game.map.getTile(position);
    Item* item = g_game.findItemOfType(tile, 10300, false, -1);
    if (!item) {
        LuaScriptInterfacePushUserdata<Item>(L, item);
        LuaScriptInterface::setItemMetatable(L, -1, item);
    }
} else {
    lua_pushnil(L);
}
 
Last edited by a moderator:
If I do it this way it does not take the look of the item below and that message is

Edit:

I found that if the item is isgroud it does not work the ignore look has how do I get it through the server or only can be by the ObjectBuilder.

Screenshot_2.png
 
Last edited:
Assuming that you use TFS 1.3, you have to modify Tile::getTopVisibleThing ( forgottenserver/tile.cpp at master · otland/forgottenserver · GitHub ) to something like the following. This allows for the ground to have the property lookThrough as well.

C++:
Thing* Tile::getTopVisibleThing(const Creature* creature)
{
    Thing* thing = getTopVisibleCreature(creature);
    if (thing) {
        return thing;
    }

    TileItemVector* items = getItemList();
    if (items) {
        for (ItemVector::const_iterator it = items->getBeginDownItem(), end = items->getEndDownItem(); it != end; ++it) {
            const ItemType& iit = Item::items[(*it)->getID()];
            if (!iit.lookThrough) {
                return (*it);
            }
        }

        for (auto it = ItemVector::const_reverse_iterator(items->getEndTopItem()), end = ItemVector::const_reverse_iterator(items->getBeginTopItem()); it != end; ++it) {
            const ItemType& iit = Item::items[(*it)->getID()];
            if (!iit.lookThrough) {
                return (*it);
            }
        }
    }

    if (!ground) {
        return nullptr;
    }

    return Item::items[ground->getID()].lookThrough ? nullptr : ground;
}

If you don't want to modify your items.otb, you can also assign the lookThrough property through items.xml by adding a check similar to this: forgottenserver/items.cpp at master · otland/forgottenserver · GitHub
 
It still does not show the description below the ground (id- 406) .

C++:
Thing* Tile::getTopVisibleThing(const Creature* creature)
{
    Thing* thing = getTopVisibleCreature(creature);
    if (thing) {
        return thing;
    }

    TileItemVector* items = getItemList();
    if (items) {
        for (ItemVector::const_iterator it = items->getBeginDownItem(), end = items->getEndDownItem(); it != end; ++it) {
            const ItemType& iit = Item::items[(*it)->getID()];
            if (!iit.lookThrough) {
                return (*it);
            }
        }

        for (auto it = ItemVector::const_reverse_iterator(items->getEndTopItem()), end = ItemVector::const_reverse_iterator(items->getBeginTopItem()); it != end; ++it) {
            const ItemType& iit = Item::items[(*it)->getID()];
            if (!iit.lookThrough) {
                return (*it);
            }
        }
    }

    if (!ground) {
        return nullptr;
    }

    return Item::items[ground->getID()].lookThrough ? nullptr : ground;
}




while assigning the peek property through Items. xml gave console error.

error :

Lua:
[Warning - Items::parseItemNode] Unknown key value: lookThrough

C++:
        } else if (tmpStrValue == "readable") {
            it.canReadText = valueAttribute.as_bool();
        }else if (tmpStrValue == "lookThrough") {
            it.lookThrough = valueAttribute.as_bool();
        } else if (tmpStrValue == "writeable") {
            it.canWriteText = valueAttribute.as_bool();
            it.canReadText = it.canWriteText;

xml:
Lua:
    <item id="406" name="white marble floor">
        <attribute key="lookThrough" value="1" />
    </item>

Editores:
Sem título.png

Look server

look.png
 
Last edited:
You could add something like this in events/scripts/player.lua

in the onLook function

Lua:
for i = thing:getPosition().z, -15 do
                    local pos = {x = thing:getPosition().x, y = thing:getPosition().y, z = i}
                    ITEM = Tile(pos):getThing()
                        if ITEM ~= nil and not ITEM:hasFlag(FLAG_LOOKTHROUGH) then
                            thing = ITEM
                            break
                        end
            end
 
Last edited:
Unfortunately this also did not solve how simple item I can get the look below, but how much is an item ground not work.
 
Lua:
function Player:onLook(thing, position, distance)


    for i = thing:getPosition().z, -15 do
        local pos = {x = thing:getPosition().x, y = thing:getPosition().y, z = i}
        ITEM = Tile(pos):getThing()
        if ITEM ~= nil and not ITEM:hasFlag(FLAG_LOOKTHROUGH) then
            thing = ITEM
            break
        end
    end

    description = "You see " .. thing:getDescription(distance)
    --if self:getGroup():getAccess() then
        if thing:isItem() then
            description = string.format("%s\nItem ID: %d", description, thing:getId())
            local actionId = thing:getActionId()
            if actionId ~= 0 then
                description = string.format("%s, Action ID: %d", description, actionId)
            end
            local uniqueId = thing:getAttribute(ITEM_ATTRIBUTE_UNIQUEID)
            if uniqueId > 0 and uniqueId < 65536 then
                description = string.format("%s, Unique ID: %d", description, uniqueId)
            end
            local itemType = thing:getType()
            local transformEquipId = itemType:getTransformEquipId()
            local transformDeEquipId = itemType:getTransformDeEquipId()
            if transformEquipId ~= 0 then
                description = string.format("%s\nTransforms to: %d (onEquip)", description, transformEquipId)
            elseif transformDeEquipId ~= 0 then
                description = string.format("%s\nTransforms to: %d (onDeEquip)", description, transformDeEquipId)
            end
            local decayId = itemType:getDecayId()
            if decayId ~= -1 then
                description = string.format("%s\nDecays to: %d", description, decayId)
            end
        elseif thing:isCreature() then
            local str = "%s\nHealth: %d / %d"
            if thing:getMaxMana() > 0 then
                str = string.format("%s, Mana: %d / %d", str, thing:getMana(), thing:getMaxMana())
            end
            description = string.format(str, description, thing:getHealth(), thing:getMaxHealth()) .. "."
            local position = thing:getPosition()
            description = string.format("%s\nPosition: %d, %d, %d",description, position.x, position.y, position.z)
            if thing:isCreature() then
                if thing:isPlayer() then
                    description = string.format("%s\nIP: %s.", description, Game.convertIpToString(thing:getIp()))
                end
            end
        end
        self:sendTextMessage(MESSAGE_INFO_DESCR, description)
    --end
end



It was not and without erros.

Sem título.png

up

help
 
Last edited by a moderator:
Try changing:

Lua:
for i = thing:getPosition().z, -15 do
        local pos = {x = thing:getPosition().x, y = thing:getPosition().y, z = i}
        ITEM = Tile(pos):getThing()
        if ITEM ~= nil and not ITEM:hasFlag(FLAG_LOOKTHROUGH) then
            thing = ITEM
            break
        end
    end

to

Lua:
local i = thing:getPosition()
local canSee = i - 4
while (i > canSee) do
        local pos = {x = thing:getPosition().x, y = thing:getPosition().y, z = i}
        ITEM = Tile(pos):getThing()
        if ITEM ~= nil and not ITEM:hasFlag(FLAG_LOOKTHROUGH) then
            thing = ITEM
            break
        end
    i = i - 1
end
 
erro

Lua:
Lua Script Error: [Event Interface]
data/events/scripts/player.lua:Player@onLook
attempt to index a number value
stack traceback:
        [C]: at 0x7ff756bd3b90
        [C]: in function '__sub'
        data/events/scripts/player.lua:13: in function <data/events/scripts/player

Sem título.png
 
Last edited:
wups here

Lua:
local i = thing:getPosition().z
local canSee = i - 4
while (i > canSee) do
        local pos = {x = thing:getPosition().x, y = thing:getPosition().y, z = i}
        ITEM = Tile(pos):getThing()
        if ITEM ~= nil and not ITEM:hasFlag(FLAG_LOOKTHROUGH) then
            thing = ITEM
            break
        end
    i = i - 1
end
 
It was not and items that do not have the flag ta error.



Sem título.png


erro:

Lua:
Lua Script Error: [Event Interface]
data/events/scripts/player.lua:Player@onLook
data/events/scripts/player.lua:38: attempt to call method 'hasFlag' (a nil value)
stack traceback:
        [C]: in function 'hasFlag'
        data/events/scripts/player.lua:38: in function <data/events/scripts/player.lua:5>

Sem título.png
 
Lua:
local i = thing:getPosition().z
local canSee = i - 4
while (i > canSee) do
        local pos = {x = thing:getPosition().x, y = thing:getPosition().y, z = i}
        TILE = Tile(pos)
        if TILE ~= nil and not TILE:hasFlag(FLAG_LOOKTHROUGH) then
            thing = TILE:getThing()
            break
        end
    i = i - 1
end
 
ele ignora a aparência no jogador e eu adquirei o jogador mais e a terrar ei e não entendo.

Sem título.png Sem título.png


É terra

Sem título.png



Sem título.png
 
Last edited:

Tip: This is on OTClient's source, not on TFS's one.

I already fixed it on mine.
Are you able to compile your sources?
If yes, you can fix that also.

Note: If you expect me to see your answer for my message as I think you do, quote my message. Otherwise, I won't be notified.
 
Tip: This is on OTClient's source, not on TFS's one.

I already fixed it on mine.
Are you able to compile your sources?
If yes, you can fix that also.

Note: If you expect me to see your answer for my message as I think you do, quote my message. Otherwise, I won't be notified.
Sim tenho os fontes do otclient por favor me ajuda ta foda fazer isso
 
Back
Top