DayZ 1.24
Loading...
Searching...
No Matches
Flashlight.c
Go to the documentation of this file.
1class 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 m_Light.SetIntensity(efficiency, GetCompEM().GetUpdateInterval());
37 else
39 }
40 }
41 }
42
43 override void OnWorkStop()
44 {
45 if (!GetGame().IsServer() || !GetGame().IsMultiplayer()) // Client side
46 {
47 if (m_Light)
48 m_Light.FadeOut();
49
50 m_Light = NULL;
51 }
52
53 SetObjectMaterial(GLASS_ID, LIGHT_OFF_GLASS);
54 SetObjectMaterial(REFLECTOR_ID, LIGHT_OFF_REFLECTOR);
55 }
56
57 // Inventory manipulation
58 override void OnInventoryExit(Man player)
59 {
60 super.OnInventoryExit(player);
61
62 if (GetCompEM().IsWorking())
63 {
64 if (player)
65 {
66 vector ori_rotate = player.GetOrientation();
67 ori_rotate = ori_rotate + Vector(270, 0, 0);
68 SetOrientation(ori_rotate);
69 }
70 }
71 }
72
73 override void SetActions()
74 {
75 super.SetActions();
76
79 }
80
81 override void OnDebugSpawn()
82 {
83 Battery9V.Cast(GetInventory().CreateInInventory("Battery9V"));
84 }
85}
void AddAction(typename actionName)
ExplosiveLight m_Light
light
override void OnWork(float consumed_energy)
Definition Flashlight.c:25
override void OnWorkStart()
Definition Flashlight.c:13
override void SetActions()
Definition Flashlight.c:73
override void OnWorkStop()
Definition Flashlight.c:43
override void OnDebugSpawn()
Definition Flashlight.c:81
override void OnInventoryExit(Man player)
Definition Flashlight.c:58
FlashlightLight m_Light
Definition Flashlight.c:3
void SetIntensity(float coef, float time)
proto native CGame GetGame()
proto native vector Vector(float x, float y, float z)
Vector constructor from components.