C++ Look ignore tile

Discussion in 'Support' started by Huntre, Jan 4, 2018.

  1. Huntre

    Huntre Member

    Joined:
    Mar 22, 2011
    Messages:
    50
    Likes Received:
    1
    Best Answers:
    0
    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.


    Code (C++):
    1. if (Creature* creature = thing->getCreature()) {
    2.     LuaScriptInterfacePushUserdata<Creature>(L, creature);
    3.     LuaScriptInterface::setCreatureMetatable(L, -1, creature);
    4. } else if (Item* item = thing->getItem()) {
    5.     Tile* tile = g_game.map.getTile(position);
    6.     Item* item = g_game.findItemOfType(tile, 10300, false, -1);
    7.     if (!item) {
    8.         LuaScriptInterfacePushUserdata<Item>(L, item);
    9.         LuaScriptInterface::setItemMetatable(L, -1, item);
    10.     }
    11. } else {
    12.     lua_pushnil(L);
    13. }
     
    Last edited by a moderator: Jan 7, 2018
  2. Peonso

    Peonso 1337

    Joined:
    Jan 14, 2008
    Messages:
    1,185
    Likes Received:
    660
    Best Answers:
    12
    You set the ignore look flag in Tibia.dat, you can use ObjectBuilder.
     
  3. Huntre

    Huntre Member

    Joined:
    Mar 22, 2011
    Messages:
    50
    Likes Received:
    1
    Best Answers:
    0
    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.
     

    Attached Files:

    Last edited: Jan 8, 2018
  4. Summ

    Summ (\/)(;,,;)(\/) Y not? Staff Member Global Moderator

    Joined:
    Oct 15, 2008
    Messages:
    4,138
    Likes Received:
    1,042
    Best Answers:
    2
    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.

    Code (C++):
    1.  
    2. Thing* Tile::getTopVisibleThing(const Creature* creature)
    3. {
    4.     Thing* thing = getTopVisibleCreature(creature);
    5.     if (thing) {
    6.         return thing;
    7.     }
    8.  
    9.     TileItemVector* items = getItemList();
    10.     if (items) {
    11.         for (ItemVector::const_iterator it = items->getBeginDownItem(), end = items->getEndDownItem(); it != end; ++it) {
    12.             const ItemType& iit = Item::items[(*it)->getID()];
    13.             if (!iit.lookThrough) {
    14.                 return (*it);
    15.             }
    16.         }
    17.  
    18.         for (auto it = ItemVector::const_reverse_iterator(items->getEndTopItem()), end = ItemVector::const_reverse_iterator(items->getBeginTopItem()); it != end; ++it) {
    19.             const ItemType& iit = Item::items[(*it)->getID()];
    20.             if (!iit.lookThrough) {
    21.                 return (*it);
    22.             }
    23.         }
    24.     }
    25.  
    26.     if (!ground) {
    27.         return nullptr;
    28.     }
    29.  
    30.     return Item::items[ground->getID()].lookThrough ? nullptr : ground;
    31. }
    32.  
    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
     
  5. Huntre

    Huntre Member

    Joined:
    Mar 22, 2011
    Messages:
    50
    Likes Received:
    1
    Best Answers:
    0
    It still does not show the description below the ground (id- 406) .

    Code (C++):
    1. Thing* Tile::getTopVisibleThing(const Creature* creature)
    2. {
    3.     Thing* thing = getTopVisibleCreature(creature);
    4.     if (thing) {
    5.         return thing;
    6.     }
    7.  
    8.     TileItemVector* items = getItemList();
    9.     if (items) {
    10.         for (ItemVector::const_iterator it = items->getBeginDownItem(), end = items->getEndDownItem(); it != end; ++it) {
    11.             const ItemType& iit = Item::items[(*it)->getID()];
    12.             if (!iit.lookThrough) {
    13.                 return (*it);
    14.             }
    15.         }
    16.  
    17.         for (auto it = ItemVector::const_reverse_iterator(items->getEndTopItem()), end = ItemVector::const_reverse_iterator(items->getBeginTopItem()); it != end; ++it) {
    18.             const ItemType& iit = Item::items[(*it)->getID()];
    19.             if (!iit.lookThrough) {
    20.                 return (*it);
    21.             }
    22.         }
    23.     }
    24.  
    25.     if (!ground) {
    26.         return nullptr;
    27.     }
    28.  
    29.     return Item::items[ground->getID()].lookThrough ? nullptr : ground;
    30. }



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

    error :

    Code (Lua):
    1. [Warning - Items::parseItemNode] Unknown key value: lookThrough
    Code (C++):
    1.         } else if (tmpStrValue == "readable") {
    2.             it.canReadText = valueAttribute.as_bool();
    3.         }else if (tmpStrValue == "lookThrough") {
    4.             it.lookThrough = valueAttribute.as_bool();
    5.         } else if (tmpStrValue == "writeable") {
    6.             it.canWriteText = valueAttribute.as_bool();
    7.             it.canReadText = it.canWriteText;
    xml:
    Code (Lua):
    1.     <item id="406" name="white marble floor">
    2.         <attribute key="lookThrough" value="1" />
    3.     </item>
    Editores:
    Sem título.png

    Look server

    look.png
     
    Last edited: Jan 12, 2018
  6. Huntre

    Huntre Member

    Joined:
    Mar 22, 2011
    Messages:
    50
    Likes Received:
    1
    Best Answers:
    0
    help?
     
  7. Itutorial

    Itutorial Well-Known Member

    Joined:
    Dec 23, 2014
    Messages:
    1,153
    Likes Received:
    206
    Best Answers:
    16
    You could add something like this in events/scripts/player.lua

    in the onLook function

    Code (Lua):
    1.  
    2. for i = thing:getPosition().z, -15 do
    3.                     local pos = {x = thing:getPosition().x, y = thing:getPosition().y, z = i}
    4.                     ITEM = Tile(pos):getThing()
    5.                         if ITEM ~= nil and not ITEM:hasFlag(FLAG_LOOKTHROUGH) then
    6.                             thing = ITEM
    7.                             break
    8.                         end
    9.             end
    10.  
     
    Last edited: Jan 12, 2018
  8. Huntre

    Huntre Member

    Joined:
    Mar 22, 2011
    Messages:
    50
    Likes Received:
    1
    Best Answers:
    0
    Unfortunately this also did not solve how simple item I can get the look below, but how much is an item ground not work.
     
  9. Itutorial

    Itutorial Well-Known Member

    Joined:
    Dec 23, 2014
    Messages:
    1,153
    Likes Received:
    206
    Best Answers:
    16
    Im sure there is sometype of function like ITEM:getCount()
     
  10. Huntre

    Huntre Member

    Joined:
    Mar 22, 2011
    Messages:
    50
    Likes Received:
    1
    Best Answers:
    0
    Code (Lua):
    1. function Player:onLook(thing, position, distance)
    2.  
    3.  
    4.     for i = thing:getPosition().z, -15 do
    5.         local pos = {x = thing:getPosition().x, y = thing:getPosition().y, z = i}
    6.         ITEM = Tile(pos):getThing()
    7.         if ITEM ~= nil and not ITEM:hasFlag(FLAG_LOOKTHROUGH) then
    8.             thing = ITEM
    9.             break
    10.         end
    11.     end
    12.  
    13.     description = "You see " .. thing:getDescription(distance)
    14.     --if self:getGroup():getAccess() then
    15.         if thing:isItem() then
    16.             description = string.format("%s\nItem ID: %d", description, thing:getId())
    17.             local actionId = thing:getActionId()
    18.             if actionId ~= 0 then
    19.                 description = string.format("%s, Action ID: %d", description, actionId)
    20.             end
    21.             local uniqueId = thing:getAttribute(ITEM_ATTRIBUTE_UNIQUEID)
    22.             if uniqueId > 0 and uniqueId < 65536 then
    23.                 description = string.format("%s, Unique ID: %d", description, uniqueId)
    24.             end
    25.             local itemType = thing:getType()
    26.             local transformEquipId = itemType:getTransformEquipId()
    27.             local transformDeEquipId = itemType:getTransformDeEquipId()
    28.             if transformEquipId ~= 0 then
    29.                 description = string.format("%s\nTransforms to: %d (onEquip)", description, transformEquipId)
    30.             elseif transformDeEquipId ~= 0 then
    31.                 description = string.format("%s\nTransforms to: %d (onDeEquip)", description, transformDeEquipId)
    32.             end
    33.             local decayId = itemType:getDecayId()
    34.             if decayId ~= -1 then
    35.                 description = string.format("%s\nDecays to: %d", description, decayId)
    36.             end
    37.         elseif thing:isCreature() then
    38.             local str = "%s\nHealth: %d / %d"
    39.             if thing:getMaxMana() > 0 then
    40.                 str = string.format("%s, Mana: %d / %d", str, thing:getMana(), thing:getMaxMana())
    41.             end
    42.             description = string.format(str, description, thing:getHealth(), thing:getMaxHealth()) .. "."
    43.             local position = thing:getPosition()
    44.             description = string.format("%s\nPosition: %d, %d, %d",description, position.x, position.y, position.z)
    45.             if thing:isCreature() then
    46.                 if thing:isPlayer() then
    47.                     description = string.format("%s\nIP: %s.", description, Game.convertIpToString(thing:getIp()))
    48.                 end
    49.             end
    50.         end
    51.         self:sendTextMessage(MESSAGE_INFO_DESCR, description)
    52.     --end
    53. end


    It was not and without erros.

    Sem título.png
     
  11. Huntre

    Huntre Member

    Joined:
    Mar 22, 2011
    Messages:
    50
    Likes Received:
    1
    Best Answers:
    0

Share This Page

Loading...