Advertisement
Guest User

Untitled

a guest
Apr 18th, 2015
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.88 KB | None | 0 0
  1. --[[
  2. © 2013 CloudSixteen.com do not share, re-distribute or modify
  3. without permission of its author (kurozael@gmail.com).
  4. --]]
  5.  
  6. include("shared.lua");
  7.  
  8. AddCSLuaFile("cl_init.lua");
  9. AddCSLuaFile("shared.lua");
  10.  
  11. -- Called when the entity initializes.
  12. function ENT:Initialize()
  13. self:SetModel("models/props_junk/watermelon01.mdl");
  14.  
  15. self:SetMoveType(MOVETYPE_VPHYSICS);
  16. self:PhysicsInit(SOLID_VPHYSICS);
  17. self:SetUseType(SIMPLE_USE);
  18. self:SetSolid(SOLID_VPHYSICS);
  19.  
  20. self.dispenser = ents.Create("prop_dynamic");
  21. self.dispenser:DrawShadow(false);
  22. self.dispenser:SetAngles( self:GetAngles() );
  23. self.dispenser:SetParent(self);
  24. self.dispenser:SetModel("models/props_combine/combine_dispenser.mdl");
  25. self.dispenser:SetPos( self:GetPos() );
  26. self.dispenser:Spawn();
  27.  
  28. self:DeleteOnRemove(self.dispenser);
  29.  
  30. local minimum = Vector(-8, -8, -8);
  31. local maximum = Vector(8, 8, 64);
  32.  
  33. self:SetCollisionBounds(minimum, maximum);
  34. self:SetCollisionGroup(COLLISION_GROUP_WORLD);
  35. self:PhysicsInitBox(minimum, maximum);
  36. self:DrawShadow(false);
  37. end;
  38.  
  39. -- Called when the entity's transmit state should be updated.
  40. function ENT:UpdateTransmitState()
  41. return TRANSMIT_ALWAYS;
  42. end;
  43.  
  44. -- A function to toggle whether the entity is locked.
  45. function ENT:Toggle()
  46. if (self:IsLocked()) then
  47. self:Unlock();
  48. else
  49. self:Lock();
  50. end;
  51. end;
  52.  
  53. -- A function to lock the entity.
  54. function ENT:Lock()
  55. self:SetDTBool(0, true);
  56. self:EmitRandomSound();
  57. end;
  58.  
  59. -- A function to unlock the entity.
  60. function ENT:Unlock()
  61. self:SetDTBool(0, false);
  62. self:EmitRandomSound();
  63. end;
  64.  
  65. -- A function to set the entity's flash duration.
  66. function ENT:SetFlashDuration(duration)
  67. self:EmitSound("buttons/combine_button_locked.wav");
  68. self:SetDTFloat(1, CurTime() + duration);
  69. end;
  70.  
  71. -- A function to create a dummy ration.
  72. function ENT:CreateDummyRation()
  73. local forward = self:GetForward() * 15;
  74. local right = self:GetRight() * 0;
  75. local up = self:GetUp() * -8;
  76.  
  77. local entity = ents.Create("prop_physics");
  78.  
  79. entity:SetAngles( self:GetAngles() );
  80. entity:SetModel("models/weapons/w_package.mdl");
  81. entity:SetPos(self:GetPos() + forward + right + up);
  82. entity:Spawn();
  83.  
  84. return entity;
  85. end;
  86.  
  87. -- A function to activate the entity's ration.
  88. function ENT:ActivateRation(activator, duration, force)
  89. local curTime = CurTime();
  90.  
  91. if (!duration) then duration = 24; end;
  92.  
  93. if (force or !self.nextActivateRation or curTime >= self.nextActivateRation) then
  94. self.nextActivateRation = curTime + duration + 2;
  95. self:SetDTFloat(0, curTime + duration);
  96.  
  97. Clockwork.kernel:CreateTimer("ration_"..self:EntIndex(), duration, 1, function()
  98. if (IsValid(self)) then
  99. local frameTime = FrameTime() * 0.5;
  100. local dispenser = self.dispenser;
  101. local entity = self:CreateDummyRation();
  102.  
  103. if (IsValid(entity)) then
  104. dispenser:EmitSound("ambient/machines/combine_terminal_idle4.wav");
  105.  
  106. entity:SetNotSolid(true);
  107. entity:SetParent(dispenser);
  108.  
  109. timer.Simple(frameTime, function()
  110. if (IsValid(self) and IsValid(entity)) then
  111. entity:Fire("SetParentAttachment", "package_attachment", 0);
  112.  
  113. timer.Simple(frameTime, function()
  114. if (IsValid(self) and IsValid(entity)) then
  115. dispenser:Fire("SetAnimation", "dispense_package", 0);
  116.  
  117. timer.Simple(1.75, function()
  118. if (IsValid(self) and IsValid(entity)) then
  119. local position = entity:GetPos();
  120. local angles = entity:GetAngles();
  121.  
  122. entity:CallOnRemove("CreateRation", function()
  123. if (IsValid(activator)) then
  124. local itemTable = Clockwork.item:CreateInstance("ration");
  125.  
  126. if (itemTable) then
  127. Clockwork.entity:CreateItem(activator, itemTable, position, angles);
  128. end;
  129. end;
  130. end);
  131.  
  132. if (IsValid(activator) and !force) then
  133. if (activator:GetCharacterData("customclass") == "Civil Worker's Union") then
  134. self:ActivateRation(activator, 8, true);
  135. end;
  136. end;
  137.  
  138. entity:SetNoDraw(true);
  139. entity:Remove();
  140. end;
  141. end);
  142. end;
  143. end);
  144. end;
  145. end);
  146. end;
  147. end;
  148. end);
  149. end;
  150. end;
  151.  
  152. -- A function to emit a random sound from the entity.
  153. function ENT:EmitRandomSound()
  154. local randomSounds = {
  155. "buttons/combine_button1.wav",
  156. "buttons/combine_button2.wav",
  157. "buttons/combine_button3.wav",
  158. "buttons/combine_button5.wav",
  159. "buttons/combine_button7.wav"
  160. };
  161.  
  162. self:EmitSound( randomSounds[ math.random(1, #randomSounds) ] );
  163. end;
  164.  
  165. -- Called when the entity's physics should be updated.
  166. function ENT:PhysicsUpdate(physicsObject)
  167. if (!self:IsPlayerHolding() and !self:IsConstrained()) then
  168. physicsObject:SetVelocity( Vector(0, 0, 0) );
  169. physicsObject:Sleep();
  170. end;
  171. end;
  172.  
  173. -- Called when the entity is used.
  174. function ENT:Use(activator, caller)
  175. if (activator:IsPlayer() and activator:GetEyeTraceNoCursor().Entity == self) then
  176. local curTime = CurTime();
  177. local unixTime = os.time();
  178.  
  179. if (!self.nextUse or curTime >= self.nextUse) then
  180. if (activator:GetFaction() == FACTION_CITIZEN) then
  181. if (!self:IsLocked() and unixTime >= activator:GetCharacterData("nextration", 0)) then
  182. if (!self.nextActivateRation or curTime >= self.nextActivateRation) then
  183. self:ActivateRation(activator);
  184.  
  185. activator:SetCharacterData("nextration", unixTime + Clockwork.config:Get("wages_interval"):Get() * 10);
  186. end;
  187. else
  188. self:SetFlashDuration(3);
  189. end;
  190. elseif (!self.nextActivateRation or curTime >= self.nextActivateRation) then
  191. self:Toggle();
  192. end;
  193.  
  194. self.nextUse = curTime + 3;
  195. end;
  196. end;
  197. end;
  198.  
  199. -- Called when a player attempts to use a tool.
  200. function ENT:CanTool(player, trace, tool)
  201. return false;
  202. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement