Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
tlrlight.c
Go to the documentation of this file.
1 class 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 
13  override ScriptedLightBase GetLight()
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  {
23  return true;
24  }
25 
26  return false;
27  }
28 
29  override void OnWorkStart()
30  {
31  if ( !GetGame().IsServer() || !GetGame().IsMultiplayer() ) // Client side
32  {
33  m_Light = PistollightLight.Cast( ScriptedLightBase.CreateLight(PistollightLight, "0 0 0", 0.08) ); // Position is zero because light is attached on parent immediately.
34  m_Light.AttachOnMemoryPoint(this, "beamStart", "beamEnd");
35  SetObjectMaterial(GLASS_ID, LIGHT_ON_GLASS);
36  SetObjectMaterial(REFLECTOR_ID, LIGHT_ON_REFLECTOR);
37  }
38  }
39 
40  override void OnWork( float consumed_energy )
41  {
42  if ( !GetGame().IsServer() || !GetGame().IsMultiplayer() ) // Client side
43  {
44  Battery9V battery = Battery9V.Cast( GetCompEM().GetEnergySource() );
45 
46  if (battery && m_Light)
47  {
48  float efficiency = battery.GetEfficiency0To1();
49 
50  if ( efficiency < 1 )
51  {
52  m_Light.SetIntensity( efficiency, GetCompEM().GetUpdateInterval() );
53  }
54  else
55  {
56  m_Light.SetIntensity( 1, 0 );
57  }
58  }
59  }
60  }
61 
62  override void OnWorkStop()
63  {
64  if ( !GetGame().IsServer() || !GetGame().IsMultiplayer() ) // Client side
65  {
66  if (m_Light)
67  m_Light.FadeOut();
68 
69  m_Light = NULL;
70 
71  SetObjectMaterial(GLASS_ID, LIGHT_OFF_GLASS);
72  SetObjectMaterial(REFLECTOR_ID, LIGHT_OFF_REFLECTOR);
73  }
74  }
75 
76  // Inventory manipulation
77  override void OnInventoryExit(Man player)
78  {
79  super.OnInventoryExit(player);
80 
81  if ( GetCompEM().IsWorking() )
82  {
83  if (player)
84  {
85  vector ori_rotate = player.GetOrientation();
86  ori_rotate = ori_rotate + Vector(270,0,0);
87  SetOrientation(ori_rotate);
88  }
89  }
90  }
91 
92  override void SetActions()
93  {
94  super.SetActions();
97  }
98 
99  override bool IsLightSource()
100  {
101  return true;
102  }
103 }
GetGame
proto native CGame GetGame()
Switchable_Base
Definition: chainsaw.c:1
ActionTurnOnWhileInHands
Definition: actionturnonwhileinhands.c:1
Battery9V
Definition: battery9v.c:1
OnWorkStop
override void OnWorkStop()
Definition: m18smokegrenade_colorbase.c:2
CanPutAsAttachment
override bool CanPutAsAttachment(EntityAI parent)
Definition: itembase.c:4021
m_Light
protected ExplosiveLight m_Light
light
Definition: explosivesbase.c:31
OnInventoryExit
override protected void OnInventoryExit(Man player)
Definition: fireworksbase.c:79
vector
Definition: enconvert.c:105
OnWork
override void OnWork(float consumed_energy)
Definition: smokegrenadebase.c:195
AddAction
void AddAction(typename actionName)
Definition: advancedcommunication.c:86
ScriptedLightBase
Definition: pointlightbase.c:1
SetActions
void SetActions()
Definition: advancedcommunication.c:79
IsLightSource
bool IsLightSource()
Definition: itembase.c:918
ActionTurnOffWhileInHands
Definition: actionturnoffwhileinhands.c:1
GetLight
ScriptedLightBase GetLight()
Vector
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
EntityAI
Definition: building.c:5
OnWorkStart
override void OnWorkStart()
Definition: smokegrenadebase.c:175