DayZ 1.24
Loading...
Searching...
No Matches
ActionSkinning.c
Go to the documentation of this file.
1/*
2 Example of skinning config which should be inside animal's base class:
3 class Skinning
4 {
5 // All classes in this scope are parsed, so they can have any name.
6 class ObtainedSteaks
7 {
8 item = "DeerSteakMeat"; // item to spawn
9 count = 10; // How many items to spawn
10 transferToolDamageCoef = 1; // Optional: How much tool's damage is transfered to item's damage.
11
12 // Make sure to have only 1 of the following quantity paramenter
13 quantity = 100; // Optional: Set item's quantity
14 quantityCoef = 1; // Optional: Set item's quantity (in coefficient)
15 quantityMinMax[] = {100, 200}; // Optional: Set item's quantity within min/max values
16 quantityMinMaxCoef[] = {0, 1}; // Optional: Set item's quantity (in coefficient) within min/max values
17 };
18 };
19*/
20
28
30{
31 void ActionSkinning()
36 m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_ANIMALSKINNING;
37 m_StanceMask = DayZPlayerConstants.STANCEMASK_CROUCH;
38 m_FullBody = true;
39 m_Text = "#skin";
40 }
41
47
48 override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
49 {
50 Object targetObject = target.GetObject();
51
52 if (targetObject.CanBeSkinned() && !targetObject.IsAlive())
53 {
55 if (Class.CastTo(target_EAI, targetObject) && target_EAI.CanBeSkinnedWith(item))
56 return true;
57 }
58
59 return false;
60 }
61
62 // Spawns the loot according to the Skinning class in the dead agent's config
64 {
65 super.OnFinishProgressServer(action_data);
66
67 Object targetObject = action_data.m_Target.GetObject();
68
69 // Mark the body as skinned to forbid another skinning action on it
71 body.SetAsSkinned();
72
73 MiscGameplayFunctions.RemoveAllAttachedChildrenByTypename(body, {Bolt_Base});
74
77
78 if (body)
79 GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).Call(GetGame().ObjectDelete, body);
80
81 MiscGameplayFunctions.DealAbsoluteDmg(action_data.m_MainItem, UADamageApplied.SKINNING);
82
84 moduleLifespan.UpdateBloodyHandsVisibility(action_data.m_Player, true);
85 action_data.m_Player.GetSoftSkillsManager().AddSpecialty(m_SpecialtyWeight);
86 }
87
89 {
90 return body_pos + Vector(Math.RandomFloat01() - 0.5, 0, Math.RandomFloat01() - 0.5);
91 }
92
93 // Spawns an organ defined in the given config
95 {
96 // Create item from config
100
101 // Check if skinning is configured for this body
102 if (!added_item)
103 return null;
104
105 // Set randomized position
106 added_item.PlaceOnSurface();
107
108 // Set item's quantity from config, if it's defined there.
109 float item_quantity = 0;
112
113 GetGame().ConfigGetFloatArray(cfg_skinning_organ_class + "quantityMinMax", quant_min_max);
114 GetGame().ConfigGetFloatArray(cfg_skinning_organ_class + "quantityMinMaxCoef", quant_min_max_coef);
115
116
117 // Read config for quantity value
118 if (quant_min_max.Count() > 0)
119 {
120 float soft_skill_manipulated_value = (quant_min_max.Get(0) + quant_min_max.Get(1)) / 2;
121 float min_quantity = player.GetSoftSkillsManager().AddSpecialtyBonus(soft_skill_manipulated_value, this.GetSpecialtyWeight());
122 item_quantity = Math.RandomFloat(min_quantity, quant_min_max.Get(1));
123 }
124
125 if (quant_min_max_coef.Count() > 0)
126 {
127 float coef = Math.RandomFloat(quant_min_max_coef.Get(0), quant_min_max_coef.Get(1));
128 item_quantity = added_item.GetQuantityMax() * coef;
129 }
130
131 if (GetGame().ConfigGetFloat(cfg_skinning_organ_class + "quantity") > 0)
132 item_quantity = g_Game.ConfigGetFloat(cfg_skinning_organ_class + "quantity");
133
134 if (GetGame().ConfigGetFloat(cfg_skinning_organ_class + "quantityCoef") > 0)
135 {
136 float coef2 = g_Game.ConfigGetFloat(cfg_skinning_organ_class + "quantityCoef");
137 item_quantity = added_item.GetQuantityMax() * coef2;
138 }
139
140 if (item_quantity > 0)
141 {
143 added_item.SetQuantity(item_quantity, false);
144 }
145
146 // Transfer tool's damage to the item's condition
147 float item_apply_tool_damage_coef = GetGame().ConfigGetFloat(cfg_skinning_organ_class + "transferToolDamageCoef");
148
150 {
151 float tool_dmg_coef = 1 - tool.GetHealth01();
153 added_item.DecreaseHealthCoef(organ_dmg_coef);
154 }
155
156 added_item.InsertAgent(eAgents.SALMONELLA, 1);
157 return added_item;
158 }
159
161 {
162 super.OnFinishProgressClient(action_data);
163
164 if (action_data.m_Target)
165 {
166 Object target_obj = action_data.m_Target.GetObject();
167
168 if (target_obj.IsKindOf("Animal_CapreolusCapreolus") || target_obj.IsKindOf("Animal_CapreolusCapreolusF") || target_obj.IsKindOf("Animal_CervusElaphus") || target_obj.IsKindOf("Animal_CervusElaphusF"))
169 GetGame().GetAnalyticsClient().OnActionFinishedGutDeer();
170 }
171 }
172
175 {
177 if (Class.CastTo(body, action_data.m_Target.GetObject()))
178 {
179 if (body.IsRestrained() && body.GetHumanInventory().GetEntityInHands())
180 MiscGameplayFunctions.TransformRestrainItem(body.GetHumanInventory().GetEntityInHands(), null, action_data.m_Player, body);
181
182 //Remove splint if target is wearing one
183 if (body.IsWearingSplint())
184 {
185 EntityAI entity = action_data.m_Player.SpawnEntityOnGroundOnCursorDir("Splint", 0.5);
187 EntityAI attachment = body.GetItemOnSlot("Splint_Right");
188 if (attachment && attachment.GetType() == "Splint_Applied")
189 {
190 if (newItem)
191 {
192 MiscGameplayFunctions.TransferItemProperties(attachment, newItem);
193 //Lower health level of splint after use
194 if (newItem.GetHealthLevel() < 4)
195 {
196 int newDmgLevel = newItem.GetHealthLevel() + 1;
197 float max = newItem.GetMaxHealth("", "");
198
199 switch (newDmgLevel)
200 {
203 break;
204
206 newItem.SetHealth("", "", max * GameConstants.DAMAGE_DAMAGED_VALUE);
207 break;
208
210 newItem.SetHealth("", "", max * GameConstants.DAMAGE_WORN_VALUE);
211 break;
212
214 newItem.SetHealth("", "", max * GameConstants.DAMAGE_RUINED_VALUE);
215 break;
216
217 default:
218 break;
219 }
220 }
221 }
222
223 attachment.Delete();
224 }
225 }
226
228 if (GetCEApi())
229 {
230 deadBodyLifetime = GetCEApi().GetCEGlobalInt("CleanupLifetimeDeadPlayer");
231 if (deadBodyLifetime <= 0)
232 deadBodyLifetime = 3600;
233 }
234
236 }
237 }
238
240 {
242 body.GetInventory().EnumerateInventory(InventoryTraversalType.LEVELORDER, children);
243 foreach (EntityAI child : children)
244 {
245 if (child)
246 {
247 child.SetLifetime(newLifetime);
248 body.GetInventory().DropEntity(InventoryMode.SERVER, body, child);
249 }
250 }
251 }
252
254 {
255 EntityAI body = EntityAI.Cast(action_data.m_Target.GetObject());
256
257 // Get config path to the animal
258 string cfg_animal_class_path = "cfgVehicles " + body.GetType() + " " + "Skinning ";
259 vector bodyPosition = body.GetPosition();
260
261 // Getting item type from the config
262 int child_count = g_Game.ConfigGetChildrenCount(cfg_animal_class_path);
263
264 string item_to_spawn;
266 // Parsing of the 'Skinning' class in the config of the dead body
267 for (int i1 = 0; i1 < child_count; i1++)
268 {
269 // To make configuration as convenient as possible, all classes are parsed and parameters are read
270 g_Game.ConfigGetChildName(cfg_animal_class_path, i1, cfg_skinning_organ_class); // out cfg_skinning_organ_class
272 g_Game.ConfigGetText(cfg_skinning_organ_class + "item", item_to_spawn); // out item_to_spawn
273
274 if (item_to_spawn != "") // Makes sure to ignore incompatible parameters in the Skinning class of the agent
275 {
276 // Spawning items in action_data.m_Player's inventory
277 int item_count = g_Game.ConfigGetInt(cfg_skinning_organ_class + "count");
278
281 float zoneDmg = 0;
282
283 GetGame().ConfigGetTextArray(cfg_skinning_organ_class + "itemZones", itemZones);
284 GetGame().ConfigGetFloatArray(cfg_skinning_organ_class + "countByZone", itemCount);
285
286 if (itemCount.Count() > 0)
287 {
288 item_count = 0;
289 for (int z = 0; z < itemZones.Count(); z++)
290 {
291 zoneDmg = body.GetHealth01(itemZones[z], "Health");
292 zoneDmg *= itemCount[z]; //just re-using variable
294 }
295 }
296
297 for (int i2 = 0; i2 < item_count; i2++)
298 {
300
301 //Damage pelts based on the average values on itemZones
302 //It only works if the "quantityCoef" in the config is more than 0
303 float qtCoeff = GetGame().ConfigGetFloat(cfg_skinning_organ_class + "quantityCoef");
304 if (qtCoeff > 0)
305 {
306 float avgDmgZones = 0;
307 for (int c2 = 0; c2 < itemZones.Count(); c2++)
308 avgDmgZones += body.GetHealth01(itemZones[c2], "Health");
309
310 avgDmgZones = avgDmgZones / itemZones.Count(); // Evaluate the average Health
311
312 if (spawn_result)
313 spawn_result.SetHealth01("", "", avgDmgZones);
314 }
315
316 // handle fat/guts from human bodies
317 if ((item_to_spawn == "Lard") || (item_to_spawn == "Guts"))
318 {
319 if (body.IsKindOf("SurvivorBase"))
320 spawn_result.InsertAgent(eAgents.BRAIN, 1);
321 }
322 }
323 }
324 }
325 }
326}
InventoryMode
NOTE: PREDICTIVE is not to be used at all in multiplayer.
Definition Inventory.c:22
bool m_FullBody
Definition ActionBase.c:52
string m_Text
Definition ActionBase.c:49
void CreateConditionComponents()
Definition ActionBase.c:196
float GetSpecialtyWeight()
Definition ActionBase.c:967
ref CCIBase m_ConditionItem
Definition ActionBase.c:55
float m_SpecialtyWeight
Definition ActionBase.c:68
ref CCTBase m_ConditionTarget
Definition ActionBase.c:56
int m_StanceMask
Definition ActionBase.c:53
void SpawnItems(ActionData action_data)
void DropInventoryItems(PlayerBase body, float newLifetime)
vector GetRandomPos(vector body_pos)
void HandlePlayerBody(ActionData action_data)
This section drops all clothes (and attachments) from the dead player before deleting their body.
ActionSkinningCB ActionContinuousBaseCB ActionSkinning()
ItemBase CreateOrgan(PlayerBase player, vector body_pos, string item_to_spawn, string cfg_skinning_organ_class, ItemBase tool)
proto native CEApi GetCEApi()
Get the CE API.
const int ECE_PLACE_ON_SURFACE
DayZGame g_Game
Definition DayZGame.c:3528
eAgents
Definition EAgents.c:3
void PluginLifespan()
PluginBase GetPlugin(typename plugin_type)
ActionData m_ActionData
void OnFinishProgressClient(ActionData action_data)
void OnFinishProgressServer(ActionData action_data)
ref CABase m_ActionComponent
Definition ActionBase.c:30
override void CreateActionComponent()
override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
Super root of all classes in Enforce script.
Definition EnScript.c:11
Definition EnMath.c:7
const float SKINNING
const float PRECISE_MEDIUM
const float SKIN
DayZPlayerConstants
defined in C++
Definition dayzplayer.c:597
InventoryTraversalType
tree traversal type, for more see http://en.wikipedia.org/wiki/Tree_traversal
Definition gameplay.c:6
proto native CGame GetGame()
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
const float DAMAGE_BADLY_DAMAGED_VALUE
Definition constants.c:772
const float DAMAGE_RUINED_VALUE
Definition constants.c:773
const float DAMAGE_DAMAGED_VALUE
Definition constants.c:771
const float DAMAGE_WORN_VALUE
Definition constants.c:770
const int STATE_RUINED
Definition constants.c:757
const int STATE_WORN
Definition constants.c:760
const int STATE_DAMAGED
Definition constants.c:759
const int STATE_BADLY_DAMAGED
Definition constants.c:758
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
static float RandomFloat01()
Returns a random float number between and min [inclusive] and max [inclusive].
Definition EnMath.c:126
static proto float Floor(float f)
Returns floor of value.
static proto float Round(float f)
Returns mathematical round of value.
static proto float RandomFloat(float min, float max)
Returns a random float number between and min[inclusive] and max[exclusive].
const int CALL_CATEGORY_SYSTEM
Definition tools.c:8