DayZ 1.24
Loading...
Searching...
No Matches
UniversalLight.c
Go to the documentation of this file.
1class UniversalLight extends Switchable_Base
2{
3 UniversallightLight m_Light;
4
5 static int REFLECTOR_ID = 1;
6 static int GLASS_ID = 2;
7
8 static string LIGHT_OFF_GLASS = "dz\\gear\\tools\\data\\flashlight_glass.rvmat";
9 static string LIGHT_OFF_REFLECTOR = "dz\\weapons\\attachments\\data\\m4_flashlight.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\\m4_flashlight_on.rvmat";
12
14
16 {
17 InitAttachmentsSlotsToCheck(m_AttachmentSlotsCheck);
18 }
19
21 {
22 return m_Light;
23 }
24
25 override bool CanPutAsAttachment(EntityAI parent)
26 {
27 if (!super.CanPutAsAttachment(parent)) return false;
28
29 bool req_attachment = false;
30 bool rail_attachment_found = false;
31 int slot_id;
33 for (int i = 0; i < parent.GetInventory().GetAttachmentSlotsCount(); i++)
34 {
35 slot_id = parent.GetInventory().GetAttachmentSlotId(i);
36 if (m_AttachmentSlotsCheck.Find(slot_id) != -1)
37 {
38 req_attachment = true;
39 attachment = ItemBase.Cast(parent.GetInventory().FindAttachment(slot_id));
40 if (attachment && attachment.ConfigIsExisting("hasRailFunctionality") && attachment.ConfigGetBool("hasRailFunctionality"))
42 }
43 }
45 }
46
47 override void OnWorkStart()
48 {
49 if (!GetGame().IsServer() || !GetGame().IsMultiplayer()) // Client side
50 {
51 m_Light = UniversallightLight.Cast(ScriptedLightBase.CreateLight(UniversallightLight, "0 0 0", 0.08)); // Position is zero because light is attached on parent immediately.
52 m_Light.AttachOnMemoryPoint(this, "beamStart", "beamEnd");
53 SetObjectMaterial(GLASS_ID, LIGHT_ON_GLASS);
54 SetObjectMaterial(REFLECTOR_ID, LIGHT_ON_REFLECTOR);
55 }
56 }
57
58 override void OnWork(float consumed_energy)
59 {
60 if (!GetGame().IsServer() || !GetGame().IsMultiplayer()) // Client side
61 {
62 Battery9V battery = Battery9V.Cast(GetCompEM().GetEnergySource());
63
64 if (battery && m_Light)
65 {
66 float efficiency = battery.GetEfficiency0To1();
67
68 if (efficiency < 1)
69 m_Light.SetIntensity(efficiency, GetCompEM().GetUpdateInterval());
70 else
72 }
73 }
74 }
75
76 override void OnWorkStop()
77 {
78 if (!GetGame().IsServer() || !GetGame().IsMultiplayer()) // Client side
79 {
80 if (m_Light)
81 m_Light.FadeOut();
82
83 m_Light = NULL;
84
85 SetObjectMaterial(GLASS_ID, LIGHT_OFF_GLASS);
86 SetObjectMaterial(REFLECTOR_ID, LIGHT_OFF_REFLECTOR);
87 }
88 }
89
90 // Inventory manipulation
91 override void OnInventoryExit(Man player)
92 {
93 super.OnInventoryExit(player);
94
95 if (GetCompEM().IsWorking())
96 {
97 if (player)
98 {
99 vector ori_rotate = player.GetOrientation();
100 ori_rotate = ori_rotate + Vector(270, 0, 0);
101 SetOrientation(ori_rotate);
102 }
103 }
104 }
105
106 override void SetActions()
107 {
108 super.SetActions();
111 }
112
113 override bool IsLightSource()
114 {
115 return true;
116 }
117
120 {
121 if (!AttSlots)
122 {
123 AttSlots = new array<int>;
124 AttSlots.Insert(InventorySlots.GetSlotIdFromString("weaponHandguardM4"));
125 AttSlots.Insert(InventorySlots.GetSlotIdFromString("weaponHandguardAK"));
126 AttSlots.Insert(InventorySlots.GetSlotIdFromString("weaponHandguardMP5"));
127 }
128 }
129}
void AddAction(typename actionName)
ExplosiveLight m_Light
light
provides access to slot configuration
static proto native int GetSlotIdFromString(string slot_name)
converts string to slot_id
void SetIntensity(float coef, float time)
override void OnWork(float consumed_energy)
UniversallightLight m_Light
override void OnInventoryExit(Man player)
override ScriptedLightBase GetLight()
override void OnWorkStart()
override void SetActions()
PistollightLight m_Light
Definition TLRLight.c:3
override void OnWorkStop()
void InitAttachmentsSlotsToCheck(out array< int > AttSlots)
Enter att slot types to check on attach.
override bool CanPutAsAttachment(EntityAI parent)
override bool IsLightSource()
ref array< int > m_AttachmentSlotsCheck
proto native CGame GetGame()
proto native vector Vector(float x, float y, float z)
Vector constructor from components.