Advertisement
Guest User

DayZ: find item in player inventory

a guest
Jan 24th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.28 KB | None | 0 0
  1.     bool CheckItem(PlayerBase player, string itemClass)
  2.     {
  3.         EntityAI attachment, subattachment; //attachments variables
  4.         int AttCount, SubAttCount; //attachments count variables
  5.         ItemBase subItem; //Item variable
  6.         string className; //Item class name variable
  7.         bool itemFound = false; // Result / default is false
  8.        
  9.         AttCount = player.GetInventory().AttachmentCount(); //Player Attachments (items on player, like clothes, backpack etc.) count for cycle
  10.         for ( int i = 0; i < AttCount; i++ ) //Check Attachments cycle
  11.         {
  12.             attachment = player.GetInventory().GetAttachmentFromIndex(i); // Get player attachment
  13.  
  14.             SubAttCount = attachment.GetInventory().AttachmentCount(); //How many subattachments in player attachment - count for cycle
  15.             for ( int a = 0; a < SubAttCount; a++ )
  16.             {
  17.                 subattachment = attachment.GetInventory().GetAttachmentFromIndex(a); // Get subattachment in attachment
  18.                 subItem = ItemBase.Cast(subattachment); //Cast subattachment to item
  19.                 className = subItem.GetType(); //Get class name of subattachment
  20.                 if ( className == itemClass ) //Check class of item (subattachment)
  21.                 {
  22.                      itemFound = true; //Item found!
  23.                      break; //break 2nd cycle
  24.                 }
  25.             }
  26.             if (mapFound) break; //break 1st cycle
  27.         }
  28.         return itemFound; //return result
  29.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement