DayZ 1.24
Loading...
Searching...
No Matches
Trap_RabbitSnare.c
Go to the documentation of this file.
1class Trap_RabbitSnare extends TrapSpawnBase
2{
4 {
5 m_DefectRate = 15; //Added damage after trap activation
6
8 m_UpdateWaitTime = 30;
9 m_IsFoldable = true;
10 m_IsUsable = true;
11 m_MinimalDistanceFromPlayersToCatch = 10;
12
13 m_BaitCatchProb = 85;
14 m_NoBaitCatchProb = 15;
15
16 m_AnimationPhaseSet = "inventory";
17 m_AnimationPhaseTriggered = "placing";
18 m_AnimationPhaseUsed = "triggered";
19
20 m_WaterSurfaceForSetup = false;
21
22 m_CatchesGroundAnimal = new multiMap<string, float>;
23 m_CatchesGroundAnimal.Insert("DeadRooster", 1);
24 m_CatchesGroundAnimal.Insert("DeadChicken_White", 1);
25 m_CatchesGroundAnimal.Insert("DeadChicken_Spotted", 1);
26 m_CatchesGroundAnimal.Insert("DeadChicken_Brown", 1);
27 // ALWAYS keep rabbit last as that is how it gets the rabbit in case of rabbit specific bait
28 m_CatchesGroundAnimal.Insert("DeadRabbit", 1);
29 }
30
31 override bool CanBePlaced(Man player, vector position)
32 {
34 return true;
35
36 int liquidType;
37 string surfaceType;
38 g_Game.SurfaceUnderObject(PlayerBase.Cast(player).GetHologramLocal().GetProjectionEntity(), surfaceType, liquidType);
39
40 return g_Game.IsSurfaceDigable(surfaceType);
41 }
42
44 {
45 super.OnVariablesSynchronized();
46
47 if (IsPlaceSound())
49 }
50
51 override void SetupTrap()
52 {
53 if (GetGame().IsServer())
54 {
55 if (GetHierarchyRootPlayer().CanDropEntity(this))
56 {
57 if (IsRuined())
58 PlayerBase player = PlayerBase.Cast(GetHierarchyRootPlayer());
59 else
60 {
61 PlayerBase owner_player = PlayerBase.Cast(GetHierarchyRootPlayer());
62
63 //GetDirection
64 vector trapPos = owner_player.GetDirection();
65 trapPos[1] = 0;
66 SetPosition(owner_player.GetPosition() + trapPos);
67
68 SetActive();
69
70 SetOrientation(owner_player.GetOrientation());
71 }
72 }
73 }
74 }
75
76 override void SpawnCatch()
77 {
78 super.SpawnCatch();
79
80 if (m_CanCatch)
81 {
83
84 // We read the relevant catch map
85 ItemBase catch;
86 catches = m_CatchesGroundAnimal;
87
88 // The catch map contains data
89 if (catches && catches.Count() > 0)
90 {
91 // select random object from catches
92 int count = catches.Count() - 1;
94
95 if (Math.RandomFloat(0, 100) < m_FinalCatchProb)
96 {
97 if (m_Bait)
98 {
99 if (m_Bait.IsInherited(Worm))
100 {
101 // We can only catch chicken, so exclude the rabbit
103 catch = ItemBase.Cast(GetGame().CreateObjectEx(catches.GetKeyByIndex(randomCatchIndex), m_PreyPos, ECE_PLACE_ON_SURFACE));
104 }
105 else
106 {
107 // Get the last index, which is the rabbit
109 catch = ItemBase.Cast(GetGame().CreateObjectEx(catches.GetKeyByIndex(randomCatchIndex), m_PreyPos, ECE_PLACE_ON_SURFACE));
110 }
111 }
112 else
113 {
114 // No bait, 50 / 50 rabbit
116 if (randomCatchIndex == 0)
117 {
119 catch = ItemBase.Cast(GetGame().CreateObjectEx(catches.GetKeyByIndex(randomCatchIndex), m_PreyPos, ECE_PLACE_ON_SURFACE));
120 }
121 else
122 {
124 catch = ItemBase.Cast(GetGame().CreateObjectEx(catches.GetKeyByIndex(randomCatchIndex), m_PreyPos, ECE_PLACE_ON_SURFACE));
125 }
126 }
127
128 // We set quantity of prey
129 if (catch)
130 CatchSetQuant(catch);
131 }
132
133 // We update the state
134 SetUsed();
135
136 // We remove the bait from this trap
137 if (m_Bait)
138 m_Bait.Delete();
139 }
140
141 // We damage the trap
142 AddDefect();
143 }
144 }
145
146 //================================================================
147 // ADVANCED PLACEMENT
148 //================================================================
149
150 override void OnPlacementComplete(Man player, vector position = "0 0 0", vector orientation = "0 0 0")
151 {
152 super.OnPlacementComplete(player, position, orientation);
153 SetOrientation(orientation);
154 SetIsPlaceSound(true);
155 }
156
157 override bool IsDeployable()
158 {
159 return true;
160 }
161
162 override string GetDeploySoundset()
163 {
164 return "placeRabbitSnareTrap_SoundSet";
165 }
166
167 override string GetLoopDeploySoundset()
168 {
169 return "rabbitsnare_deploy_SoundSet";
170 }
171
172 override void SetActions()
173 {
174 super.SetActions();
175
176 // We remove the hunting trap deploy action in order to all advanced placement
178
180 AddAction(ActionDeployObject);
181 }
182
183 // ===============================================================
184 // ===================== DEPRECATED ============================
185 // ===============================================================
186
187 override void AlignCatch(ItemBase obj, string catch_name)
188 {
189 if (catch_name == "Animal_LepusEuropaeus")
190 {
191 obj.SetOrientation(GetOrientation());
192
193 vector forward_vec = GetDirection();
194 vector side_vec = forward_vec.Perpend() * -0.22;
195 forward_vec = forward_vec * -0.3;
196
197 vector chatch_pos = obj.GetPosition() + forward_vec + side_vec;
198 obj.SetPosition(chatch_pos);
199 }
200 }
201}
202
203class RabbitSnareTrap extends Trap_RabbitSnare
204{
205
206}
void AddAction(typename actionName)
void RemoveAction(typename actionName)
vector GetOrientation()
const int ECE_PLACE_ON_SURFACE
DayZGame g_Game
Definition DayZGame.c:3528
void PlayPlaceSound()
Definition ItemBase.c:9027
void SetIsPlaceSound(bool is_place_sound)
Definition ItemBase.c:8962
bool IsPlaceSound()
Definition ItemBase.c:8967
bool m_IsBeingPlaced
Definition ItemBase.c:4731
string m_AnimationPhaseTriggered
Definition TrapBase.c:34
float m_DefectRate
Definition TrapBase.c:19
void AddDefect()
Definition TrapBase.c:403
void SetActive()
Definition TrapBase.c:409
string m_AnimationPhaseSet
Definition TrapBase.c:33
float m_InitWaitTime
Definition TrapBase.c:17
Definition EnMath.c:7
override void AlignCatch(ItemBase obj, string catch_name)
override string GetLoopDeploySoundset()
override void SpawnCatch()
void Trap_RabbitSnare()
override bool CanBePlaced(Man player, vector position)
override void SetupTrap()
override void OnPlacementComplete(Man player, vector position="0 0 0", vector orientation="0 0 0")
override bool IsDeployable()
override string GetDeploySoundset()
override void OnVariablesSynchronized()
override void SetActions()
proto native CGame GetGame()
proto native void SetPosition(vector position)
Set the world position of the Effect.
Definition Effect.c:420
static proto float RandomFloat(float min, float max)
Returns a random float number between and min[inclusive] and max[exclusive].
static proto int RandomInt(int min, int max)
Returns a random int number between and min [inclusive] and max [exclusive].
static int RandomIntInclusive(int min, int max)
Returns a random int number between and min [inclusive] and max [inclusive].
Definition EnMath.c:54