Comparing inventories.

Discussion in 'Fallout General Modding' started by Zorchar, Feb 14, 2020.

  1. Zorchar

    Zorchar First time out of the vault

    46
    Jun 18, 2018
    Hi guys.

    I am trying to check if a critter's inventory after barter is the same as before barter. I've tried this code
    the variables are declared in the begining of the script, so I guess they are saved between procedures, right?
    Code:
    variable inv1;
    variable inv2;
    variable inv3;
    
    procedure barter1 begin
    
       move_obj_inven_to_obj(self_obj, inv1);
       inv2 := inv1;
       move_obj_inven_to_obj(inv2, self_obj);
    
       gdialog_mod_barter(0);
    
    
         call Node006;
    
    end
    
    procedure Node006 begin
       Reply(mstr(600));
    
       NOption(601,Node007,004);
    
    end
    // did or didnt trade anything
    procedure Node007 begin
    
       move_obj_inven_to_obj(self_obj, inv3);
    
       if inv1 == inv3 then
          Reply(mstr(700));
    
       else
          Reply(mstr(800));
    
       GOption(801,Node999,004);
       NOption(1121,Node999,004);
       BOption(1122,Node998,004);
    
       move_obj_inven_to_obj(inv3, self_obj);
    end
    
    The extra steps are there just becuase I tried simpler versions of basiclly the same code just to make sure the conditions are checked in the right status.

    So, about the result. It dosent matter if I trade any item with the critter or not, I always get messege 700, which happans if inv1 == inv3, as stated in the code.

    Any help? much appriciated
     
  2. Lexx

    Lexx Background Radiant
    Moderator Modder

    Apr 24, 2005
    This doesn't work. Looking at the script you've posted, of course you will get Reply(700) (no need for mstr() here). All 3 of your variables start out as 0, there is nothing in the code that makes them NOT 0, even your inv2 := inv1 is just "make 0 to 0" in this context. So once it later checks if inv1 == inv3, it returns true, because all of them are... 0.

    Besides, move_obj_inven_to_obj() - which is used to MOVE stuff around - requires pointers, and in the context, inv1/2 aren't pointers. Truth told, I'm surprised the game doesn't just crash on you.

    As far as I am aware, you can't just throw the inventory of a critter into a variable and call it a day. You will have to cycle through each item and then compare the results. I'm guessing the easiest would be to just compare the monetary value that a critter has. So you read the price of every items proto and add them up. The result is what you compare. However, it might be possible for the player to buy/sell enough stuff that accidentally the inventory value is exactly the same (no clue how high the chances are), so you might as well compare the total item weight / size stats, just to be sure.

    It's lots of work for a different Reply() text. You sure it's worth it?
     
  3. Zorchar

    Zorchar First time out of the vault

    46
    Jun 18, 2018
    Thanks Lexx.

    It does sound like a lot of work, but maybe ill make a macro out of it and use it for other stuff. maybe:)
     
  4. burn

    burn Mildly Dipped
    Modder

    522
    Apr 22, 2012
    Check out Den orphans code for iterating over inventory.
     
  5. Zorchar

    Zorchar First time out of the vault

    46
    Jun 18, 2018

    Whoa. Thanks burn. Looks like I can learn a few tricks about other stuff also.
     
  6. Nirran

    Nirran Vault Senior Citizen
    Modder

    Apr 15, 2007
    i havent tested this or compiled,but it will compare inventory count of before barter - after barter,so if items swapped are the same number,it will fail to return a different value,but it should work

    Code:
    variable inv1;
    variable inv2;
    
    procedure barter1 begin
    
       
       inv1 := critter_inven_obj(self_obj, -2);//set inv1 to inventory count of self object
    
       gdialog_mod_barter(0);
    
    
         call Node006;
    
    end
    
    procedure Node006 begin
       Reply(mstr(600));
    
       NOption(601,Node007,004);
    
    end
    // did or didnt trade anything
    procedure Node007 begin
    
       inv2 := critter_inven_obj(self_obj, -2);//set inv2 to inventory count of self object
    
       if inv1 == inv2 then
          Reply(mstr(700));
    
       else
          Reply(mstr(800));
    
       GOption(801,Node999,004);
       NOption(1121,Node999,004);
       BOption(1122,Node998,004);
    end
     
    • [Rad] [Rad] x 1
  7. Lexx

    Lexx Background Radiant
    Moderator Modder

    Apr 24, 2005
    With inventory count you mean the amount of items? That can cause the issue I mentioned in my post - if you just swap items with him, the game will think the inventory hasn't changed, while in fact it did. :>
     
  8. Zorchar

    Zorchar First time out of the vault

    46
    Jun 18, 2018
    Works just as you guys said, so not ideal, but useful. Thanks Nirran.