Advertisement
szymski

Untitled

Dec 30th, 2015
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. class TINV_Item {
  2.  
  3. // SubInventory fields
  4. var SubInventory;
  5. var SlotX, SlotY;
  6.  
  7. // Item data
  8. var Width, Height;
  9. var RegisteredItemId; // Index to the item table in TINV.RegisteredItems
  10. var Model;
  11. var Class = "prop_physics";
  12. var MaterialType; // Used for playing sounds
  13. var BoundsMin; // Sent to the client to render items properly
  14. var BoundsMax; // Same as above
  15. var Rotation; // Same as above
  16.  
  17. // Custom data
  18. var ServerData = { };
  19. var SharedData = { };
  20.  
  21. /*
  22. Constructor
  23. */
  24. function TINV_Item(prop) {
  25. // For testing purposes
  26. if(prop == "test") {
  27. this:GenerateTest();
  28. return;
  29. }
  30.  
  31. if(prop == "networked")
  32. return;
  33.  
  34. if(!IsEntity(prop))
  35. error("TINV Error: Item not initialized properly! Prop is null or not an entity.");
  36.  
  37. this:InitProp(prop);
  38. }
  39.  
  40. /*
  41. Initialization
  42. */
  43. function InitProp(prop) {
  44. this.Model = prop:GetModel();
  45. this.Class = prop:GetClass();
  46. this.MaterialType = prop:GetMaterialType();
  47. this.Width, this.Height, this.Rotation, this.BoundsMin, this.BoundsMax = TINV.CalculateItemSize(prop);
  48.  
  49.  
  50.  
  51. // TODO: Calculate sizes and save data
  52. }
  53.  
  54. /*
  55. Creates and returns an entity reconstructed from item data. Created entity is not spawned.
  56. */
  57. function CreateEntity() {
  58. var ent = ents.Create(this.Class);
  59. ent:SetModel(this.Model);
  60.  
  61. if(TINV.RegisteredItems[this.RegisteredItemId].LoadData)
  62. TINV.RegisteredItems[this.RegisteredItemId].LoadData(ent, this.ServerData, this.SharedData);
  63.  
  64. return ent;
  65. }
  66.  
  67. /*
  68. Update inventory, called by subinventory.
  69. */
  70. function UpdateSubInventory(subInv, x, y) {
  71. this.SubInventory = subInv;
  72. this.SlotX, this.SlotY = x, y;
  73. }
  74.  
  75. /*
  76. Generates a sample item, with random model and size.
  77. */
  78. function GenerateTest() {
  79. var models = {
  80. { "models/alyx.mdl", 2, 5 },
  81. { "models/props_borealis/bluebarrel001.mdl", 2, 4 },
  82. { "models/Combine_Helicopter/helicopter_bomb01.mdl", 2, 2 },
  83. { "models/props_interiors/Furniture_chair01a.mdl", 1, 3 },
  84. };
  85.  
  86. var rand = table.Random(models);
  87. this.Model = rand[1];
  88. this.Width, this.Height = rand[2], rand[3];
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement