DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
ShelterSite.c
Go to the documentation of this file.
1class ShelterSite extends BaseBuildingBase
2{
3 const float MAX_ACTION_DETECTION_ANGLE_RAD = 1.3; //1.3 RAD = ~75 DEG
4 const float MAX_ACTION_DETECTION_DISTANCE = 2.0; //meters
5
7 {
8 }
9
10 override string GetConstructionKitType()
11 {
12 return "ShelterKit";
13 }
14
15 override int GetMeleeTargetType()
16 {
17 return EMeleeTargetType.NONALIGNABLE;
18 }
19
20 //--- CONSTRUCTION KIT
22 {
23 if ( MemoryPointExists( "kit_spawn_position" ) )
24 {
25 vector position;
26 position = GetMemoryPointPos( "kit_spawn_position" );
27
28 return ModelToWorld( position );
29 }
30
31 return GetPosition();
32 }
33
34 //--- BUILD EVENTS
35 //CONSTRUCTION EVENTS
36 override void OnPartBuiltServer( notnull Man player, string part_name, int action_id )
37 {
38 ConstructionPart constrution_part = GetConstruction().GetConstructionPart( part_name );
39
40 string shelter_type = "";
41 switch (part_name)
42 {
43 case "leather":
44 shelter_type = "ShelterLeather";
45 break;
46
47 case "fabric":
48 shelter_type = "ShelterFabric";
49 break;
50
51 case "stick":
52 shelter_type = "ShelterStick";
53 break;
54
55 default: {};
56 }
57
58 if (shelter_type != "")
59 {
60 GetConstruction().DropNonUsableMaterialsServer( player, part_name );
61 MiscGameplayFunctions.TurnItemIntoItem(this, shelter_type, PlayerBase.Cast(player));
62
63 PluginAdminLog admin_log = PluginAdminLog.Cast( GetPlugin(PluginAdminLog) );
64 if (admin_log)
65 {
66 string playerPrefix = admin_log.GetPlayerPrefix(PlayerBase.Cast(player), player.GetIdentity());
67 admin_log.DirectAdminLogPrint(playerPrefix +" built " + shelter_type + " with Hands ");
68 }
69 }
70 //super.OnPartBuiltServer( part_name, action_id );
71 }
72
73 override bool CanPutIntoHands( EntityAI parent )
74 {
75 return false;
76 }
77
79 {
80 return true;
81 }
82
83 override bool CanUseHandConstruction()
84 {
85 return true;
86 }
87
88 override bool MustBeBuiltFromOutside()
89 {
90 return true;
91 }
92
93 override bool IsFacingCamera( string selection )
94 {
95 vector ref_dir = GetDirection();
97
98 //ref_dir = GetGame().GetCurrentCameraPosition() - GetPosition();
99 ref_dir.Normalize();
100 ref_dir[1] = 0; //ignore height
101
102 cam_dir.Normalize();
103 cam_dir[1] = 0; //ignore height
104
105 if ( ref_dir.Length() != 0 )
106 {
107 float angle = Math.Acos( cam_dir * ref_dir );
108
109 if ( angle >= MAX_ACTION_DETECTION_ANGLE_RAD )
110 {
111 return true;
112 }
113 }
114
115 return false;
116 }
117
118 override bool IsPlayerInside( PlayerBase player, string selection )
119 {
120 vector player_pos = player.GetPosition();
121 vector object_pos = GetPosition();
122 vector ref_dir = GetDirection();
123 ref_dir[1] = 0;
124 ref_dir.Normalize();
125
126 vector min,max;
127 min = -GetMemoryPointPos( "BoundingBox_min" );
128 max = -GetMemoryPointPos( "BoundingBox_max" );
129
130 vector dir_to_object = object_pos - player_pos;
131 dir_to_object[1] = 0;
132 float len = dir_to_object.Length();
133
134 dir_to_object.Normalize();
135
136 vector ref_dir_angle = ref_dir.VectorToAngles();
137 vector dir_to_object_angle = dir_to_object.VectorToAngles();
138 vector test_angles = dir_to_object_angle - ref_dir_angle;
139
140 vector test_position = test_angles.AnglesToVector() * len;
141
142 if(test_position[0] > max[0] || test_position[0] < min[0] || test_position[2] > max[2] || test_position[2] < min[2] )
143 {
144 return false;
145 }
146
147 return true;
148 }
149
150 override bool HasProperDistance( string selection, PlayerBase player )
151 {
152 if ( MemoryPointExists( selection ) )
153 {
154 vector selection_pos = ModelToWorld( GetMemoryPointPos( selection ) );
155 float distance = vector.Distance( selection_pos, player.GetPosition() );
156 if ( distance >= MAX_ACTION_DETECTION_DISTANCE )
157 {
158 return false;
159 }
160 }
161
162 return true;
163 }
164
165 override void SetActions()
166 {
167 super.SetActions();
168
173 }
174}
ActionFoldBaseBuildingObjectCB ActionContinuousBaseCB ActionFoldBaseBuildingObject()
void AddAction(typename actionName)
Construction GetConstruction()
EMeleeTargetType
PluginBase GetPlugin(typename plugin_type)
class JsonUndergroundAreaTriggerData GetPosition
override bool MustBeBuiltFromOutside()
Definition ShelterSite.c:88
override bool CanUseHandConstruction()
Definition ShelterSite.c:83
override bool IsFacingCamera(string selection)
Definition ShelterSite.c:93
override bool CanBeRepairedToPristine()
Definition ShelterSite.c:78
override bool HasProperDistance(string selection, PlayerBase player)
override bool IsPlayerInside(PlayerBase player, string selection)
override int GetMeleeTargetType()
Definition ShelterSite.c:15
override void OnPartBuiltServer(notnull Man player, string part_name, int action_id)
Definition ShelterSite.c:36
override bool CanPutIntoHands(EntityAI parent)
Definition ShelterSite.c:73
override string GetConstructionKitType()
Definition ShelterSite.c:10
override vector GetKitSpawnPosition()
Definition ShelterSite.c:21
override void SetActions()
proto native vector GetCurrentCameraDirection()
Definition EnMath.c:7
static proto native float Distance(vector v1, vector v2)
Returns the distance between tips of two 3D vectors.
proto float Normalize()
Normalizes vector. Returns length.
proto vector AnglesToVector()
Converts spherical coordinates (yaw, pitch, roll in degrees) to unit length vector.
proto vector VectorToAngles()
Converts vector to spherical coordinates with radius = 1.
proto native float Length()
Returns length of vector (magnitude)
proto native CGame GetGame()
static proto float Acos(float c)
Returns angle in radians from cosinus.