DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
ActionEnterLadder.c
Go to the documentation of this file.
1
3{
4 private const string GEOM_LOD_NAME = LOD.NAME_GEOMETRY;
5 private const string MEM_LOD_NAME = LOD.NAME_MEMORY;
6
8 {
9 m_StanceMask = DayZPlayerConstants.STANCEMASK_CROUCH | DayZPlayerConstants.STANCEMASK_ERECT;
10 m_Text = "#enter_ladder";
11 }
12
14 {
17 }
18
19 override bool ActionCondition( PlayerBase player, ActionTarget target, ItemBase item )
20 {
22 if (!target || !target.GetObject() || player.GetCommand_Ladder() || player.GetCommand_Fall() )
23 return false;
24
25 Building building;
26 if (!Class.CastTo(building, target.GetObject()))
27 return false;
28
29 // TODO: direction tests
30 // Get memory LOD from p3d and save all its selections
31 LOD lod = building.GetLODByName(MEM_LOD_NAME);
32 if(lod == NULL)
33 return false;
34
35 ref array<Selection> memSelection = new array<Selection>();
36 if(!lod.GetSelections(memSelection))
37 return false;
38
40 string compName = building.GetActionComponentName( target.GetComponentIndex() );
41 if( compName.Length() < 6 || compName.Substring(0,6) != "ladder" )
42 {
43 return false;
44 }
45
46 // ze stringu compName dostat posledni cislo a to je index zebriku
47
48 //building.GetActionComponentNameList( action_data.m_Target.GetComponentIndex(), components );
49
50 string condCompName = string.Format("%1_con", compName);
51 vector pos = player.GetPosition();
52 //Print(w);
53 bool found = false;
54 vector ladderEnterPointGlobal;
55 vector ladderDirPointGlobal;
56 float minDistanceSq = 100.0;
57
58 string dirCompName = string.Format("%1_con_dir", compName);
59
60 for ( int i = 0; i < memSelection.Count(); i++ )
61 {
62 if ( memSelection[i].GetName() == condCompName )
63 {
64
65 for( int j = 0; j < memSelection[i].GetVertexCount(); j++ )
66 {
67 ladderEnterPointGlobal = building.ModelToWorld( memSelection[i].GetVertexPosition(lod, j) );
68 if( vector.DistanceSq(ladderEnterPointGlobal,pos) < UAMaxDistances.LADDERS * UAMaxDistances.LADDERS)
69 {
71 found = true;
72 break;
73 }
74 }
75 }
76 }
77
78 if (found)
79 {
80 for (int k = 0; k < memSelection.Count(); k++)
81 {
82 if( memSelection[k].GetName() == dirCompName )
83 {
84 for( int l = 0; l < memSelection[k].GetVertexCount(); l++ )
85 {
86 vector dirPoint = building.ModelToWorld( memSelection[k].GetVertexPosition(lod, l) );
87 float dst = vector.DistanceSq(ladderEnterPointGlobal,dirPoint);
88 if( dst < minDistanceSq)
89 {
90 minDistanceSq = dst;
91 ladderDirPointGlobal = dirPoint;
92 //HumanCommandLadder.DebugDrawLadder(building, HumanCommandLadder.DebugGetLadderIndex(compName));
93 //found = true;
94 }
95 }
96 }
97 }
98
99 pos = pos - ladderEnterPointGlobal;
100 ladderDirPointGlobal = ladderDirPointGlobal - ladderEnterPointGlobal;
101
102 float angle = Math.AbsFloat(pos.VectorToAngles()[0] - ladderDirPointGlobal.VectorToAngles()[0]);
103
104 if ( angle < 90 || angle > 270)
105 {
106 return true;
107 }
108 }
109
110 return false;
111 }
112
113 override void Start( ActionData action_data )
114 {
115 super.Start( action_data );
116 Building b;
117 Class.CastTo(b, action_data.m_Target.GetObject());
118
119 if (b)
120 {
121 string compName = b.GetActionComponentName( action_data.m_Target.GetComponentIndex() );
122 int ladderIndex = HumanCommandLadder.DebugGetLadderIndex(compName);
123
124 LOD geomLod = action_data.m_Target.GetObject().GetLODByName(GEOM_LOD_NAME);
125 string ladderType = "metal";
126
127 for (int i = 0; i < geomLod.GetPropertyCount(); ++i)
128 {
129 if (geomLod.GetPropertyName(i) == "laddertype")
130 {
131 ladderType = geomLod.GetPropertyValue(i);
132 break;
133 }
134 }
135
136 action_data.m_Player.SetClimbingLadderType(ladderType);
137 action_data.m_Player.StartCommand_Ladder(b, ladderIndex );
138 }
139
140
141 /* if( GetGame().IsServer() )
142 {
143 OnStartServer(action_data);
144 }
145 else
146 {
147 OnStartClient(action_data);
148 }*/
149 }
150
151/* override void WriteToContext (ParamsWriteContext ctx,ActionTarget target)
152 {
153 ctx.Write(INPUT_UDT_STANDARD_ACTION);
154 ctx.Write(GetType());
155
156 PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
157 ActionManagerClient AM = ActionManagerClient.Cast( player.GetActionManager());
158 //ActionTarget target = AM.FindActionTarget();
159 Object targetObject = target.GetObject();
160 ctx.Write(targetObject);
161 Object targetParent = target.GetParent();
162 ctx.Write(targetParent);
163 int componentIndex = target.GetComponentIndex();
164 ctx.Write(componentIndex);
165 }
166
167 override void OnStartServer( ActionData action_data )
168 {
169 Print("psovis - server/single");
170
171 Building building;
172 if ( Class.CastTo(building, action_data.m_Target.GetObject()) )
173 {
174 ref array<Selection> memSelections = new array<Selection>();
175
176 // Get memory LOD from p3d and save all its selections
177 LOD lod = building.GetLODByName(MEM_LOD_NAME);
178 if(lod != NULL && lod.GetSelections(memSelections))
179 {
180 Print("Memory selections:");
181 for( int i =0; i < memSelections.Count(); i++ )
182 {
183 if (memSelections[i].GetVertexCount() > 0)
184 {
185 vector pos = memSelections[i].GetVertexPosition(lod, 0);
186 Print(memSelections[i].GetName());
187 Print(pos);
188 }
189 }
190 }
191 }
192 }*/
193
194 /*override void OnStartClient( ActionData action_data )
195 {
196 Print("psovis - client");
197 }*/
198
199 override bool IsInstant()
200 {
201 return true;
202 }
203
204 override bool UseAcknowledgment()
205 {
206 return false;
207 }
208
209 override bool CanBeUsedSwimming()
210 {
211 return true;
212 }
213};
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 int m_StanceMask
Definition ActionBase.c:53
class ActionTargets ActionTarget
PlayerBase m_Player
Definition ActionBase.c:33
ref ActionTarget m_Target
Definition ActionBase.c:32
override bool IsInstant()
private const string GEOM_LOD_NAME
override void Start(ActionData action_data)
override void CreateConditionComponents()
private const string MEM_LOD_NAME
override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
override bool UseAcknowledgment()
override bool CanBeUsedSwimming()
Super root of all classes in Enforce script.
Definition EnScript.c:11
proto static native int DebugGetLadderIndex(string pComponentName)
proto static native bool DebugDrawLadder(Building pBuilding, int pLadderIndex)
debug draws any ladder
LOD class.
Definition gameplay.c:203
proto native owned string GetPropertyValue(int index)
static const string NAME_MEMORY
Definition gameplay.c:208
proto native int GetPropertyCount()
static const string NAME_GEOMETRY
Definition gameplay.c:205
proto native bool GetSelections(notnull out array< Selection > selections)
proto native owned string GetPropertyName(int index)
Definition EnMath.c:7
const float LADDERS
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
static proto native float DistanceSq(vector v1, vector v2)
Returns the square distance between tips of two 3D vectors.
proto vector VectorToAngles()
Converts vector to spherical coordinates with radius = 1.
DayZPlayerConstants
defined in C++
Definition dayzplayer.c:602
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
static proto float AbsFloat(float f)
Returns absolute value.
proto string Substring(int start, int len)
Substring of 'str' from 'start' position 'len' number of characters.
proto native int Length()
Returns length of string.
proto native owned string GetName()