DayZ 1.24
Loading...
Searching...
No Matches
TLRLight.c
Go to the documentation of this file.
1class TLRLight extends Switchable_Base
2{
3 PistollightLight m_Light;
4
5 static int REFLECTOR_ID = 1;
6 static int GLASS_ID = 0;
7
8 static string LIGHT_OFF_GLASS = "dz\\gear\\tools\\data\\flashlight_glass.rvmat";
9 static string LIGHT_OFF_REFLECTOR = "dz\\weapons\\attachments\\data\\TLS3.rvmat";
10 static string LIGHT_ON_GLASS = "dz\\gear\\tools\\data\\flashlight_glass_on.rvmat";
11 static string LIGHT_ON_REFLECTOR = "dz\\weapons\\attachments\\data\\TLS3_on.rvmat";
12
14 {
15 return m_Light;
16 }
17
18 override bool CanPutAsAttachment(EntityAI parent)
19 {
20 if (!super.CanPutAsAttachment(parent)) return false;
21 if (!parent.IsKindOf("PlateCarrierHolster") && !parent.IsKindOf("PlateCarrierComplete") && !parent.IsKindOf("CarrierHolsterSolo") && !parent.IsKindOf("ChestHolster"))
22 return true;
23
24 return false;
25 }
26
27 override void OnWorkStart()
28 {
29 if (!GetGame().IsServer() || !GetGame().IsMultiplayer()) // Client side
30 {
31 m_Light = PistollightLight.Cast(ScriptedLightBase.CreateLight(PistollightLight, "0 0 0", 0.08)); // Position is zero because light is attached on parent immediately.
32 m_Light.AttachOnMemoryPoint(this, "beamStart", "beamEnd");
33 SetObjectMaterial(GLASS_ID, LIGHT_ON_GLASS);
34 SetObjectMaterial(REFLECTOR_ID, LIGHT_ON_REFLECTOR);
35 }
36 }
37
38 override void OnWork(float consumed_energy)
39 {
40 if (!GetGame().IsServer() || !GetGame().IsMultiplayer()) // Client side
41 {
42 Battery9V battery = Battery9V.Cast(GetCompEM().GetEnergySource());
43
44 if (battery && m_Light)
45 {
46 float efficiency = battery.GetEfficiency0To1();
47
48 if (efficiency < 1)
49 m_Light.SetIntensity(efficiency, GetCompEM().GetUpdateInterval());
50 else
52 }
53 }
54 }
55
56 override void OnWorkStop()
57 {
58 if (!GetGame().IsServer() || !GetGame().IsMultiplayer()) // Client side
59 {
60 if (m_Light)
61 m_Light.FadeOut();
62
63 m_Light = NULL;
64
65 SetObjectMaterial(GLASS_ID, LIGHT_OFF_GLASS);
66 SetObjectMaterial(REFLECTOR_ID, LIGHT_OFF_REFLECTOR);
67 }
68 }
69
70 // Inventory manipulation
71 override void OnInventoryExit(Man player)
72 {
73 super.OnInventoryExit(player);
74
75 if (GetCompEM().IsWorking())
76 {
77 if (player)
78 {
79 vector ori_rotate = player.GetOrientation();
80 ori_rotate = ori_rotate + Vector(270, 0, 0);
81 SetOrientation(ori_rotate);
82 }
83 }
84 }
85
86 override void SetActions()
87 {
88 super.SetActions();
91 }
92
93 override bool IsLightSource()
94 {
95 return true;
96 }
97}
void AddAction(typename actionName)
ExplosiveLight m_Light
light
void SetIntensity(float coef, float time)
override void OnWork(float consumed_energy)
Definition TLRLight.c:38
override void OnInventoryExit(Man player)
Definition TLRLight.c:71
override ScriptedLightBase GetLight()
Definition TLRLight.c:13
override void OnWorkStart()
Definition TLRLight.c:27
override void SetActions()
Definition TLRLight.c:86
PistollightLight m_Light
Definition TLRLight.c:3
override void OnWorkStop()
Definition TLRLight.c:56
override bool CanPutAsAttachment(EntityAI parent)
Definition TLRLight.c:18
override bool IsLightSource()
Definition TLRLight.c:93
proto native CGame GetGame()
proto native vector Vector(float x, float y, float z)
Vector constructor from components.