Data Realms Fan Forums
http://45.55.195.193/

Transferring Inventory
http://45.55.195.193/viewtopic.php?f=73&t=31975
Page 1 of 1

Author:  weegee [ Sun Oct 21, 2012 2:57 pm ]
Post subject:  Re: Transferring Inventory

You can try this function to get inventory and clear it in source actor, and transfering items to another actor is trivial I guess

Code:
-----------------------------------------------------------------------------------------
-- Get table with inventory of actor, inventory cleared as a result
-----------------------------------------------------------------------------------------
function CF_GetInventory(actor)
   --print("GetInventory")
   local inventory = {}
   local classes = {}

   if MovableMan:IsActor(actor) then
      if actor.ClassName == "AHuman" then
         local human = ToAHuman(actor);
         
         if human ~= nil then
            if human.EquippedItem ~= nil then
               inventory[#inventory + 1] = human.EquippedItem.PresetName;
               classes[#classes + 1] = human.EquippedItem.ClassName;
            end
            
            human:UnequipBGArm()
         end
      end
      
      if not actor:IsInventoryEmpty() then
         local enough = false;
         while not enough do
            local weap = nil;
         
            weap = actor:SwapNextInventory(weap, true);
            
            if weap == nil then
               enough = true;
            else
               inventory[#inventory + 1] = weap.PresetName;
               classes[#classes + 1] = weap.ClassName;
            end
         end
      end
   else
      --print("Actor: ")
      --print(actor);
   end
   
   return inventory, classes;
end


Author:  weegee [ Sun Oct 21, 2012 4:37 pm ]
Post subject:  Re: Transferring Inventory

You can send me what you're making and I can try to put everything together if it looks too hard.

Author:  weegee [ Sun Oct 21, 2012 6:55 pm ]
Post subject:  Re: Transferring Inventory

Transfering script will look like this:

Code:
local presets, classes = CF_GetInventory(source_actor)

for i = 1, #presets do
   local itm;
   
   if classes[i] == "HDFirearm" then
      itm = CreateHDFirearm(presets[i])
   elseif classes[i] == "TDExplosive" then
      itm = CreateTDExplosive(presets[i])
   elseif classes[i] == "HeldDevice" then
      itm = CreateHeldDevice(presets[i])
   end
   
   if itm ~= nil then
      dest_actor:AddInventoryItem(itm)
   end
end

Page 1 of 1 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/