View unanswered posts | View active topics It is currently Thu Mar 28, 2024 7:53 pm



Reply to topic  [ 3 posts ] 
 Transferring Inventory 
Author Message
DRL Developer
DRL Developer
User avatar

Joined: Thu Jun 11, 2009 2:34 pm
Posts: 966
Location: Moscow, Russia
Reply with quote
Post 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



Sun Oct 21, 2012 2:57 pm
Profile
DRL Developer
DRL Developer
User avatar

Joined: Thu Jun 11, 2009 2:34 pm
Posts: 966
Location: Moscow, Russia
Reply with quote
Post Re: Transferring Inventory
You can send me what you're making and I can try to put everything together if it looks too hard.


Sun Oct 21, 2012 4:37 pm
Profile
DRL Developer
DRL Developer
User avatar

Joined: Thu Jun 11, 2009 2:34 pm
Posts: 966
Location: Moscow, Russia
Reply with quote
Post 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


Sun Oct 21, 2012 6:55 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.045s | 15 Queries | GZIP : Off ]