I've been working on a house class, on and off, for a while. It's been frustrating me a bit so I feel like venting a bit.
First a bit about what I've done so far. I created a house class with some function. So far the functions include
Code: Select all
house:findItem(name) -- Searches all house storage chests including servant inventories.
house:findEquipedItem(name) -- Searches servant equipped items.
house:itemTotalCount(name) -- Counts how many of an item there are in all the house storages.
Servants are stored in a sub table house.Servants and you can use similar functions on the servants to search only the servants, eg.
Code: Select all
servant = house.Servant[1]
servant:findItem(name)
servant:findEquipedItem(name)
servant:itemTotalCount(name)
Storage devices such as chests are stored in house.Chests and you can use the following functions,
Code: Select all
chest = house.Chests[1]
chest:findItem(name)
chest:itemTotalCount(name)
All the search functions return an item table including the following information
Code: Select all
item.DBID -- This is the container identifier.
item.BagId -- The slot in the container where the item is.
item.Name -- The item name
item.ItemCount -- The stack amount.
This class only uses in game functions so the returned data is limited. Each item has the following functions so far.
Code: Select all
item:pickup() -- Picks up the item
item:draw() -- Moves item directly to your inventory.
item:delete() -- Deletes the item.
This works without opening any containers. I got most of this done before I realized sometimes it couldn't see what is in the containers without opening them first at least once. So now I'm resigned to the fact that I have to open the chests first before the class functions start working properly. Turns out that's not too easy to do but I finally got it working. Turns out to successfully open the chest the client window needs to be in the foreground, the mouse needs to be over the object and you have to move the mouse a bit over the object first. Then you can do a player:target_NPC("chestname") and it will open correctly. Bit of a pain but now I have another issue. I have no way to tell which object in the house corresponds to which furniture in the furniture drop down list. So if I want to open a chest to populate it's contents, I have no idea which object it is. I've been working on this a couple of days now including memory searches so I don't think I'll find a solution for this. The only idea I can think of is, when the user does a house:update() it goes to every object in the house and tries to open it. Once it's opened all the containers it should be able to use the functions normally. This assumes that all the chests will be accessible from the one location.
That's enough venting. Feel free to comment on your thought about the class.