Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
flashlight.c
Go to the documentation of this file.
1 class Flashlight extends ItemBase
2 {
3  FlashlightLight 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\\gear\\tools\\data\\flashlight.rvmat";
10  static string LIGHT_ON_GLASS = "dz\\gear\\tools\\data\\flashlight_glass_on.rvmat";
11  static string LIGHT_ON_REFLECTOR = "dz\\gear\\tools\\data\\flashlight_glass_on.rvmat";
12 
13  override void OnWorkStart()
14  {
15  if ( !GetGame().IsServer() || !GetGame().IsMultiplayer() ) // Client side
16  {
17  m_Light = FlashlightLight.Cast( ScriptedLightBase.CreateLight(FlashlightLight, "0 0 0", 0.08) ); // Position is zero because light is attached on parent immediately.
18  m_Light.AttachOnMemoryPoint(this, "beamStart", "beamEnd");
19  }
20 
21  SetObjectMaterial(GLASS_ID, LIGHT_ON_GLASS);
22  SetObjectMaterial(REFLECTOR_ID, LIGHT_ON_REFLECTOR);
23  }
24 
25  override void OnWork( float consumed_energy )
26  {
27  if ( !GetGame().IsServer() || !GetGame().IsMultiplayer() ) // Client side
28  {
29  Battery9V battery = Battery9V.Cast( GetCompEM().GetEnergySource() );
30 
31  if (battery && m_Light)
32  {
33  float efficiency = battery.GetEfficiency0To1();
34 
35  if ( efficiency < 1 )
36  {
37  m_Light.SetIntensity( efficiency, GetCompEM().GetUpdateInterval() );
38  }
39  else
40  {
41  m_Light.SetIntensity( 1, 0 );
42  }
43  }
44  }
45  }
46 
47  override void OnWorkStop()
48  {
49  if ( !GetGame().IsServer() || !GetGame().IsMultiplayer() ) // Client side
50  {
51  if (m_Light)
52  m_Light.FadeOut();
53 
54  m_Light = NULL;
55  }
56 
57  SetObjectMaterial(GLASS_ID, LIGHT_OFF_GLASS);
58  SetObjectMaterial(REFLECTOR_ID, LIGHT_OFF_REFLECTOR);
59  }
60 
61  // Inventory manipulation
62  override void OnInventoryExit(Man player)
63  {
64  super.OnInventoryExit(player);
65 
66  if ( GetCompEM().IsWorking() )
67  {
68  if (player)
69  {
70  vector ori_rotate = player.GetOrientation();
71  ori_rotate = ori_rotate + Vector(270,0,0);
72  SetOrientation(ori_rotate);
73  }
74  }
75  }
76 
77  override void SetActions()
78  {
79  super.SetActions();
80 
83  }
84 
85  override void OnDebugSpawn()
86  {
87  Battery9V.Cast(GetInventory().CreateInInventory("Battery9V"));
88  }
89 }
ItemBase
Definition: inventoryitem.c:730
GetGame
proto native CGame GetGame()
ActionTurnOnWhileInHands
Definition: actionturnonwhileinhands.c:1
Battery9V
Definition: battery9v.c:1
OnWorkStop
override void OnWorkStop()
Definition: m18smokegrenade_colorbase.c:2
m_Light
protected ExplosiveLight m_Light
light
Definition: explosivesbase.c:31
OnInventoryExit
override protected void OnInventoryExit(Man player)
Definition: fireworksbase.c:79
OnDebugSpawn
class Hatchback_02_Blue extends Hatchback_02 OnDebugSpawn
Definition: hatchback_02.c:404
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
ActionTurnOffWhileInHands
Definition: actionturnoffwhileinhands.c:1
Vector
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
OnWorkStart
override void OnWorkStart()
Definition: smokegrenadebase.c:175