Dayz Explorer 1.29.162510
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
13 ref array<int> m_AttachmentSlotsCheck;
14
15 void UniversalLight()
16 {
17 InitAttachmentsSlotsToCheck(m_AttachmentSlotsCheck);
18 }
19
20 override ScriptedLightBase GetLight()
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;
32 ItemBase attachment;
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") )
41 rail_attachment_found = true;
42 }
43 }
44 return !req_attachment || (req_attachment && rail_attachment_found);
45 }
46
47 override void OnWorkStart()
48 {
49 if ( !g_Game.IsServer() || !g_Game.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 ( !g_Game.IsServer() || !g_Game.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 {
70 m_Light.SetIntensity( efficiency, GetCompEM().GetUpdateInterval() );
71 }
72 else
73 {
74 m_Light.SetIntensity( 1, 0 );
75 }
76 }
77 }
78 }
79
80 override void OnWorkStop()
81 {
82 if ( !g_Game.IsServer() || !g_Game.IsMultiplayer() ) // Client side
83 {
84 if (m_Light)
85 m_Light.FadeOut();
86
87 m_Light = NULL;
88
89 SetObjectMaterial(GLASS_ID, LIGHT_OFF_GLASS);
90 SetObjectMaterial(REFLECTOR_ID, LIGHT_OFF_REFLECTOR);
91 }
92 }
93
94 // Inventory manipulation
95 override void OnInventoryExit(Man player)
96 {
97 super.OnInventoryExit(player);
98
99 if ( GetCompEM().IsWorking() )
100 {
101 if (player)
102 {
103 vector ori_rotate = player.GetOrientation();
104 ori_rotate = ori_rotate + Vector(270,0,0);
105 SetOrientation(ori_rotate);
106 }
107 }
108 }
109
110 override void SetActions()
111 {
112 super.SetActions();
113 AddAction(ActionTurnOnWhileInHands);
114 AddAction(ActionTurnOffWhileInHands);
115 }
116
117 override bool IsLightSource()
118 {
119 return true;
120 }
121
123 void InitAttachmentsSlotsToCheck(out array<int> AttSlots)
124 {
125 if (!AttSlots)
126 {
127 AttSlots = new array<int>;
128 AttSlots.Insert(InventorySlots.GetSlotIdFromString("weaponHandguardM4"));
129 AttSlots.Insert(InventorySlots.GetSlotIdFromString("weaponHandguardAK"));
130 AttSlots.Insert(InventorySlots.GetSlotIdFromString("weaponHandguardMP5"));
131 }
132 }
133}
class LogManager EntityAI
void AddAction(typename actionName)
void SetActions()
DayZGame g_Game
Definition dayzgame.c:3942
class GP5GasMask extends MaskBase ItemBase
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
void OnInventoryExit(Man player)
Event called on item when it is removed from the player(Man) inventory, passes the old owner as a par...
Definition itembase.c:8825
override bool CanPutAsAttachment(EntityAI parent)
Definition itembase.c:9066
class Land_Buoy extends House m_Light
override void OnWorkStop()
override void OnWork(float consumed_energy)
override void OnWorkStart()