Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class TINV_Item {
- // SubInventory fields
- var SubInventory;
- var SlotX, SlotY;
- // Item data
- var Width, Height;
- var RegisteredItemId; // Index to the item table in TINV.RegisteredItems
- var Model;
- var Class = "prop_physics";
- var MaterialType; // Used for playing sounds
- var BoundsMin; // Sent to the client to render items properly
- var BoundsMax; // Same as above
- var Rotation; // Same as above
- // Custom data
- var ServerData = { };
- var SharedData = { };
- /*
- Constructor
- */
- function TINV_Item(prop) {
- // For testing purposes
- if(prop == "test") {
- this:GenerateTest();
- return;
- }
- if(prop == "networked")
- return;
- if(!IsEntity(prop))
- error("TINV Error: Item not initialized properly! Prop is null or not an entity.");
- this:InitProp(prop);
- }
- /*
- Initialization
- */
- function InitProp(prop) {
- this.Model = prop:GetModel();
- this.Class = prop:GetClass();
- this.MaterialType = prop:GetMaterialType();
- this.Width, this.Height, this.Rotation, this.BoundsMin, this.BoundsMax = TINV.CalculateItemSize(prop);
- // TODO: Calculate sizes and save data
- }
- /*
- Creates and returns an entity reconstructed from item data. Created entity is not spawned.
- */
- function CreateEntity() {
- var ent = ents.Create(this.Class);
- ent:SetModel(this.Model);
- if(TINV.RegisteredItems[this.RegisteredItemId].LoadData)
- TINV.RegisteredItems[this.RegisteredItemId].LoadData(ent, this.ServerData, this.SharedData);
- return ent;
- }
- /*
- Update inventory, called by subinventory.
- */
- function UpdateSubInventory(subInv, x, y) {
- this.SubInventory = subInv;
- this.SlotX, this.SlotY = x, y;
- }
- /*
- Generates a sample item, with random model and size.
- */
- function GenerateTest() {
- var models = {
- { "models/alyx.mdl", 2, 5 },
- { "models/props_borealis/bluebarrel001.mdl", 2, 4 },
- { "models/Combine_Helicopter/helicopter_bomb01.mdl", 2, 2 },
- { "models/props_interiors/Furniture_chair01a.mdl", 1, 3 },
- };
- var rand = table.Random(models);
- this.Model = rand[1];
- this.Width, this.Height = rand[2], rand[3];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement