DayZ 1.24
Loading...
Searching...
No Matches
PluginLifespan.c
Go to the documentation of this file.
1//-----------------------------
2// LIFESPAN plugin
3//-----------------------------
4/*
5 Lifespan plugin handles player facial hair, bloody hands, blood type in HUD
6*/
7
9{
10 CLEAN = 0,//clean needs to be 0
13 //--- ONLY LAST_INDEX BELLOW !!!
15}
16
18{
23 COUNT = 4,
24}
25
26class PluginLifespan extends PluginBase
27{
28 protected static const int LIFESPAN_MIN = 0;
29 protected static const int LIFESPAN_MAX = 240; // value in minutes when player achieved maximum age in order to have full beard
30 protected int m_FakePlaytime;
31
36
37 //========================================
38 // GetInstance
39 //========================================
44
52
53 //-----------------------------
54 // Player load from config
55 //-----------------------------
57 {
60
62
63 //cfg_name = 'CfgVehicles'
64 // config_name = 'CfgVehicles'
65 //cfg_class_count = 2348
66 // config_count = 2348
67 //cfg_class_name = 'SurvivorMale_Base'
68 // survivor_name = 'SurvivorMale_Base'
69 //cfg_class_fullname = 'CfgVehicles SurvivorMale_Base'
70 // survivor_path = 'CfgVehicles SurvivorMale_Base'
71 //cfg_class_member_count = 10
72 // survivor_lifespan_count = 10
73 //cfg_class_member_name = 'Lifespan'
74 // survivor_lifespan_name = 'Lifespan'
75 //cfg_class_member_fullname = 'CfgVehicles SurvivorMale_Base Lifespan';
76 // survivor_lifespan_path = 'CfgVehicles SurvivorMale_Base Lifespan';
77 //cfg_class_member_member_count = 1
78 // survivor_lifespan_beard_count = 1
79 //cfg_class_member_member_name = 'Beard'
80 // survivor_lifespan_beard_name = 'Beard'
81 //cfg_class_member_member_fullname = 'CfgVehicles SurvivorMale_Base Lifespan Beard'
82 // survivor_lifespan_beard_path = 'CfgVehicles SurvivorMale_Base Lifespan Beard'
83 //cfg_class_member_member_variable_name = 'mat'
84 // survivor_lifespan_beard_material_name = 'mat'
85 //cfg_class_member_member_variable_fullname = 'CfgVehicles SurvivorMale_Base Lifespan Beard mat'
86 // survivor_lifespan_beard_material_path = 'CfgVehicles SurvivorMale_Base Lifespan Beard mat'
87
88 string config_name = "CfgVehicles";
89 int config_count = GetGame().ConfigGetChildrenCount(config_name);
90
91 int i, j, k, l, m;
92
93 //Print( "config_count: " + config_count );
94 for (i = 0; i < config_count; i++)
95 {
96 string survivor_name = "";
97 GetGame().ConfigGetChildName(config_name, i, survivor_name);
98
99 if (survivor_name != "" && survivor_name != "access")
100 {
101 if (GetGame().IsKindOf(survivor_name, "SurvivorMale_Base") || GetGame().IsKindOf(survivor_name, "SurvivorFemale_Base"))
102 {
103 string survivor_path = config_name + " " + survivor_name;
104 int survivor_lifespan_count = GetGame().ConfigGetChildrenCount(survivor_path);
105
106 //Print( "survivor_path: " + survivor_path );
107 for (j = 0; j < survivor_lifespan_count; j++)
108 {
109 string survivor_lifespan_name = "";
110 GetGame().ConfigGetChildName(survivor_path, j, survivor_lifespan_name);
111
113
114 if (survivor_lifespan_name == "Lifespan")
115 {
116 int survivor_lifespan_beard_count = GetGame().ConfigGetChildrenCount(survivor_lifespan_path);
117
118 for (k = 0; k < survivor_lifespan_beard_count; k++)
119 {
122
124
125 if (survivor_lifespan_beard_name == "Beard")
126 {
129
131 {
135
137 {
139
141
142 int level_count = materials.Count() / 2;
143 for (m = 0; m < level_count; m++)
144 {
145 int tex = m * 2;
146 int mat = ((m * 2) + 1);
147 if (mat < materials.Count())
148 {
149 float threshold = (((float)m / (float)(level_count - 1)) * (float)LIFESPAN_LENGTH) + (float)LIFESPAN_MIN;
151 //Print("material a textura a threshold: " + materials.Get(tex) + " " + materials.Get(mat) + " " + threshold );
152 }
153 }
154
155 if (lifespan_levels.Count() > 0)
157 }
158 }
159 }
160 }
161 }
162 else if (survivor_lifespan_name == "BloodyHands")
163 {
165 string path_normal = survivor_lifespan_path + " mat_normal";
166 string path_bloody = survivor_lifespan_path + " mat_blood";
167 GetGame().ConfigGetText(path_normal, normal_material);
168 GetGame().ConfigGetText(path_bloody, bloody_material);
170 }
171 }
172 }
173 }
174 }
175
176 /*for ( int cl = 0; cl < m_LifespanLevels.Count(); cl++ )
177 {
178 string class_name = m_LifespanLevels.GetKey( cl );
179 array<ref LifespanLevel> levels = m_LifespanLevels.GetElement( cl );
180
181 Print( class_name );
182
183 for ( int ll = 0; ll < levels.Count(); ll++)
184 {
185 Print( "lvl: " + levels.Get( ll ).GetLevel() );
186 Print( "treshold: " + levels.Get( ll ).GetThreshold() );
187 Print( "texture: " + levels.Get( ll ).GetTextureName() );
188 Print( "material: " + levels.Get( ll ).GetMaterialName() );
189 }
190 }*/
191 }
192
193 //-----------------------------
194 // Support functions
195 //-----------------------------
196
204
206 {
207 if (!GetGame().IsMultiplayer())
208 {
210 UpdateLifespan(player, true);
211 }
212 }
213
214 //-----------------------------
215 // Facial hair
216 //-----------------------------
217
219 {
220 if (player != null)
221 {
223
224 if (GetGame().IsMultiplayer() && GetGame().IsServer())
226
227 float playerBeard = playerPlaytime - player.GetLastShavedSeconds();
228 playerBeard = playerBeard / 60.0;
229
231 }
232 }
233
234 protected void UpdateLifespanLevel(PlayerBase player, float player_beard, bool force_update = false)
235 {
236 if (!player.IsAlive())
237 return;
238
239 if (m_PlayerCurrentLevel.Contains(player))
240 {
242
243 if (player_beard > current_level.GetThreshold() || force_update)
244 {
246
247 if (next_level != NULL)
248 {
251 }
252 }
253 }
254 else
255 {
256 if (m_LifespanLevels.Contains(player.GetPlayerClass()))
257 {
259
260 if (level != NULL)
261 {
264 }
265 }
266 }
267 }
268
269 protected LifespanLevel GetLifespanLevel(string player_class, float age = 0)
270 {
272
273 if (lifespan_levels != NULL)
274 {
275 for (int i = lifespan_levels.Count() - 1; i >= 0; i--)
276 {
278
279 if (age >= level.GetThreshold())
280 return level;
281 }
282 }
283
284 return NULL;
285 }
286
288 {
289 if (player.m_CorpseState != 0)
290 return;
292 EntityAI players_head = player.GetInventory().FindPlaceholderForSlot(slot_id);
293
294 if (players_head)
295 {
296 switch (level.GetLevel())
297 {
298 case LifeSpanState.BEARD_NONE:
299 {
300 players_head.SetObjectTexture(0, "");
301 players_head.SetObjectMaterial(0, "");
302
303 player.SetFaceTexture(level.GetTextureName());
304 player.SetFaceMaterial(level.GetMaterialName());
305
306 player.SetLifeSpanStateVisible(LifeSpanState.BEARD_NONE);
307 //Print("LifeSpanState.BEARD_NONE");
308 break;
309 }
310 case LifeSpanState.BEARD_MEDIUM:
311 {
312 players_head.SetObjectTexture(0, "");
313 players_head.SetObjectMaterial(0, "");
314
315 player.SetFaceTexture(level.GetTextureName());
316 player.SetFaceMaterial(level.GetMaterialName());
317
318 player.SetLifeSpanStateVisible(LifeSpanState.BEARD_MEDIUM);
319 //Print("LifeSpanState.BEARD_MEDIUM");
320 break;
321 }
322
323 case LifeSpanState.BEARD_LARGE:
324 {
325 players_head.SetObjectTexture(0, "");
326 players_head.SetObjectMaterial(0, "");
327
328 player.SetFaceTexture(level.GetTextureName());
329 player.SetFaceMaterial(level.GetMaterialName());
330
331 player.SetLifeSpanStateVisible(LifeSpanState.BEARD_LARGE);
332 //Print("LifeSpanState.BEARD_LARGE");
333 break;
334 }
335
336 case LifeSpanState.BEARD_EXTRA:
337 {
338 players_head.SetObjectTexture(0, level.GetTextureName());
339 players_head.SetObjectMaterial(0, level.GetMaterialName());
340
343
344 player.SetFaceTexture(prev_level.GetTextureName());
345 player.SetFaceMaterial(prev_level.GetMaterialName());
346
347 player.SetLifeSpanStateVisible(LifeSpanState.BEARD_EXTRA);
348 //Print("LifeSpanState.BEARD_EXTRA");
349 break;
350 }
351
352 default:
353 {
354 Print("Lifespan state missing");
355 break;
356 }
357 }
358 }
359 }
360
362 {
363 float player_beard;
364
365 switch (state)
366 {
367 case LifeSpanState.BEARD_NONE:
368 {
369 // first out of 4 states
371 break;
372 }
373 case LifeSpanState.BEARD_MEDIUM:
374 {
375 // second out of 4 states
377 break;
378 }
379
380 case LifeSpanState.BEARD_LARGE:
381 {
382 // third out of 4 states
384 break;
385 }
386
387 case LifeSpanState.BEARD_EXTRA:
388 {
389 // fourth out of 4 states
391 break;
392 }
393
394 default:
395 {
396 Print("Lifespan state missing");
397 break;
398 }
399 }
400
402 }
403
404 //-----------------------------
405 // Bloody hands
406 //-----------------------------
407
413
419
424
425
427 {
428 player.SetBloodyHandsEx(type);
429
430 if (type)
432 else
434
435 }
436
438 {
439 player.SetBloodyHands(show);
440
441 if (show)
443 else
445 }
446
448 {
449 string player_class = player.GetPlayerClass();
450 int slot_id;
452
453 if (m_BloodyHands.Contains(player_class))
454 {
456 eai = player.GetInventory().FindPlaceholderForSlot(slot_id);
457
458 if (eai)
459 eai.SetObjectMaterial(0, m_BloodyHands.Get(player_class).GetMaterial(material_type));
460 }
461 else
462 {
463 //Print("Error! Player class <" + player_class + "> does not contain valid configuration for bloody hands!");
464 }
465 }
466
468 {
469 return !player.FindAttachmentBySlotName("Gloves"));
470 }
471
472 //-----------------------------
473 // Blood type in HUD
474 //-----------------------------
475
477 {
478 player.SetBloodTypeVisible(show);
479
480 if (player.m_Hud)
481 player.m_Hud.UpdateBloodName();
482 }
483
485 {
486 player.SetBloodType(blood_type);
487 }
488
493
498
499 //-----------------------------
500 // Getters for other systems
501 //-----------------------------
502
504 {
505 if (m_PlayerCurrentLevel.Contains(player))
506 {
508 return current_level.GetTextureName();
509 }
510 return "";
511 }
512
514 {
515 if (m_PlayerCurrentLevel.Contains(player))
516 {
518 return current_level.GetMaterialName();
519 }
520 return "";
521 }
522}
void SetPlayerLifespanLevel(PlayerBase player, LifespanLevel level)
void UpdateBloodyHandsVisibility(PlayerBase player, bool show)
void SynchShowBloodTypeVisual(PlayerBase player, bool show)
static const int LIFESPAN_MAX
enum eBloodyHandsTypes COUNT
void UpdateLifespan(PlayerBase player, bool force_update=false)
void SynchBloodyHandsVisual(PlayerBase player, bool has_bloody_hands)
void SetBloodyHandsEx(PlayerBase player, eBloodyHandsTypes type)
void SynchLifespanVisual(PlayerBase player, int beard_state_visible, bool bloody_hands_visible, bool blood_type_visible, int blood_type)
void SynchBeardVisual(PlayerBase player, int state)
void UpdateBloodTypeVisibility(PlayerBase player, bool show)
void UpdateBloodType(PlayerBase player, int blood_type)
void PluginLifespan()
ref map< PlayerBase, int > m_BloodType
eBloodyHandsTypes
@ JUST_BLOOD
@ CLEAN
@ LAST_INDEX
@ SALMONELA
enum eBloodyHandsTypes BEARD_MEDIUM
enum eBloodyHandsTypes BEARD_NONE
void ChangeFakePlaytime(PlayerBase player, int change)
string GetCurrentHeadMaterial(PlayerBase player)
enum eBloodyHandsTypes BEARD_LARGE
enum eBloodyHandsTypes LIFESPAN_MIN
int m_FakePlaytime
string GetCurrentHeadTexture(PlayerBase player)
void SetHandsMaterial(PlayerBase player, int material_type)
ref map< string, ref BloodyHands > m_BloodyHands
void UpdateLifespanLevel(PlayerBase player, float player_beard, bool force_update=false)
enum eBloodyHandsTypes BEARD_EXTRA
void SetBloodyHands(PlayerBase player, bool show)
bool CanMakeHandsBloody(PlayerBase player)
LifespanLevel GetLifespanLevel(string player_class, float age=0)
ref map< string, ref array< ref LifespanLevel > > m_LifespanLevels
void UpdateBloodyHandsVisibilityEx(PlayerBase player, eBloodyHandsTypes type)
ref map< PlayerBase, ref LifespanLevel > m_PlayerCurrentLevel
void SynchShowBloodType(PlayerBase player, int blood_type)
PluginBase GetPlugin(typename plugin_type)
const int MATERIAL_TYPE_BLOODY
Definition BloodyHands.c:6
const int MATERIAL_TYPE_NORMAL
Definition BloodyHands.c:5
provides access to slot configuration
static proto native int GetSlotIdFromString(string slot_name)
converts string to slot_id
static PluginCameraTools GetInstance()
proto native CGame GetGame()
proto void Print(void var)
Prints content of variable to console/log.
array< string > TStringArray
Definition EnScript.c:666