DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
ActionDigInStash.c
Go to the documentation of this file.
2{
3 override void CreateActionComponent()
4 {
6 }
7};
8
10{
11 static float m_DigStashSlopeTolerance = 0.6;
12
14 {
16 m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_DIGMANIPULATE;
17 m_FullBody = true;
18 m_StanceMask = DayZPlayerConstants.STANCEMASK_ERECT;
20 m_Text = "#bury";
21 }
22
24 {
27 }
28
29 override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
30 {
31 ItemBase targetIB;
32 if (Class.CastTo(targetIB, target.GetObject()) && targetIB.CanBeDigged())
33 {
34 if (player.IsPlacingLocal())
35 {
36 return false;
37 }
38
39 if (targetIB.IsRuined() || targetIB.GetInventory().IsAttachment())
40 {
41 return false;
42 }
43
44 if (targetIB.GetInventory().IsAttachment())
45 {
46 return false;
47 }
48
49 if (targetIB.IsInherited(UndergroundStash))
50 {
51 return false;
52 }
53
55 EntityAI entityToCheck = targetIB;
56 if (targetIB.GetInventory().IsInCargo());
57 entityToCheck = player;
58
59 // here we check if a stash is nearby and block digging a new one in close proximity
60 array<Object> excludedObjects = new array<Object>;
61 excludedObjects.Insert(targetIB);
62 array<Object> nearbyObjects = new array<Object>;
63 // For now we exclude an area of 2 X 2 X 2 meters
64 if (GetGame().IsBoxColliding(entityToCheck.GetPosition(), entityToCheck.GetOrientation(), "2 2 2", excludedObjects, nearbyObjects))
65 {
66 for (int i = 0; i < nearbyObjects.Count(); i++)
67 {
68 if (nearbyObjects[i].IsInherited(UndergroundStash))
69 {
70 return false;
71 }
72 }
73 }
74
75 // Check surface
76 int liquidType;
77 string surfaceType;
78 GetGame().SurfaceUnderObject(entityToCheck, surfaceType, liquidType);
79
80 if (!GetGame().IsSurfaceDigable(surfaceType))
81 {
82 return false;
83 }
84 else
85 {
87 vector position = entityToCheck.GetPosition();
88
89 array<vector> positions = new array<vector>;
90 positions.Insert(position + "0.5 0 0.5");
91 positions.Insert(position + "-0.5 0 0.5");
92 positions.Insert(position + "0.5 0 -0.5");
93 positions.Insert(position + "-0.5 0 -0.5");
94
95 float difference = GetGame().GetHighestSurfaceYDifference(positions);
96
97 return difference < m_DigStashSlopeTolerance;
98 }
99 }
100
101 return false;
102 }
103
104 override void OnExecuteClient(ActionData action_data)
105 {
106 super.OnExecuteClient(action_data);
107
108 SpawnParticleShovelRaise(action_data);
109 }
110
111 override void OnExecuteServer(ActionData action_data)
112 {
113 super.OnExecuteServer(action_data);
114
115 if (!GetGame().IsMultiplayer())
116 {
117 SpawnParticleShovelRaise(action_data);
118 }
119 }
120
122 {
123 ParticleManager.GetInstance().PlayOnObject(ParticleList.DIGGING_STASH, action_data.m_Player);
124 }
125
126 override void OnFinishProgressServer(ActionData action_data)
127 {
128 EntityAI targetEntity = EntityAI.Cast(action_data.m_Target.GetObject());
129 if (!targetEntity)
130 {
131 ErrorEx("Cannot get entity=" + targetEntity);
132 return;
133 }
134
135 InventoryLocation targetIL = new InventoryLocation();
136 if (!targetEntity.GetInventory().GetCurrentInventoryLocation(targetIL))
137 {
138 ErrorEx("Cannot get inventory location of entity=" + targetEntity);
139 return;
140 }
141
142 UndergroundStash stash = UndergroundStash.Cast(GetGame().CreateObjectEx("UndergroundStash", targetEntity.GetPosition(), ECE_PLACE_ON_SURFACE));
143 if (stash)
144 {
145 stash.PlaceOnGround();
147 {
148 action_data.m_Player.ServerTakeEntityToTargetCargo(stash, targetEntity);
149 }
150 else
151 {
152 Debug.Log(string.Format("Cannot remove entity=%1 obj from current location=%2", targetEntity, InventoryLocation.DumpToStringNullSafe(targetIL)));
153 }
154 }
155 else
156 {
157 ErrorEx("Stash not spawned!");
158 }
159
160 //Apply tool damage
161 MiscGameplayFunctions.DealAbsoluteDmg(action_data.m_MainItem, 10);
162 action_data.m_Player.GetSoftSkillsManager().AddSpecialty(m_SpecialtyWeight);
163 }
164
165 override string GetAdminLogMessage(ActionData action_data)
166 {
167 return string.Format("Player %1 Dug in %2 at position %3", action_data.m_Player, action_data.m_Target.GetObject(), action_data.m_Target.GetObject().GetPosition());
168 }
169}
protected float m_SpecialtyWeight
Definition ActionBase.c:68
ref CCIBase m_ConditionItem
Definition ActionBase.c:55
ref CCTBase m_ConditionTarget
Definition ActionBase.c:56
protected string m_Text
Definition ActionBase.c:49
protected bool m_FullBody
Definition ActionBase.c:52
protected int m_StanceMask
Definition ActionBase.c:53
class ActionTargets ActionTarget
const int ECE_PLACE_ON_SURFACE
void ParticleManager(ParticleManagerSettings settings)
Constructor (ctor)
protected ActionData m_ActionData
ItemBase m_MainItem
Definition ActionBase.c:28
PlayerBase m_Player
Definition ActionBase.c:33
ref CABase m_ActionComponent
Definition ActionBase.c:30
ref ActionTarget m_Target
Definition ActionBase.c:32
override void CreateActionComponent()
override void OnFinishProgressServer(ActionData action_data)
override void OnExecuteServer(ActionData action_data)
override string GetAdminLogMessage(ActionData action_data)
override void CreateConditionComponents()
override void OnExecuteClient(ActionData action_data)
void SpawnParticleShovelRaise(ActionData action_data)
override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
static float m_DigStashSlopeTolerance
proto void SurfaceUnderObject(notnull Object object, out string type, out int liquidType)
float GetHighestSurfaceYDifference(array< vector > positions)
Returns the largest height difference between the given positions.
Definition Game.c:1050
Super root of all classes in Enforce script.
Definition EnScript.c:11
Definition Debug.c:14
static void Log(string message=LOG_DEFAULT, string plugin=LOG_DEFAULT, string author=LOG_DEFAULT, string label=LOG_DEFAULT, string entity=LOG_DEFAULT)
Prints debug message with normal prio.
Definition Debug.c:133
script counterpart to engine's class Inventory
Definition Inventory.c:77
static proto native bool LocationCanRemoveEntity(notnull InventoryLocation inv_loc)
queries if the entity contained in inv_loc.m_item can be removed from ground/attachment/cargo/hands/....
InventoryLocation.
static string DumpToStringNullSafe(InventoryLocation loc)
static const int DIGGING_STASH
const float DEFAULT
const float DIG_STASH
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
DayZPlayerConstants
defined in C++
Definition dayzplayer.c:602
proto native CGame GetGame()
enum ShapeType ErrorEx
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
static proto string Format(string fmt, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL)
Gets n-th character from string.