4 bool m_TransferVariables;
6 bool m_ExcludeQuantity;
7 float m_quantity_override;
14 void SetTransferParams (
bool transfer_agents =
true,
bool transfer_variables =
true,
bool transfer_health =
true,
bool exclude_quantity =
false,
float quantity_override = -1)
16 m_TransferAgents = transfer_agents;
17 m_TransferVariables = transfer_variables;
18 m_TransferHealth = transfer_health;
19 m_ExcludeQuantity = exclude_quantity;
20 m_quantity_override = quantity_override;
25 super.CopyOldPropertiesToNew(old_item, new_item);
29 MiscGameplayFunctions.TransferItemProperties(old_item, new_item, m_TransferAgents, m_TransferVariables, m_TransferHealth, m_ExcludeQuantity);
30 MiscGameplayFunctions.TransferInventory(old_item, new_item,
m_Player);
33 if (
ItemBase.Cast(new_item) && m_quantity_override != -1)
35 m_quantity_override =
Math.Max(m_quantity_override,0);
36 ItemBase.Cast(new_item).SetQuantity(m_quantity_override);
41 Debug.LogError(
"TurnItemIntoItemLambda: failed to create new item",
"static");
46 override void VerifyItemTypeBySlotType ()
48 if (m_NewLocation.GetType() ==
InventoryLocationType.ATTACHMENT && m_OldItem.ConfigIsExisting(
"ChangeIntoOnAttach"))
56 m_OldItem.ConfigGetTextArray(
"ChangeInventorySlot",inventory_slots);
57 if (inventory_slots.Count() < 1)
59 inventory_slots_idx.Insert(
InventorySlots.GetSlotIdFromString(m_OldItem.ConfigGetString(
"ChangeInventorySlot")));
60 attach_types.Insert(m_OldItem.ConfigGetString(
"ChangeIntoOnAttach"));
64 inventory_slots_idx.Clear();
65 for (
int i = 0; i < inventory_slots.Count(); ++i)
67 inventory_slots_idx.Insert(
InventorySlots.GetSlotIdFromString(inventory_slots.Get(i)));
69 m_OldItem.ConfigGetTextArray(
"ChangeIntoOnAttach",attach_types);
72 idx = m_NewLocation.GetSlot();
73 str = attach_types.Get(inventory_slots_idx.Find(idx));
81 override void OnSuccess (
EntityAI new_item)
83 super.OnSuccess(new_item);
86 m_Player.GetItemAccessor().OnItemInHandsChanged();
95 super.OnSuccess(new_item);
103class TurnItemIntoItemLambdaRestrainLambda
extends TurnItemIntoItemLambdaAnimSysNotifyLambda
107 super.OnSuccess(new_item);
126 super.CopyOldPropertiesToNew(old_item, new_item);
132 int count = children.Count();
133 for (
int i = 0; i < count; ++i)
139 child.GetInventory().GetCurrentInventoryLocation(child_src);
145 Math3D.MatrixIdentity4(m4);
150 child_dst.SetGround(child,m4);
152 m_Player.LocalTakeToDst(child_src, child_dst);
154 GetGame().RemoteObjectTreeCreate(child);
172 if (new_item_type !=
string.
Empty)
173 Error(
"MoveEquipAndDestroyRootLambda expects new_item_type to be empty");
178 super.RemoveNetworkObjectInfo();
183 super.UndoRemoveNetworkObjectInfo();
190 super.CopyOldPropertiesToNew(old_item, new_item);
197 super.CreateNetworkObjectInfo(new_item);
213class MiscGameplayFunctions
216 static float Truncate(
float value,
int decimals = 2)
218 int multiplier =
Math.Pow(10,decimals);
219 return Math.Clamp(
Math.Floor(value * multiplier),
float.LOWEST,
float.MAX) / multiplier;
222 static string TruncateToS(
float value,
int decimals = 2)
224 return Truncate(value, decimals).ToString();
227 static vector TruncateVec(
vector value,
int decimals = 2)
229 int multiplier =
Math.Pow(10,decimals);
230 float v1 =
Math.Clamp(
Math.Floor(value[0] * multiplier),
float.LOWEST,
float.MAX) / multiplier;
231 float v2 =
Math.Clamp(
Math.Floor(value[1] * multiplier),
float.LOWEST,
float.MAX) / multiplier;
232 float v3 =
Math.Clamp(
Math.Floor(value[2] * multiplier),
float.LOWEST,
float.MAX) / multiplier;
236 static string TruncateVecToS(
vector value,
int decimals = 2,
string delimiter =
" ")
238 return MiscGameplayFunctions.TruncateToS(value[0],decimals) + delimiter + MiscGameplayFunctions.TruncateToS(value[1],decimals) +delimiter + MiscGameplayFunctions.TruncateToS(value[2],decimals);
243 return string.Format(
"#(argb,8,8,3)color(%1,CO)",
string.Format(
"%1,%2,%3,%4", r, g, b, a));
247 static string ValueToBar(
float value,
string bar =
"[----------]",
string mark =
"x")
249 int length = bar.Length() - 2;
250 float index =
Math.Lerp(0,length, value);
251 index =
Math.Round(index);
252 index =
Math.Clamp(index,0,length);
254 return InsertAtPos(bar,mark,index);
258 static string InsertAtPos(
string base,
string insert,
int pos)
260 int length_first = pos+1;
261 int length_base = base.Length();
262 int length_second = length_base - length_first;
263 string first = base.Substring(0,length_first);
264 string second = base.Substring(pos+1,length_second);
265 return first + insert + second;
269 static void TransferItemProperties(
EntityAI source, notnull
EntityAI target,
bool transfer_agents =
true,
bool transfer_variables =
true,
bool transfer_health =
true,
bool exclude_quantity =
false)
273 if (transfer_agents && target_ib)
274 target_ib.TransferAgents(source.GetAgents());
276 if (transfer_variables)
277 MiscGameplayFunctions.TransferEntityVariables(source, target, exclude_quantity);
283 TransferEntityHealth(source,target,{
"Health"});
288 static void TransferEntityVariables(
EntityAI source,
EntityAI target,
bool exclude_quantity =
false)
290 if (exclude_quantity)
292 int maskOriginal = source.m_VariablesMask;
294 target.TransferVariablesFloat(source.GetVariablesFloat());
295 source.m_VariablesMask = maskOriginal;
299 target.TransferVariablesFloat(source.GetVariablesFloat());
302 if (source.IsMagazine() && target.IsMagazine())
304 Magazine source_mag = Magazine.Cast(source);
305 Magazine target_mag = Magazine.Cast(target);
307 target_mag.ServerSetAmmoCount(source_mag.GetAmmoCount());
310 if (source.IsWeapon() && target.IsWeapon())
315 target_wpn.CopyWeaponStateFrom(source_wpn);
318 if (source.HasEnergyManager() && target.HasEnergyManager())
331 if (
Class.CastTo(source_edb,source) &&
Class.CastTo(target_edb,target))
339 static void TransferItemVariables(
ItemBase source,
ItemBase target,
bool exclude_quantity =
false)
341 TransferEntityVariables(source,target,exclude_quantity);
350 int count = children.Count();
351 for (
int i = 0; i < count; ++i)
357 child.GetInventory().GetCurrentInventoryLocation( child_src );
360 child_dst.Copy( child_src );
361 child_dst.SetParent( targetItem );
368 targetItem.GetInventory().TakeToDst(
InventoryMode.LOCAL, child_src, child_dst);
377 player.LocalDropEntity(child);
378 GetGame().RemoteObjectTreeCreate(child);
389 if (!healthTypes || healthTypes.Count() == 0)
390 HPTypes.Insert(
"Health");
392 HPTypes.Copy(healthTypes);
394 if (transferZoneDamage)
398 source.GetDamageZones(zonesSrc);
399 target.GetDamageZones(zonesTgt);
401 foreach (
string zone : zonesSrc)
403 if (zonesTgt.Find(zone) == -1)
406 foreach (
string health : HPTypes)
408 target.SetHealth01(zone,health,source.GetHealth01(zone,health));
413 foreach (
string gHealth : HPTypes)
415 target.SetHealth01(
"",gHealth,source.GetHealth01(
"",gHealth));
419 static void UnlimitedAmmoDebugCheck(
Weapon_Base weapon)
426 magazine = weapon.GetMagazine(weapon.GetCurrentMuzzle());
430 if (magazine.GetAmmoCount() <= 5)
432 magazine.ServerSetAmmoMax();
438 magazine = weapon.GetMagazine(weapon.GetCurrentMuzzle());
442 if (magazine.GetAmmoCount() <= 5)
444 magazine.LocalSetAmmoMax();
454 static void TurnItemIntoItem (notnull
ItemBase old_item,
string new_item_type, notnull
PlayerBase player)
461 player.ServerReplaceItemWithNew(lambda);
464 static void TurnItemInHandsIntoItem (notnull
ItemBase old_item,
string new_item_type, notnull
PlayerBase player)
471 player.ServerReplaceItemInHandsWithNew(lambda);
475 static array<ItemBase> CreateItemBasePiles(
string item_name,
vector ground_position,
float quantity,
float health,
bool floaty_spawn =
false)
478 float max_stack_size;
482 max_stack_size =
g_Game.ConfigGetInt(
"cfgVehicles " + item_name +
" varStackMax");
483 if( max_stack_size < 1)
484 max_stack_size =
g_Game.ConfigGetInt(
"cfgVehicles " + item_name +
" varQuantityMax");
485 if( max_stack_size < 1)
488 int full_piles_count =
Math.Floor(quantity/max_stack_size);
489 int rest = quantity - (full_piles_count*max_stack_size);
491 for (
int i = 0; i < full_piles_count; ++i)
497 pile.SetQuantity(max_stack_size);
498 pile.SetHealth(health);
499 item_piles.Insert(pile);
508 pile.SetQuantity(rest);
509 pile.SetHealth(health);
510 item_piles.Insert(pile);
516 static array<ItemBase> CreateItemBasePilesDispersed(
string item_name,
vector starPos,
vector targetPos,
float radius,
float quantity,
float health,
Object ignoreObjectCollison)
519 float max_stack_size;
523 max_stack_size =
g_Game.ConfigGetInt(
"cfgVehicles " + item_name +
" varStackMax");
524 if( max_stack_size < 1)
525 max_stack_size =
g_Game.ConfigGetInt(
"cfgVehicles " + item_name +
" varQuantityMax");
526 if( max_stack_size < 1)
529 int full_piles_count =
Math.Floor(quantity/max_stack_size);
530 int rest = quantity - (full_piles_count*max_stack_size);
533 for (
int i = 0; i < full_piles_count; ++i)
535 randomizedPos = MiscGameplayFunctions.GetRandomizedPositionVerified(starPos,targetPos,radius,ignoreObjectCollison);
537 pile.SetQuantity(max_stack_size);
538 pile.SetHealth(health);
539 item_piles.Insert(pile);
544 randomizedPos = MiscGameplayFunctions.GetRandomizedPositionVerified(starPos,targetPos,radius,ignoreObjectCollison);
546 pile.SetQuantity(rest);
547 pile.SetHealth(health);
548 item_piles.Insert(pile);
553 static array<Magazine> CreateMagazinePiles(
string item_name,
vector ground_position,
float quantity,
float health )
560 stack_size =
g_Game.ConfigGetInt(
"cfgMagazines " + item_name +
" count");
562 int piles_count =
Math.Floor(quantity/stack_size);
563 int rest = quantity - (piles_count*stack_size);
565 for (
int i = 0; i < piles_count; ++i)
568 pile.ServerSetAmmoCount(stack_size);
574 pile.ServerSetAmmoCount(rest);
581 static array<Magazine> CreateMagazinePilesDispersed(
string item_name,
vector starPos,
vector targetPos,
float radius,
float quantity,
float health,
Object ignoreObjectCollison)
588 stack_size =
g_Game.ConfigGetInt(
"cfgMagazines " + item_name +
" count");
590 int piles_count =
Math.Floor(quantity/stack_size);
591 int rest = quantity - (piles_count*stack_size);
594 for (
int i = 0; i < piles_count; ++i)
596 randomizedPos = MiscGameplayFunctions.GetRandomizedPositionVerified(starPos,targetPos,radius,ignoreObjectCollison);
598 pile.ServerSetAmmoCount(stack_size);
604 randomizedPos = MiscGameplayFunctions.GetRandomizedPositionVerified(starPos,targetPos,radius,ignoreObjectCollison);
606 pile.ServerSetAmmoCount(rest);
612 static array<Magazine> CreateMagazinePilesFromBullet(
string bullet_type,
vector ground_position,
float quantity,
float health )
619 if (!
g_Game.ConfigGetText(
"cfgAmmo " + bullet_type +
" spawnPileType", item_name))
622 stack_size =
g_Game.ConfigGetInt(
"cfgMagazines " + item_name +
" count");
626 int piles_count =
Math.Floor(quantity/stack_size);
627 int rest = quantity - (piles_count*stack_size);
629 for (
int i = 0; i < piles_count; ++i)
632 pile.ServerSetAmmoCount(stack_size);
639 pile.ServerSetAmmoCount(rest);
647 static array<Magazine> CreateMagazinePilesFromBulletDispersed(
string bullet_type,
vector starPos,
vector targetPos,
float radius,
float quantity,
float health,
Object ignoreObjectCollison)
652 if (!
g_Game.ConfigGetText(
"cfgAmmo " + bullet_type +
" spawnPileType", item_name))
655 items = CreateMagazinePilesDispersed(item_name,starPos,targetPos,radius,quantity,health,ignoreObjectCollison);
659 static int GetHealthLevelForAmmo(
string class_name,
float health)
661 float health_normalized = health / 100;
675 static float GetTypeMaxGlobalHealth(
string class_name,
string health_type =
"Health")
692 cfg_path = cfg_path +
" "+
class_name+
" DamageSystem GlobalHealth " + health_type +
" hitpoints";
693 max_health =
GetGame().ConfigGetFloat(cfg_path);
700 vector usti_hlavne_position = weapon.GetSelectionPositionMS(
"usti hlavne" );
701 vector konec_hlavne_position = weapon.GetSelectionPositionMS(
"konec hlavne" );
702 vector end_point = weapon.ModelToWorld(usti_hlavne_position);
703 vector begin_point = weapon.ModelToWorld(konec_hlavne_position);
705 int contact_component;
707 vector aim_point = end_point - begin_point;
709 aim_point = aim_point + end_point;
711 if (
DayZPhysics.RaycastRV(begin_point, aim_point, position, contact_dir, contact_component, null, null, null,
false,
false, ObjIntersectFire))
719 int headBoneIdx = player.GetBoneIndexByName(
"Head");
720 if ( headBoneIdx == -1 )
721 { pos = player.GetPosition()[1] + 1.6; }
723 { pos = player.GetBonePositionWS(headBoneIdx); }
729 float headingAngle = GetHeadingAngle(player);
730 dir[0] =
Math.Cos(headingAngle +
Math.PI_HALF);
731 dir[2] =
Math.Sin(headingAngle +
Math.PI_HALF);
733 return dir.Normalized();
739 float headingAngle = hic.GetHeadingAngle();
744 static float GetEnergyMetabolicSpeed(
int movement_speed)
747 switch (movement_speed)
767 static float GetWaterMetabolicSpeed(
int movement_speed)
770 switch (movement_speed)
790 static string ObtainRestrainItemTargetClassname(notnull
EntityAI entity)
792 return entity.ConfigGetString(
"OnRestrainChange");
802 type = tool.ConfigGetBool(
"RestrainUnlockType");
804 string new_item_name = current_item.ConfigGetString(
"OnRestrainChange");
806 if ( new_item_name !=
"" )
810 if (player_target.IsAlive())
811 MiscGameplayFunctions.TurnItemIntoItemEx(player_target,
new ReplaceAndDestroyLambdaEx(current_item, new_item_name, player_target, type));
817 MiscGameplayFunctions.TurnItemIntoItemEx(player_target,
new ReplaceAndDestroyLambdaEx(current_item, new_item_name, player_target, type));
822 Error(
"current_item:" +current_item+
", tool:" +tool +
". No value for 'OnRestrainChange' config parameter");
826 static bool IsValueInRange(
float value,
float from,
float to)
828 return (value >= from) && (value <= to);
836 vector player_dir = player.GetDirection();
837 vector to_target_dir = target_pos - player.GetPosition();
840 to_target_dir[1] = 0;
842 player_dir.Normalize();
843 to_target_dir.Normalize();
845 float cos_fi =
vector.Dot(player_dir, to_target_dir);
846 vector cross = player_dir * to_target_dir;
848 int dir =
Math.Acos(cos_fi) *
Math.RAD2DEG;
854 if( (dir <= cone_angle && dir >= -cone_angle) ||
Math.AbsFloat(dir) == 90 )
863 static string SanitizeString(
string input)
865 int max_length = 512;
866 string output = input;
868 output = output.Substring(0,
Math.Clamp(max_length,0,output.Length()));
873 static bool ComplexBuildCollideCheckClient(
PlayerBase player, ActionTarget target,
ItemBase item,
string partName =
"" )
878 static bool ComplexBuildCollideCheckClient(
PlayerBase player, ActionTarget target,
ItemBase item,
int constraction_index )
883 Construction construction = base_building.GetConstruction();
884 if (construction && BuildCondition( player, target, item,
false, constraction_index ))
897 if (base_building.PerformRoofCheckForBase(partName,player,boo) && boo)
899 if ( player.IsPlacingLocal() || player.IsPlacingServer() )
908 return !construction.IsColliding( partName );
915 static bool BuildCondition(
PlayerBase player, ActionTarget target,
ItemBase item,
bool camera_check )
920 static bool BuildCondition(
PlayerBase player, ActionTarget target,
ItemBase item,
bool camera_check,
int constraction_index )
922 Object targetObject = target.GetObject();
923 if ( targetObject && targetObject.CanUseConstruction() )
927 construction_action_data.
SetTarget( targetObject );
948 if ( constrution_part )
951 bool position_check = ( base_building.MustBeBuiltFromOutside() && !base_building.
IsPlayerInside(player, constrution_part.GetMainPartName()) ) || ( !base_building.MustBeBuiltFromOutside() && base_building.
IsPlayerInside(player, constrution_part.GetMainPartName()) );
952 if ( position_check && !player.GetInputController().CameraIsFreeLook() )
959 return !base_building.
IsFacingCamera( constrution_part.GetMainPartName() );
974 entity.GetCollisionBox(minMax);
978 float from_override = entity.HeightStartCheckOverride();
979 if (from_override > 0.0)
981 size[1] = from_override;
985 size[1] = minMax[1][1] - minMax[0][1];
988 from = entity.GetPosition() + size;
989 if ( entity.HeightCheckOverride() > 0 )
991 to = entity.GetPosition() +
Vector(0, entity.HeightCheckOverride(), 0);
1003 return IsUnderRoofEx(entity, height, ObjIntersectIFire);
1006 static bool IsUnderRoofEx(
EntityAI entity,
float height =
GameConstants.ROOF_CHECK_RAYCAST_DIST,
int geometry = ObjIntersectView)
1011 IsUnderRoofFromToCalculation(entity, from, to, height);
1015 int contact_component;
1017 return DayZPhysics.RaycastRV(from, to, contact_pos, contact_dir, contact_component, NULL, NULL, entity,
false,
false, geometry,0.25);
1024 float steam_offset = 0;
1028 particle_pos = parent.GetPosition();
1030 if ( parent.IsInherited( PortableGasStove ) )
1046 else if ( fireplace.IsFireplaceIndoor() )
1048 steam_offset = 0.45;
1057 particle_pos[1] = particle_pos[1] + steam_offset;
1059 return particle_pos;
1062 static vector GetRandomizedPosition(
vector targetPos,
float radius)
1064 int angle =
Math.RandomIntInclusive(1,360);
1065 float usedRadius =
Math.RandomFloat01() * radius;
1066 vector randomPos =
Vector(targetPos[0] + (
Math.Cos(angle) * usedRadius), targetPos[1], targetPos[2] + (
Math.Sin(angle) * usedRadius));
1073 vector ret = GetRandomizedPosition(targetPos,radius);
1075 params.type = ObjIntersectIFire;
1078 if (
DayZPhysics.RaycastRVProxy(params,results,excluded))
1080 ret = results[0].pos;
1081 ret[1] = targetPos[1];
1086 static vector GetRandomizedPositionVerifiedPlayer(Man player,
float distance,
float radius,
Object ignore)
1089 MiscGameplayFunctions.GetHeadBonePos(
PlayerBase.Cast(player),startPos);
1090 vector targetPos = player.GetPosition() + (player.GetDirection() * distance);
1091 return GetRandomizedPositionVerified(startPos,targetPos,radius,ignore);
1094 static void DropAllItemsInInventoryInBounds(
ItemBase ib,
vector halfExtents)
1101 vector direction = ib.GetDirection();
1104 float angle =
Math.Acos(dot);
1105 if (direction[0] < 0)
1108 float cos =
Math.Cos(angle);
1109 float sin =
Math.Sin(angle);
1112 int count = items.Count();
1113 for (
int i = 0; i < count; ++i )
1115 item = items.Get(i);
1117 ib.GetInventory().DropEntityInBounds(
InventoryMode.SERVER, ib, item, halfExtents, angle, cos, sin);
1121 static void ThrowAllItemsInInventory(notnull
EntityAI parent,
int flags)
1123 vector position = parent.GetPosition();
1124 vector orientation = parent.GetOrientation();
1125 vector rotation_matrix[3];
1129 parent.GetCollisionBox(minmax);
1131 Math3D.YawPitchRollMatrix( orientation, rotation_matrix );
1132 Math3D.MatrixToQuat( rotation_matrix, direction );
1138 count = parent.GetInventory().AttachmentCount();
1139 for (i = 0; i < count; ++i)
1141 ents.Insert(parent.GetInventory().GetAttachmentFromIndex(i));
1145 count = parent.GetInventory().GetCargo().GetItemCount();
1146 for (i = 0; i < count; ++i)
1148 ents.Insert(parent.GetInventory().GetCargo().GetItem(i));
1154 randomPos =
Vector(position[0] +
Math.RandomFloat(minmax[0][0], minmax[1][0]),
1155 position[1] +
Math.RandomFloat(minmax[0][1], minmax[1][1]),
1156 position[2] +
Math.RandomFloat(minmax[0][2], minmax[1][2]));
1161 static void ThrowEntityFromInventory(notnull
EntityAI entity,
vector position,
float direction[4],
vector force,
int flags)
1164 if ( !
GetGame().IsMultiplayer() )
1168 if (CastTo(entityIB, entity))
1171 dst.SetGroundEx(entity, position, direction);
1175 for (
int l = 0; l < entityIB.GetQuantity(); ++l)
1181 MiscGameplayFunctions.TransferItemProperties(entityIB, new_item);
1182 entityIB.AddQuantity( -1 );
1183 new_item.SetQuantity( 1 );
1184 new_item.ThrowPhysically(null, force,
false);
1190 float stackable = entityIB.GetTargetQuantityMax();
1191 if ( !(stackable == 0 || stackable >= entityIB.GetQuantity()) )
1193 while (entityIB.GetQuantity() > stackable)
1196 position[1] = position[1] + 0.1;
1197 spltDst.SetGroundEx(entity, position, direction);
1199 ItemBase splitItem = entityIB.SplitIntoStackMaxToInventoryLocationEx( spltDst );
1200 splitItem.ThrowPhysically(null, force,
false);
1205 entity.GetInventory().GetCurrentInventoryLocation(src);
1207 entity.GetInventory().TakeToDst(invMode, src, dst);
1208 entityIB.ThrowPhysically(null, force,
false);
1213 entity.GetInventory().DropEntity(invMode, entity.GetHierarchyRoot(), entity);
1218 static float GetCurrentItemHeatIsolation(
ItemBase pItem )
1223 float heatIsolation = pItem.GetHeatIsolation();
1224 float itemHealthLabel = pItem.GetHealthLevel();
1225 float itemWetness = pItem.GetWet();
1242 wetFactor =
GameConstants.ENVIRO_ISOLATION_WETFACTOR_SOAKED;
1250 switch (itemHealthLabel)
1253 healthFactor =
GameConstants.ENVIRO_ISOLATION_HEALTHFACTOR_PRISTINE;
1257 healthFactor =
GameConstants.ENVIRO_ISOLATION_HEALTHFACTOR_WORN;
1261 healthFactor =
GameConstants.ENVIRO_ISOLATION_HEALTHFACTOR_DAMAGED;
1265 healthFactor =
GameConstants.ENVIRO_ISOLATION_HEALTHFACTOR_B_DAMAGED;
1269 healthFactor =
GameConstants.ENVIRO_ISOLATION_HEALTHFACTOR_RUINED;
1274 heatIsolation *= healthFactor;
1275 heatIsolation *= wetFactor;
1277 return heatIsolation;
1282 if (!obstructingObjects)
1285 for (
int i = 0; i < potentiallyObstructingObjects.Count(); ++i )
1287 Object obj = potentiallyObstructingObjects[i];
1288 if ( obj && ( obj.CanObstruct() || obj.CanProxyObstruct() ) )
1289 obstructingObjects.Insert(obj);
1293 static bool CanIgnoreDistanceCheck(
Object obj)
1295 return obj.IsTransport() || obj.CanUseConstruction();
1299 static void FilterObstructedObjectsByGrouping(
vector origin,
float range,
float distanceDelta,
array<Object> objects,
array<Object> obstructingObjects, out
array<Object> filteredObjects,
bool doDistanceCheck =
false,
bool checkIfDistanceCanBeIgnored =
false,
float maxDist = 0)
1302 vicinityObjects.Copy(objects);
1307 int mCount = vicinityObjects.Count();
1309 if (!filteredObjects)
1313 if ( doDistanceCheck )
1315 for ( i = vicinityObjects.Count() - 1; i >= 0; --i )
1317 Object obj = vicinityObjects[i];
1318 if ( obj && !CanIgnoreDistanceCheck( obj ) &&
vector.DistanceSq(origin, obj.GetPosition()) > maxDist * maxDist )
1319 vicinityObjects.Remove(i);
1327 float distance, dist1, dist2;
1329 for ( i = 0; i < obstructingObjects.Count(); ++i )
1331 distance =
vector.DistanceSq(obstructingObjects[i].GetWorldPosition(), origin);
1332 distanceHelper.Insert(distance);
1335 distanceHelperUnsorted.Copy(distanceHelper);
1336 distanceHelper.Sort();
1338 for ( i = distanceHelper.Count() - 1; i >= 0; --i )
1339 sortedObstructingObjects.Insert(obstructingObjects[distanceHelperUnsorted.Find(distanceHelper[i])]);
1345 float cos =
Math.Cos(90);
1346 float sin =
Math.Sin(90);
1349 for ( i = 0; i < sortedObstructingObjects.Count(); ++i )
1351 Object obstrObj = sortedObstructingObjects[i];
1352 vector worldPos = obstrObj.GetWorldPosition();
1355 if ( obstrObj.GetCollisionBox(minMax) )
1359 max = max * (obstrObj.GetOrientation() * range);
1361 vector center, dx, dy, dz, half;
1362 center = (min + max) * 0.5;
1363 dz = obstrObj.GetOrientation();
1365 dy =
vector.RotateAroundZero(dz,
vector.Aside, cos, sin);
1366 half = (max - min) * 0.5;
1367 half =
Vector(
Math.AbsFloat(half[0]),
Math.AbsFloat(half[1]),
Math.AbsFloat(half[2]));
1372 for ( j = vicinityObjects.Count() - 1; j >= 0; --j )
1374 Object vicObj = vicinityObjects[j];
1377 vector d = vicObj.GetWorldPosition() - worldPos + center;
1380 group.Insert(vicObj);
1381 vicinityObjects.Remove(j);
1386 if ( group.Count() > 0 )
1387 tempGroups.Insert(group);
1392 for ( i = 0; i < tempGroups.Count(); ++i )
1393 SplitArrayIntoGroupsByDistance(tempGroups[i], objectGroups, distanceDelta);
1396 SplitArrayIntoGroupsByDistance(vicinityObjects, objectGroups, distanceDelta);
1400 for ( i = 0; i < objectGroups.Count(); ++i )
1403 Object sampleObject = objectGroup[0];
1405 if ( !IsObjectObstructedEx(sampleObject, cache) )
1406 filteredObjects.InsertAll(objectGroup);
1415 for (
int i = 0; i < objects.Count(); )
1417 Object obj1 = objects[i];
1422 for (
int j = objects.Count() - 1; j > i; --j )
1424 Object obj2 = objects[j];
1427 vector start = obj1.GetWorldPosition();
1428 vector end = obj2.GetWorldPosition();
1430 float distance =
vector.DistanceSq(start, end);
1431 if ( distance < squaredDistanceDelta )
1438 objectGroups.Insert(group);
1446 static bool IsObjectObstructed(
Object object,
bool doDistanceCheck =
false,
vector distanceCheckPos =
"0 0 0",
float maxDist = 0)
1452 return IsObjectObstructedEx(
object, cache, doDistanceCheck, distanceCheckPos, maxDist);
1461 if (doDistanceCheck &&
vector.DistanceSq(player.GetPosition(), distanceCheckPos) > maxDist * maxDist)
1464 cache.ObjectCenterPos =
object.GetCenter();
1466 return IsObjectObstructedFilterEx(
object, cache, player);
1471 if (
object.CanProxyObstruct())
1474 DayZPhysics.RaycastRVProxy(rayInput, cache.HitProxyObjects);
1475 if (cache.HitProxyObjects)
1477 if (cache.HitProxyObjects.Count() > 0)
1479 if (cache.HitProxyObjects[0].hierLevel > 0)
1482 if (!cache.HitProxyObjects[0].parent.IsMan())
1484 if (cache.HitProxyObjects[0].parent)
1487 if (proxyParent.GetInventory() && proxyParent.GetInventory().GetCargo())
1500 for (
int m = 0; m < cache.HitObjects.Count(); ++m)
1502 Object hit_object = cache.HitObjects.Get(m);
1504 if ( hit_object.CanObstruct() )
1531 if (geometryTypeOverride != -1)
1532 rayInput.type = geometryTypeOverride;
1533 DayZPhysics.RaycastRVProxy(rayInput, cache.HitProxyObjects);
1537 if (cache.HitProxyObjects)
1539 count = cache.HitProxyObjects.Count();
1541 for (i = 0; i < count; ++i)
1543 if (cache.HitProxyObjects[i].hierLevel > 0)
1545 parent = cache.HitProxyObjects[i].parent;
1546 if (parent && !parent.IsMan() && parent.CanProxyObstruct())
1548 if (parent !=
object || (parent ==
object &&
object.CanProxyObstructSelf()))
1556 int geometry = ObjIntersectFire;
1557 if (geometryTypeOverride != -1)
1558 geometry = geometryTypeOverride;
1559 DayZPhysics.RaycastRV(cache.RaycastStart, cache.ObjectCenterPos, cache.ObjectContactPos, cache.ObjectContactDir, cache.ContactComponent, cache.HitObjects,
object,
GetGame().
GetPlayer(),
false,
false, geometry, 0.0,
CollisionFlags.ALLOBJECTS);
1560 count = cache.HitObjects.Count();
1561 for (i = 0; i < count; ++i)
1563 if (cache.HitObjects[i].CanObstruct())
1571 static void DealEvinronmentAdjustedDmg(
ItemBase item,
PlayerBase player,
float baseDamage)
1575 float adjustedDamage;
1578 float modifierSurface =
Surface.GetParamFloat(surfaceType,
"toolDamage");
1579 if (modifierSurface == 0)
1580 modifierSurface = 1;
1582 if (player.GetInColdArea())
1585 adjustedDamage = baseDamage * modifierSurface;
1587 DealAbsoluteDmg(item, adjustedDamage);
1591 static void DealAbsoluteDmg(
ItemBase item,
float dmg)
1593 item.DecreaseHealth(dmg,
false);
1597 static float Normalize(
int val,
int maxVal)
1601 Debug.LogError(
"Division by 0 is not allowed");
1605 return val / maxVal;
1608 static float Bobbing(
float period,
float amplitude,
float elapsedTime)
1614 elapsedTime /= period;
1617 cycle += elapsedTime;
1618 cycle = FModulus(cycle, 360);
1619 cycle =
Math.Sin(cycle) * amplitude;
1625 static float FModulus(
float x,
float y)
1627 return Math.ModFloat(
x,
y);
1630 static void RemoveSplint(
PlayerBase player )
1632 EntityAI entity = player.GetInventory().CreateInInventory(
"Splint");
1634 entity = player.SpawnEntityOnGroundOnCursorDir(
"Splint", 0.5);
1638 Class.CastTo(attachment, player.GetItemOnSlot(
"Splint_Right"));
1639 if ( attachment && attachment.GetType() ==
"Splint_Applied" )
1643 MiscGameplayFunctions.TransferItemProperties(attachment,new_item);
1648 if (new_item.GetHealthLevel() < 4)
1650 int newDmgLevel = new_item.GetHealthLevel() + 1;
1652 float max = new_item.GetMaxHealth(
"",
"");
1654 switch ( newDmgLevel )
1657 new_item.SetHealth(
"",
"", max *
GameConstants.DAMAGE_BADLY_DAMAGED_VALUE );
1661 new_item.SetHealth(
"",
"", max *
GameConstants.DAMAGE_DAMAGED_VALUE );
1665 new_item.SetHealth(
"",
"", max *
GameConstants.DAMAGE_WORN_VALUE );
1669 new_item.SetHealth(
"",
"", max *
GameConstants.DAMAGE_RUINED_VALUE );
1679 attachment.Delete();
1686 if( player.GetSimulationTimeStamp() < 20 && !player.IsPersistentFlag(
PersistentFlag.AREA_PRESENCE) )
1691 vector player_pos = player.GetPosition();
1692 vector closest_safe_pos = MiscGameplayFunctions.GetClosestSafePos(player_pos, safe_positions);
1694 if (player_pos!=closest_safe_pos)
1696 closest_safe_pos[1] =
GetGame().
SurfaceY(closest_safe_pos[0], closest_safe_pos[2]);
1698 player.SetPosition( closest_safe_pos );
1700 GetGame().RPCSingleParam(player,
ERPCs.RPC_WARNING_TELEPORT, null,
true, player.GetIdentity());
1702 PluginAdminLog adminLog = PluginAdminLog.Cast(
GetPlugin(PluginAdminLog));
1704 adminLog.PlayerTeleportedLog(player,player_pos,closest_safe_pos,
"Unwillingly spawning in contaminated area.");
1713 vector closest_pos = to_pos;
1714 float smallest_dist =
float.MAX;
1722 float dist =
vector.DistanceSq(to_pos, vpos);
1723 if ( dist < smallest_dist)
1725 smallest_dist = dist;
1733 static bool TeleportPlayerToSafeLocation3D(notnull
PlayerBase player,
vector safePos)
1735 vector playerPos = player.GetPosition();
1736 if (playerPos != safePos)
1738 player.SetPosition(safePos);
1739 GetGame().RPCSingleParam(player,
ERPCs.RPC_WARNING_TELEPORT, null,
true, player.GetIdentity());
1747 static void GenerateAINoiseAtPosition(
vector position,
float lifeTime,
NoiseParams noiseParams)
1754 noise.AddNoiseTarget(position, lifeTime, noiseParams,
NoiseAIEvaluate.GetNoiseReduction(
GetGame().GetWeather()));
1761 float minValue = 0.0;
1762 for (
int i = 0; i < pArray.Count(); ++i)
1764 if (minValue == 0 || pArray.Get(i) < minValue)
1766 minValue = pArray.Get(i);
1775 float maxValue = 0.0;
1776 for (
int i = 0; i < pArray.Count(); ++i)
1778 if (maxValue == 0 || pArray.Get(i) > maxValue)
1780 maxValue = pArray.Get(i);
1787 static string GetItemDisplayName(
string type)
1789 return GetGame().ConfigGetTextOut(
"CfgVehicles " + type +
" displayName");
1792 static bool IsComponentInSelection(
array<Selection> pSelection,
string pCompName)
1794 if (pSelection.Count() == 0 || pCompName.Length() == 0)
1799 for (
int i = 0; i < pSelection.Count(); ++i)
1801 pCompName.ToLower();
1802 if (pSelection[i] && pSelection[i].GetName() == pCompName)
1813 if (!MiscGameplayFunctions.IsComponentInSelection(pSelection, pCompName))
1818 for (
int i = 0; i < pSelection.Count(); ++i)
1820 pCompName.ToLower();
1821 if (pSelection[i] && pSelection[i].GetName() == pCompName)
1832 if (listOfTypenames.Count() > 0)
1837 Object childToRemove = child;
1838 child =
Object.Cast(child.GetSibling());
1840 if (childToRemove.IsAnyInherited(listOfTypenames))
1842 vector pos = parent.GetPosition();
1843 parent.RemoveChild(childToRemove,
false);
1846 Math3D.MatrixIdentity4(m4);
1848 childToRemove.SetTransform(m4);
1849 childToRemove.PlaceOnSurface();
1857 if (listOfTypenames.Count() > 0)
1862 Object childToRemove = child;
1863 child =
Object.Cast(child.GetSibling());
1865 if (childToRemove.IsAnyInherited(listOfTypenames))
1867 parent.RemoveChild(childToRemove,
false);
1868 childToRemove.Delete();
1880 outputObjects.Insert(child);
1885 static void SoakItemInsideParentContainingLiquidAboveThreshold(notnull
ItemBase item, notnull
ItemBase parent,
float liquidQuantityThresholdPercentage = 0.05)
1889 if (parent.GetLiquidType() != 0 && parent.GetQuantityNormalized() > liquidQuantityThresholdPercentage && !parent.GetIsFrozen())
1894 static float GetCombinedSnowfallWindValue()
1898 g_Game.GetWeather().GetWindMagnitude().GetLimits(windMin, windMax);
1899 float snowfall =
g_Game.GetWeather().GetSnowfall().GetActual();
1900 float value = snowfall +
g_Game.GetWeather().GetWindMagnitude().GetActual() / windMax;
1914 old_item.GetTransform(mtx);
1916 player.GetTransform(mtx);
1917 gnd.SetGround(NULL, mtx);
1918 OverrideNewLocation(gnd);
1923 super.RemoveOldItemFromLocation();
1924 m_Player.GetHumanInventory().OnEntityInHandsDestroyed(m_OldLocation);
InventoryMode
NOTE: PREDICTIVE is not to be used at all in multiplayer.
override void OnSuccess(EntityAI new_item)
const int ECE_PLACE_ON_SURFACE
const int ECE_UPDATEPATHGRAPH
const int ECE_CREATEPHYSICS
override bool IsPlayerInside(PlayerBase player, string selection)
override bool IsFacingCamera(string selection)
proto native float SurfaceY(float x, float z)
proto void SurfaceUnderObject(notnull Object object, out string type, out int liquidType)
Super root of all classes in Enforce script.
void SwitchOn()
Energy manager: Switches ON the device so it starts doing its work if it has enough energy.
float GetEnergy()
Energy manager: Returns the amount of stored energy this device has.
void SetEnergy(float new_energy)
Energy manager: Sets stored energy for this device. It ignores the min/max limit!
bool IsSwitchedOn()
Energy manager: Returns state of the switch. Whenever the device is working or not does not matter....
ConstructionPart GetBuildPartNoToolAtIndex(int idx)
void SetTarget(Object target)
ConstructionPart GetBuildPartAtIndex(int idx)
override void OnItemInHandsChanged()
override void RemoveOldItemFromLocation()
this one is a bit special: it drops all items and destroys the ex-root of the hierarchy
void TransferFoodStage(notnull Edible_Base source)
override bool IsBaseFireplace()
override bool IsIndoorOven()
override bool IsBarrelWithHoles()
script counterpart to engine's class Inventory
static proto native bool PrepareDropEntityPos(EntityAI owner, notnull EntityAI item, out vector mat[4], bool useValuesInMatrix=false, int conflictCheckDepth=-1)
Finds a transformation for the item to be dropped to If the initial transforation overlaps with anoth...
static proto native EntityAI LocationCreateEntity(notnull InventoryLocation inv_loc, string type, int iSetupFlags, int iRotation)
creates new item directly at location
static proto native bool LocationCanAddEntity(notnull InventoryLocation inv_loc)
queries if the entity contained in inv_loc.m_item can be added to ground/attachment/cargo/hands/....
provides access to slot configuration
this one is a also bit special: it moves all items to already existing item and destroys the ex-root ...
base class for transformation operations (creating one item from another)
void UndoRemoveNetworkObjectInfo()
void CreateNetworkObjectInfo(EntityAI new_item)
Step G. - create NetworkObjectInfo for new item.
ref InventoryLocation m_NewLocation
void CopyOldPropertiesToNew(notnull EntityAI old_item, EntityAI new_item)
Step E. copy properties from old object to the created one.
void RemoveNetworkObjectInfo()
Step C. - remove network part of the object @NOTE this operation does not delete the object,...
adds automatic QuickBar handling
float GetColdAreaToolDamageModifier()
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
void Construction(BaseBuildingBase parent)
proto native int GetComponentIndex()
DayZPlayerConstants
defined in C++
bool IsUnderRoof()
Is character under roof (periodically checked - GameConstants.ENVIRO_TICK_ROOF_RC_CHECK)....
const int INDEX_NOT_FOUND
InventoryTraversalType
tree traversal type, for more see http://en.wikipedia.org/wiki/Tree_traversal
proto native CGame GetGame()
void Error(string err)
Messagebox with error message.
const float PROJECTED_CURSOR_DISTANCE
array< string > TStringArray
proto native IEntity GetSibling()
Returns pointer to next child Entity on the same hierarchy.
proto native IEntity GetChildren()
Returns pointer to first child Entity in hierarchy.
const int VARIABLE_QUANTITY
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
proto native vector GetVelocity(notnull IEntity ent)
Returns linear velocity.
proto void dBodyApplyImpulse(notnull IEntity body, vector impulse)
Applies impuls on a rigidbody (origin)
InventoryLocationType
types of Inventory Location
string GetColorString()
Returns item's PROCEDURAL color as formated string, i.e. "#(argb,8,8,3)color(0.15,...
ref array< ref RaycastRVResult > HitProxyObjects
DestroyItemInCorpsesHandsAndCreateNewOnGndLambda RaycastStart
enum ThrowEntityFlags Truncate(float value, int decimals=2)
truncate float to specified precision
ref set< Object > HitObjects
void MoveEquipToExistingItemAndDestroyOldRootLambda(EntityAI old_item, string new_item_type, PlayerBase player, EntityAI new_item)
void IsObjectObstructedCache(vector rayCastStart, int totalObjects)
override void CopyOldPropertiesToNew(notnull EntityAI old_item, EntityAI new_item)
class NoiseSystem NoiseParams()
class OptionSelectorMultistate extends OptionSelector class_name
PluginBase GetPlugin(typename plugin_type)