Advertisement
Guest User

Untitled

a guest
Jun 11th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.54 KB | None | 0 0
  1.  
  2. local Clockwork = Clockwork;
  3.  
  4. local ITEM = Clockwork.item:New("clothes_base", true);
  5. ITEM.name = "Armor Clothes Base";
  6. ITEM.uniqueID = "armor_clothes_base";
  7. ITEM.model = "models/props_c17/suitcase_passenger_physics.mdl";
  8. ITEM.actualWeight = 2;
  9. ITEM.invSpace = 2;
  10. ITEM.protection = 0;
  11. ITEM.maxArmor = 0;
  12. ITEM.hasGasmask = false;
  13. ITEM.hasRebreather = false;
  14. ITEM.isPA = false;
  15. ITEM.useText = "Wear";
  16. ITEM.category = "Clothing";
  17. ITEM.description = "A suitcase full of clothes.";
  18.  
  19. ITEM:AddData("armor", -1, true);
  20. ITEM:AddData("Rarity", 1, true);
  21. ITEM:AddData("PerceivedWeight", -1, true);
  22. ITEM:AddData("AddInvSpace", 0, true);
  23.  
  24. ITEM:AddQueryProxy("color", ITEM.GetRarityColor);
  25. ITEM:AddQueryProxy("weight", "PerceivedWeight");
  26. ITEM:AddQueryProxy("addInvSpace", "AddInvSpace");
  27.  
  28. -- Called when a player wears the accessory.
  29. function ITEM:OnChangedClothes(player, bIsWearing)
  30. if (bIsWearing) then
  31. -- Player is putting armor on
  32. -- Set player armor value to current remaining armor
  33. player:SetMaxArmor(self("maxArmor"));
  34. player:SetArmor(self:GetData("armor"));
  35.  
  36. -- Set perceived weight to 0
  37. self:SetData("PerceivedWeight", 0);
  38.  
  39. -- Allow armor pockets to be used for inventory weight
  40. self:SetData("AddInvSpace", self("invSpace"));
  41. else
  42. -- Player is taking item off
  43. -- Save armor on item and reset player's armor value
  44. self:SetData("armor", math.Clamp(player:Armor(), 0, self("maxArmor")));
  45. player:SetArmor(0);
  46.  
  47. -- Set perceived weight back to the actual weight
  48. self:SetData("PerceivedWeight", self("actualWeight"));
  49.  
  50. -- Remove pocket space
  51. self:SetData("AddInvSpace", 0);
  52. end;
  53. end;
  54.  
  55. -- Called when a player has unequipped the item.
  56. function ITEM:OnPlayerUnequipped(player, extraData)
  57. if (self("hasGasmask")) then
  58. local items = player:GetInventory();
  59. for k, itemList in pairs(items) do
  60. for k, item in pairs(itemList) do
  61. if (!item:IsBasedFrom("filter_base")) then
  62. break;
  63. elseif (item:GetData("equipped")) then
  64. hasEquipped = true;
  65. Clockwork.player:Notify(player, "You need to unscrew your filter first!");
  66. return false;
  67. end;
  68. end;
  69. end;
  70. end;
  71.  
  72. if (player:GetInventoryWeight() + self("actualWeight") > (player:GetMaxWeight() - self("addInvSpace"))) then
  73. Clockwork.player:Notify(player, "You don't have enough inventory space to unequip this!");
  74. return false;
  75. end;
  76.  
  77. player:RemoveClothes();
  78. end;
  79.  
  80. function ITEM:CanGiveStorage(player, storageTable)
  81. if (player:IsWearingItem(self)) then
  82. Clockwork.player:Notify(player, "You cannot store this while you are wearing it!");
  83. return false;
  84. end;
  85. end;
  86.  
  87. -- Called when a player attempts to take the item from storage.
  88. function ITEM:CanTakeStorage(player, storageTable)
  89. local target = Clockwork.entity:GetPlayer(storageTable.entity);
  90.  
  91. if (target) then
  92. if (target:GetInventoryWeight() > (target:GetMaxWeight() - self("addInvSpace"))) then
  93. return false;
  94. end;
  95. end;
  96. end;
  97.  
  98. -- A function to get the item's rarity color.
  99. function ITEM:GetRarityColor()
  100. local rarity = self:GetData("Rarity");
  101. if (rarity == 1) then
  102. return Color(248, 248, 255, 255);
  103. elseif (rarity == 2) then
  104. return Color(61, 210, 11, 255);
  105. elseif (rarity == 3) then
  106. return Color(47, 120, 255, 255);
  107. elseif (rarity == 4) then
  108. return Color(145, 50, 200, 255);
  109. elseif (rarity == 5) then
  110. return Color(255, 150, 0, 255);
  111. end;
  112. end;
  113.  
  114. function ITEM:EntityHandleMenuOption(player, entity, option, argument)
  115. -- Armor repair
  116. if (option == "Repair") then
  117. self:RepairArmor(player);
  118.  
  119. -- Admin armor repair
  120. elseif (option == "AdminRepair") then
  121. if (player:IsSuperAdmin()) then
  122. self:SetData("armor", self("maxArmor"));
  123. Clockwork.kernel:PrintLog(LOGTYPE_MAJOR, player:Name().." has admin-repaired a "..self("name")..".");
  124. else
  125. Clockwork.Notify(player, "You are not a super admin!");
  126. end;
  127. end;
  128. end;
  129.  
  130. if (SERVER) then
  131. function ITEM:OnInstantiated()
  132. -- Set initial values of the data fields
  133. if (self:GetData("armor") == -1) then
  134. self:SetData("armor", self("maxArmor"));
  135. end;
  136.  
  137. if (self:GetData("PerceivedWeight") == -1) then
  138. self:SetData("PerceivedWeight", self("actualWeight"));
  139. end;
  140.  
  141. -- Set PA footstep sounds if it's PA.
  142. if (self("isPA")) then
  143. self.runSound = {
  144. "newvegas/fst_armorpower_01.wav",
  145. "newvegas/fst_armorpower_02.wav",
  146. "newvegas/fst_armorpower_03.wav"
  147. }
  148. self.walkSound = self.runSound;
  149. end;
  150. end;
  151.  
  152. function ITEM:RepairArmor(player)
  153. if (!self("repairItem")) then
  154. Clockwork.player:Notify(player, "This item cannot be repaired! (Contact a dev if it should be)");
  155. return;
  156. end;
  157. if (self:GetData("armor") == self("maxArmor")) then
  158. Clockwork.player:Notify(player, "This item already has full armor!");
  159. return;
  160. end;
  161.  
  162. -- Check if a flag is required and if the player has it
  163. if (self("repairFlag") and !Clockwork.player:HasFlags(player, self("repairFlag"))) then
  164. Clockwork.player:Notify(player, "You do not have the "..self("repairFlag").." flag!");
  165. end;
  166.  
  167. local repairItem = player:FindItemByID(self("repairItem"));
  168.  
  169. -- Check if the player has the needed item
  170. if (!player:HasItemByID(self("repairItem"))) then
  171. repairItem = Clockwork.item:CreateInstance(self("repairItem"));
  172. Clockwork.player:Notify(player, "You do not have enough "..repairItem("name").." to repair this!");
  173. return;
  174. end;
  175.  
  176. local amount = self("repairAmount") or 50;
  177.  
  178. -- Take the repair item
  179. player:TakeItem(repairItem);
  180. -- Set armor to new value
  181. self:SetData("armor", math.Clamp(self:GetData("armor") + amount, 0, self("maxArmor")));
  182. -- Notify player
  183. Clockwork.player:Notify(player, "You have repaired the "..self("name").." for "..tostring(amount).." armor.");
  184. Clockwork.kernel:PrintLog(LOGTYPE_GENERIC, player:Name().." has repaired a "..self("name").." for "..tostring(amount)..".");
  185. end;
  186. else
  187. function ITEM:GetClientSideInfo()
  188. if (!self:IsInstance()) then return; end;
  189.  
  190. local clientSideInfo = "";
  191.  
  192. local itemRarity = self:GetData("Rarity");
  193. if (itemRarity == 1) then
  194. clientSideInfo = Clockwork.kernel:AddMarkupLine(clientSideInfo, "Common", self:GetRarityColor());
  195. elseif (itemRarity == 2) then
  196. clientSideInfo = Clockwork.kernel:AddMarkupLine(clientSideInfo, "Uncommon", self:GetRarityColor());
  197. elseif (itemRarity == 3) then
  198. clientSideInfo = Clockwork.kernel:AddMarkupLine(clientSideInfo, "Rare", self:GetRarityColor());
  199. elseif (itemRarity == 4) then
  200. clientSideInfo = Clockwork.kernel:AddMarkupLine(clientSideInfo, "Unique", self:GetRarityColor());
  201. elseif (itemRarity == 5) then
  202. clientSideInfo = Clockwork.kernel:AddMarkupLine(clientSideInfo, "Legendary", self:GetRarityColor());
  203. end;
  204.  
  205. local armor = self:GetData("armor");
  206. if (Clockwork.player:IsWearingItem(self)) then
  207. armor = Clockwork.Client:Armor();
  208. end;
  209.  
  210. clientSideInfo = Clockwork.kernel:AddMarkupLine(clientSideInfo, "Armor: "..math.floor(armor));
  211. clientSideInfo = Clockwork.kernel:AddMarkupLine(clientSideInfo, "Protection: "..math.floor(100 * self("protection")).."%");
  212.  
  213. return (clientSideInfo != "" and clientSideInfo);
  214. end;
  215.  
  216. -- Called when the item entity's menu options are needed.
  217. function ITEM:GetEntityMenuOptions(entity, options)
  218. if (!IsValid(entity)) then
  219. return;
  220. end;
  221.  
  222. if (Clockwork.Client:IsSuperAdmin()) then
  223. options["AdminRepair"] = function()
  224. Clockwork.entity:ForceMenuOption(entity, "AdminRepair", nil);
  225. end;
  226. end;
  227.  
  228. options["Repair"] = function()
  229. Clockwork.entity:ForceMenuOption(entity, "Repair", nil);
  230. end;
  231. end;
  232. end;
  233.  
  234. Clockwork.item:Register(ITEM);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement