Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.75 KB | None | 0 0
  1. -----------------------------------------------------
  2. if (SERVER) then
  3. AddCSLuaFile();
  4. end;
  5.  
  6. local BaseClass = baseclass.Get("base_entity");
  7.  
  8. ENT.PrintName = "Combine Camera";
  9. ENT.Category = "CCTV";
  10. ENT.Spawnable = true;
  11. ENT.AdminOnly = true;
  12. ENT.Model = Model("models/hunter/blocks/cube025x025x025.mdl");
  13. ENT.RenderGroup = RENDERGROUP_BOTH;
  14.  
  15. function ENT:SetupDataTables()
  16. self:NetworkVar("String", 0, "ID");
  17. self:NetworkVar("Bool", 0, "Destroyed");
  18. self:NetworkVar("Entity", 0, "Pilot");
  19. self:NetworkVar("Entity", 1, "Fake");
  20. self:NetworkVar("Entity", 2, "Light");
  21. self:NetworkVar("Entity", 3, "NPC");
  22. self:NetworkVar("Int", 0, "HP");
  23. self:NetworkVar("Angle", 0, "TargetAngle");
  24. end;
  25.  
  26. if (SERVER) then
  27.  
  28. function ENT:SpawnFunction(player, trace, class)
  29. if (!trace.Hit) then return; end;
  30. local entity = ents.Create(class);
  31.  
  32. entity:SetPos(trace.HitPos + trace.HitNormal * 1.5);
  33. entity:Spawn();
  34.  
  35. return entity;
  36. end;
  37.  
  38. function ENT:Initialize()
  39. self:SetModel(self.Model);
  40. self:SetSolid(SOLID_VPHYSICS);
  41. self:PhysicsInit(SOLID_VPHYSICS);
  42. self:SetName("CCTV" .. self:EntIndex());
  43. self:SetHP(50);
  44.  
  45. local phys = self:GetPhysicsObject();
  46.  
  47. if (IsValid(phys)) then
  48. phys:Wake();
  49. phys:EnableMotion(false);
  50. end;
  51.  
  52. self:SetupNPC();
  53. self:SetRenderMode(1);
  54. self:SetMaterial("models/effects/vol_light001");
  55. end;
  56.  
  57. function ENT:SetupNPC()
  58. SafeRemoveEntity(self.NPC);
  59.  
  60. self.NPC = ents.Create("npc_combine_camera");
  61. self.NPC:SetKeyValue("innerradius", 800);
  62. self.NPC:SetKeyValue("outerradius", 800);
  63.  
  64. if (self:GetDestroyed()) then
  65. self.NPC:SetKeyValue("spawnflags", "128");
  66. self:EmitSound("division/skills/turret_deploy.mp3");
  67. end;
  68.  
  69. self.NPC:SetKeyValue("OnFoundPlayer", self:GetName() .. ",Scan");
  70.  
  71. self.NPC:Spawn();
  72.  
  73. if (IsValid(self:GetFake())) then
  74. self.NPC:ResetSequence(self.NPC:LookupSequence("idlealert"));
  75. self.NPC:SetCycle(1);
  76. self.NPC:SetPoseParameter("aim_yaw", self:GetFake():GetPoseParameter("aim_yaw"));
  77. self.NPC:SetPoseParameter("aim_pitch", self:GetFake():GetPoseParameter("aim_pitch"));
  78. self:GetFake():Remove();
  79. end;
  80.  
  81. self.NPC:SetParent(self);
  82. self.NPC:SetLocalAngles(angle_zero);
  83. self.NPC:SetLocalPos(Vector(0, 0, 4));
  84. self.NPC:SetNotSolid(true);
  85.  
  86. if (self:GetDestroyed()) then
  87. self.NPC:Fire("Enable");
  88. self:SetDestroyed(false);
  89. end;
  90.  
  91. self:SetNPC(self.NPC);
  92. end;
  93.  
  94. function ENT:AcceptInput(name, act, caller, data)
  95. if (name == "Scan") then
  96. if (IsValid(act)) then
  97. self:OnFoundPlayer(act);
  98. end;
  99. end;
  100. end;
  101.  
  102. local yellow = Color(255, 255, 0);
  103. local orange = Color(255, 150, 0);
  104.  
  105. function ENT:ShouldHate(player)
  106. if (player:GetNoDraw()) then
  107. return false;
  108. end;
  109.  
  110. if (!Schema:PlayerIsCombine(player) and player:GetFaction() != FACTION_ADMIN and player:GetFaction() != FACTION_PROSELYTE) then
  111. local wep = player:GetActiveWeapon();
  112.  
  113. if (IsValid(wep)) then
  114. local weaponClass = wep:GetClass():lower();
  115.  
  116. if (weaponClass:find("rcs_") or weaponClass:find("bfg_") or weaponClass:find("cw_shiv")) and (!weaponClass:find("rcs_usp") or !weaponClass:find("rcs_glock")) then
  117. return true, "ALERT: Armed 647e identified by %s!", "danger", color_red;
  118. end;
  119. end;
  120.  
  121. if (player:GetSharedVar("IsConcealed")) then
  122. return true, "ALERT: Concealed 647e identified by %s!", "danger", color_red;
  123. elseif (player:GetCivilStatus() == "Anti-Citizen") then
  124. return true, "ALERT: Anti-Citizen identified by %s!", "danger", orange;
  125. elseif (player:GetBOLStatus()) then
  126. return true, "NOTICE: BOL identified by %s.", "poi", yellow;
  127. end;
  128. end;
  129.  
  130. return false;
  131. end;
  132.  
  133. function ENT:OnFoundPlayer(player)
  134. local bShouldHate, threat, waypointType = self:ShouldHate(player);
  135. local color = (255, 255, 0, 255)
  136.  
  137. if (!bShouldHate) then return; end;
  138.  
  139. local id = self:GetID();
  140.  
  141. id = (#id > 0 and id or "CCTV");
  142.  
  143. self:GetNPC():Fire("SetAngry");
  144. self:GetNPC():Fire("SetIdle", "", 5);
  145.  
  146. Schema:AddCombineDisplayLine(Format(threat, id:upper()), color);
  147.  
  148. if (Schema.waypoints) then
  149. Schema.waypoints:AddWaypoint(player:GetPos() + Vector(0, 0, 20), id, waypointType, 30, nil);
  150. end;
  151. end;
  152.  
  153. function ENT:Use(activator, caller, type, value)
  154. if (!IsValid(activator)) then return; end;
  155.  
  156. if (self:GetDestroyed()) then
  157. local faction = activator:GetFaction();
  158.  
  159. if (faction == FACTION_MPF or faction == FACTION_MPFSCN or faction == FACTION_OTA) then
  160. self:Repair();
  161. end;
  162. end;
  163. end;
  164.  
  165. function ENT:Transmit(player)
  166. if (self:GetDestroyed()) then return false; end;
  167. if (IsValid(self:GetPilot())) then return false; end;
  168.  
  169. if (IsValid(player:GetSharedVar("CCTV"))) then
  170. player:GetSharedVar("CCTV"):Eject(true);
  171. else
  172. player.CCTVEyeAngles = player:EyeAngles();
  173. end;
  174.  
  175. self:MakeFake();
  176.  
  177. local ang = self:GetTargetAngle();
  178. ang.z = 0;
  179.  
  180. net.Start("CCTV_CameraEnter");
  181. net.WriteEntity(self);
  182. net.WriteAngle(ang);
  183. net.Send(player);
  184.  
  185. self:SetPilot(player);
  186. player:SetSharedVar("CCTV", self);
  187. end;
  188.  
  189. function ENT:Eject(bNoReset)
  190. local pilot = self:GetPilot();
  191.  
  192. self:SetPilot(NULL);
  193.  
  194. if (!bNoReset) then
  195. pilot:SetSharedVar("CCTV", NULL);
  196. pilot:SetEyeAngles(pilot.CCTVEyeAngles);
  197. end;
  198.  
  199. self:SetupNPC();
  200. end;
  201.  
  202. function ENT:MakeFake()
  203. if (!IsValid(self.NPC)) then return; end;
  204.  
  205. self:SetTargetAngle(self.NPC:GetAttachment(self.NPC:LookupAttachment("eyes")).Ang);
  206.  
  207. self.dynamic = ents.Create("prop_dynamic");
  208. self.dynamic:SetModel("models/combine_camera/combine_camera.mdl");
  209. self.dynamic:SetKeyValue("DefaultAnim", "idlealert");
  210. self.dynamic:Spawn();
  211. self.dynamic:ResetSequence(self.dynamic:LookupSequence("idlealert"));
  212. self.dynamic:SetCycle(1);
  213. self.dynamic:SetParent(self);
  214. self.dynamic:SetLocalAngles(angle_zero);
  215. self.dynamic:SetLocalPos(Vector(0, 0, 4));
  216. self.dynamic:SetNotSolid(true);
  217. self.dynamic:SetPoseParameter("aim_yaw", self.NPC:GetPoseParameter("aim_yaw"));
  218. self.dynamic:SetPoseParameter("aim_pitch", self.NPC:GetPoseParameter("aim_pitch"));
  219. self:SetFake(self.dynamic);
  220.  
  221. self.light = ents.Create("env_sprite");
  222. self.light:SetKeyValue("model", "sprites/light_glow03.vmt");
  223. self.light:SetKeyValue("scale", 0.2);
  224. self.light:SetKeyValue("rendermode", RENDERMODE_WORLDGLOW);
  225. self.light:SetParent(self.dynamic);
  226. self.light:Spawn();
  227. self.light:Fire("SetParentAttachment", "light");
  228. self.light:Activate();
  229. self.light:SetColor(Color(0, 0, 255));
  230. self:SetLight(self.light);
  231.  
  232. self.NPC:Remove();
  233. self:SetNPC(NULL);
  234. end;
  235.  
  236. function ENT:MakeNPC()
  237. if (!IsValid(self.dynamic)) then return; end;
  238.  
  239. self:SetupNPC();
  240.  
  241. self.dynamic:Remove();
  242. self.light:Remove();
  243. self:SetFake(NULL);
  244. end;
  245.  
  246. function ENT:Repair()
  247. SafeRemoveEntity(self.NPC);
  248.  
  249. self:SetupNPC();
  250.  
  251. self:SetHP(50);
  252. end;
  253.  
  254. function ENT:OnTakeDamage(info)
  255. if (self:GetDestroyed()) then return; end;
  256.  
  257. if (IsValid(self.NPC)) then
  258.  
  259. self.NPC:TakeDamageInfo(info);
  260.  
  261. if (info:GetDamage() >= self:GetHP()) then
  262. self:SetDestroyed(true);
  263. end;
  264.  
  265. self:SetHP(self:GetHP() - info:GetDamage());
  266. elseif (IsValid(self.dynamic)) then
  267. if (info:GetDamage() >= self:GetHP()) then
  268. self:Eject();
  269. self:SetupNPC();
  270. self.NPC:TakeDamage(100, info:GetAttacker(), info:GetInflictor());
  271. self:SetDestroyed(true);
  272. end;
  273.  
  274. self:SetHP(self:GetHP() - info:GetDamage());
  275. end;
  276. end;
  277.  
  278. elseif (CLIENT) then
  279.  
  280. function ENT:Initialize()
  281. self:SetSolid(SOLID_VPHYSICS);
  282.  
  283. self.vis = util.GetPixelVisibleHandle();
  284. end;
  285.  
  286. function ENT:Draw()
  287. self:DrawModel();
  288. end;
  289.  
  290. local repairMat = Material("vgui/repair.png");
  291.  
  292. function ENT:DrawTranslucent()
  293. if (self:GetDestroyed()) then
  294. local faction = Clockwork.Client:GetFaction();
  295.  
  296. if (faction == FACTION_MPF or faction == FACTION_MPFSCN or faction == FACTION_OTA) then
  297. local origin = self:GetPos() - Vector(0, 0, 5);
  298. local vis = util.PixelVisible(origin, 10, self.vis);
  299.  
  300. cam.Start2D();
  301. local dist = Clockwork.Client:EyePos():Distance(origin);
  302. local scale = (dist < 200) and (200 / (dist / 40)) or 40;
  303. local screenPos = origin:ToScreen();
  304.  
  305. surface.SetMaterial(repairMat);
  306. surface.SetDrawColor(192, 57, 43, math.Clamp(255 * vis, 150, 255));
  307. surface.DrawTexturedRect(screenPos.x - scale / 2, screenPos.y - scale / 2, scale, scale);
  308. cam.End2D();
  309. end;
  310. end;
  311. end;
  312.  
  313. end;
  314.  
  315. function ENT:Think()
  316. if (IsValid(self:GetFake()) and IsValid(self:GetPilot())) then
  317. self:SetTargetAngle(self:GetPilot():EyeAngles());
  318. self:UpdateFacing();
  319. elseif (SERVER and IsValid(self:GetNPC())) then
  320. if ((self.nextUpdate or 0) <= CurTime()) then
  321. for k, v in pairs(player.GetAll()) do
  322. if (!v:HasInitialized()) then continue; end;
  323.  
  324. local bShouldHate = self:ShouldHate(v);
  325.  
  326. if (!bShouldHate) then
  327. self:GetNPC():AddEntityRelationship(v, D_NU, 99);
  328. else
  329. self:GetNPC():AddEntityRelationship(v, D_HT, 99);
  330. end;
  331. end;
  332.  
  333. self.nextUpdate = CurTime() + 2;
  334. end;
  335. end;
  336.  
  337. if (CLIENT) then
  338. if (Clockwork.Client == self:GetPilot()) then
  339. if (IsValid(self:GetFake())) then
  340. self:GetFake():SetNoDraw(true);
  341. end;
  342.  
  343. if (IsValid(self:GetLight())) then
  344. self:GetLight():SetNoDraw(true);
  345. end;
  346. end;
  347. end;
  348.  
  349. if (SERVER) then
  350. self:NextThink(CurTime());
  351. else
  352. self:SetNextClientThink(CurTime());
  353. end;
  354.  
  355. return true;
  356. end;
  357.  
  358. function ENT:UpdateFacing()
  359. if (!self:GetTargetAngle()) then return; end;
  360.  
  361. local vecGoalLocalAngles = self:GetFake():WorldToLocalAngles(self:GetTargetAngle());
  362.  
  363. self:GetFake():SetPoseParameter("aim_pitch", vecGoalLocalAngles.x);
  364.  
  365. self:GetFake():SetPoseParameter("aim_yaw", vecGoalLocalAngles.y);
  366.  
  367. if (CLIENT) then
  368. self:InvalidateBoneCache();
  369. end;
  370. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement