Advertisement
Guest User

Untitled

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