Deprecated: The behavior of unparenthesized expressions containing both '.' and '+'/'-' will change in PHP 8: '+'/'-' will take a higher precedence in /home/iano/public_html/tpforums-vb5/forum/includes/class_core.php on line 5842

PHP Warning: Use of undefined constant MYSQL_NUM - assumed 'MYSQL_NUM' (this will throw an Error in a future version of PHP) in ..../includes/init.php on line 165

PHP Warning: Use of undefined constant MYSQL_ASSOC - assumed 'MYSQL_ASSOC' (this will throw an Error in a future version of PHP) in ..../includes/init.php on line 165

PHP Warning: Use of undefined constant MYSQL_BOTH - assumed 'MYSQL_BOTH' (this will throw an Error in a future version of PHP) in ..../includes/init.php on line 165

PHP Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in ..../includes/functions_navigation.php on line 588

PHP Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in ..../includes/functions_navigation.php on line 612

PHP Warning: Use of undefined constant misc - assumed 'misc' (this will throw an Error in a future version of PHP) in ..../global.php(29) : eval()'d code(6) : eval()'d code on line 1

PHP Warning: Use of undefined constant index - assumed 'index' (this will throw an Error in a future version of PHP) in ..../global.php(29) : eval()'d code(6) : eval()'d code on line 1

PHP Warning: Use of undefined constant misc - assumed 'misc' (this will throw an Error in a future version of PHP) in ..../includes/class_bootstrap.php(1422) : eval()'d code(4) : eval()'d code on line 1

PHP Warning: Use of undefined constant index - assumed 'index' (this will throw an Error in a future version of PHP) in ..../includes/class_bootstrap.php(1422) : eval()'d code(4) : eval()'d code on line 1

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6
[C] Reading Tile on map
Results 1 to 7 of 7

Thread: [C] Reading Tile on map

  1. #1

    [C] Reading Tile on map

    Hi all, I have a slight problem. I'm trying to read items/objects on a specific tile for finding the body of a slain monster, below is the function I'm using.

    The problem is;
    If I slay a monster, the bot will open the corpse. But if another monster is slain on the same tile while the container from the first slain monster is still opened, the first container will be closed and the latest monsters corpse will not be opened. Which indicates that the bot is trying to open the corpse from the first slain monster. Which would mean that my stack position is wrong.

    Code:
    // nTile is the TileNumber of the slain creature, this TileNumber is always correct and this function is called after the creature has transformed into a corpse. I am using 8.6 addresses and distances.
    BOOL getCorpseId(short nTile)
    {
    	int TileAddr, TileItems, ItemId, i;
            
            // Address to the tile itself
    	TileAddr  = va_MapAddress + (nTile * TILE_STEP);
            // Number of items on the specific tile
    	TileItems = ReadTibiaMemory(TileAddr);
    
            // Read tile items, top to bottom
    	for(i = (TileItems - 1); i >= 0; i--)
    	{
    		ItemId = ReadTibiaMemory(TileAddr + 4 + i * 12);
    
                    // Compare the itemid to .DAT input, is the item a container?
    		if(gTibiaObject[ItemId].IsContainer)
    		{
                            // I'm not entirely sure how the
                            // objects on a tile is stored in memory.
                            // I'm assuming that the top object has the stack position
                            // of TileItems, this seems to be wrong and I cannot find
                            // find any information on exactly how items on tiles
                            // is stored in memory and I can't seem to work out any 
                            // logical answer to it either by checking packets sent 
                            // from the client when right-clicking the corpse.
    			gTarget.nStackPos = i;
    			gTarget.nCorpseId = ItemId;
    
    			return TRUE;
    		}
    	}
    
    	return FALSE;
    }

  2. #2

    RE: [C] Reading Tile on map

    Sorry for double but I have now changed the code a bit, but I also noticed this;

    i = current item on tile (3 objects here)

    i: 0 -> itemid: 353 -> 0 // Ground I suppose
    i: 1 -> itemid: 2886 -> 1 // Should be blood? But I can't seem to find what ID 2886 is nor why the IsContainer flag is set. Does this mean that I am reading the DAT file wrong?
    i: 2 -> itemid: 5964 -> 1 // Dead rat

    Sometimes I get this as output instead;

    i: 0 -> itemid: 353 -> 0 // Ground I suppose
    i: 1 -> itemid: 2886 -> 1 // Should be blood, but I cannot find out what 2886 is.
    i: 2 -> itemid: 3994 -> 1 // Should be dead rat, but I cannot find out what 3994 is.

    The code I'm currently using;
    Code:
    BOOL getCorpseId(short nTile)
    {
    	int TileAddr, TileItems, ItemId, i;
         
    	TileAddr  = va_MapAddress + (nTile * 168);
    	TileItems = ReadTibiaMemory(va_MapAddress + (nTile * 168));
    
    	for(i = 0; i < TileItems; i++)
    	{
    		ItemId = ReadTibiaMemory(TileAddr + i * 12 + 4);
    
    		if(gTibiaObject[ItemId].IsContainer)
    		{
    			gTarget.nStackPos = i;
    			gTarget.nCorpseId = ItemId;
    
    			//return TRUE; // Commented for debugging purposes, so I can print out all the items on the tile.
    		}
    	}
    
    	return FALSE;
    }

  3. #3

    RE: [C] Reading Tile on map

    Sorry for triple but now I got the hang of it, this screenshot will explain;

    Item 4 is the latest monster slain (based on the packet sent from the client when I right clicked the corpse on top), item 5 is the 100GP I placed on the body of rat on Item 6. For some reason 2886 (In this case Blood) has the IsContainer flag set, I'm not entierly sure why, 2886 seems to be the corpse of a firedevil, but every other flag / dat data stored in my structure seems to be correct except from this one.


  4. #4
    Senior Member
    Join Date
    Jan 2012
    Posts
    417

    RE: [C] Reading Tile on map

    your .dat seems to be wrong or maybe your is container flag is wrong.

    some results I got:

    item id: 2886
    item flags: 10244
    IsContainer flag: 16
    item is container? False

    and yes, I checked out the sprite and it is blood.

    EDIT: I'm reading the .dat from memory. If you are following Jo3's .dat parser, his IsContainer flag is 4, that means 2^4 = 16.

  5. #5

    RE: [C] Reading Tile on map

    No, I'm not following Joes dat parser, I'm using 8.6 as stated and 0x4 seems to be the flag stored in file for IsContainer, code follows;

    Code:
    struct _TIBIAOBJECT {
           long id;
           BOOL IsBlocking;
           BOOL IsContainer;
    } * gTibiaObject;
    
    void ReadTilesBin()
    {
        BYTE width, height, blendframes, xrepeat, yrepeat, zrepeat, animations, buf;
        long spriteCount, i;
        FILE * f;
        
    	unsigned char signature[4], nItemFlags;
    	short nDatItems, nDatCreatures, nDatMissiles, nDatEffects;
    	int nDatTotalItems, nItemCounter;
    
        f = fopen("tiles.bin", "rb");
        signature[0] = fgetc(f);
        signature[1] = fgetc(f);
        signature[2] = fgetc(f);
        signature[3] = fgetc(f);
        
        fread(&nDatItems, 1, 2, f);
        fread(&nDatCreatures, 1, 2, f);
        fread(&nDatEffects, 1, 2, f);
        fread(&nDatMissiles, 1, 2, f);
      
        nDatTotalItems = nDatItems + nDatCreatures + nDatEffects + nDatMissiles;
        gTibiaObject = malloc(sizeof(struct _TIBIAOBJECT) * nDatTotalItems);
        
        for(nItemCounter = 100; nItemCounter < (nDatTotalItems - 99); nItemCounter++)
        {
             gTibiaObject[nItemCounter].id = nItemCounter;
             
             do {
                 nItemFlags = (unsigned char)fgetc(f);
                 
                 if(nItemFlags == 0xC)
                    gTibiaObject[nItemCounter].IsBlocking = TRUE;
                 
                 if(nItemFlags == 0x4)
                    gTibiaObject[nItemCounter].IsContainer = TRUE;
                 
             } while(nItemFlags != 0xFF);
             
             width = fgetc(f);
             height = fgetc(f);
             if(width > 1 || height > 1) { fgetc(f); }
             blendframes = fgetc(f);
             xrepeat = fgetc(f);
             yrepeat = fgetc(f);
             zrepeat = fgetc(f);
             animations = fgetc(f);
             
             spriteCount = (width * height * blendframes * xrepeat * yrepeat * zrepeat * animations * 2);
    
             for(i = 0; i < spriteCount-1; i++)
                 fread(&buf, 1, 1, f);
        }
        
        fclose(f);
    
        return;
    }

  6. #6
    Senior Member
    Join Date
    Jan 2012
    Posts
    417

    RE: [C] Reading Tile on map

    your code seems to be ok, I just didn't understand the line

    spriteCount = (width * height * blendframes * xrepeat * yrepeat * zrepeat * animations * 2);

    specificaly the 2 at end. Maybe it is messing the reading.

    EDIT: I suggest you read http://tpforums.org/forum/thread-9308.html . I know it is for a newer version than yours, but in some flags it reads extra bytes and for sure will give you some tips.

  7. #7

    RE: [C] Reading Tile on map

    I see, seems like the cause is due to;

    For example, the light-flag is followed by brightness and color of the light bytes. My reader doesn't know that those two bytes is part of the light-flag therefore it'll think that 0x4 if found among the following light-flag bytes is a container flag. So now it's fixed, thanks for the tips.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •