@@ -35,42 +35,42 @@ public Plugin myinfo =
35
35
public void OnPluginStart ()
36
36
{
37
37
isPluginEnabled = CreateConVar (" sm_autoplant_enabled" , " 1" , " Should the autoplant plugin be enabled" , _ , true , 0.0 , true , 1.0 );
38
-
38
+
39
39
freezeTime = FindConVar (" mp_freezetime" );
40
-
40
+
41
41
bombTicking = FindSendPropInfo (" CPlantedC4" , " m_bBombTicking" );
42
-
42
+
43
43
HookEvent (" round_start" , OnRoundStart , EventHookMode_PostNoCopy );
44
44
HookEvent (" round_end" , OnRoundEnd , EventHookMode_PostNoCopy );
45
45
}
46
46
47
47
public Action OnRoundStart (Event eEvent , const char [] sName , bool bDontBroadcast )
48
48
{
49
- hasBombBeenDeleted = false ;
50
-
51
- if (! isPluginEnabled .BoolValue )
52
- {
53
- return Plugin_Continue ;
54
- }
55
-
56
- bomber = GetBomber ();
57
-
58
- if (IsValidClient (bomber ))
59
- {
60
- bombsite = GetNearestBombsite (bomber );
61
-
62
- int bomb = GetPlayerWeaponSlot (bomber , 4 );
63
-
64
- hasBombBeenDeleted = SafeRemoveWeapon (bomber , bomb );
65
-
66
- GetClientAbsOrigin (bomber , bombPosition );
67
-
68
- delete bombTimer ;
69
-
70
- bombTimer = CreateTimer (freezeTime .FloatValue , PlantBomb , bomber );
71
- }
72
-
73
- return Plugin_Continue ;
49
+ hasBombBeenDeleted = false ;
50
+
51
+ if (! isPluginEnabled .BoolValue )
52
+ {
53
+ return Plugin_Continue ;
54
+ }
55
+
56
+ bomber = GetBomber ();
57
+
58
+ if (IsValidClient (bomber ))
59
+ {
60
+ bombsite = GetNearestBombsite (bomber );
61
+
62
+ int bomb = GetPlayerWeaponSlot (bomber , 4 );
63
+
64
+ hasBombBeenDeleted = SafeRemoveWeapon (bomber , bomb );
65
+
66
+ GetClientAbsOrigin (bomber , bombPosition );
67
+
68
+ delete bombTimer ;
69
+
70
+ bombTimer = CreateTimer (freezeTime .FloatValue , PlantBomb , bomber );
71
+ }
72
+
73
+ return Plugin_Continue ;
74
74
}
75
75
76
76
public void OnRoundEnd (Event event , const char [] sName , bool bDontBroadcast )
@@ -99,23 +99,7 @@ public Action PlantBomb(Handle timer, int client)
99
99
ActivateEntity (bombEntity );
100
100
TeleportEntity (bombEntity , bombPosition , NULL_VECTOR , NULL_VECTOR );
101
101
102
- if (! (GetEntityFlags (bombEntity ) & FL_ONGROUND ))
103
- {
104
- float direction [3 ];
105
- float floor [3 ];
106
-
107
- Handle trace ;
108
-
109
- direction [0 ] = 89.0 ;
110
-
111
- TR_TraceRay (bombPosition , direction , MASK_PLAYERSOLID_BRUSHONLY , RayType_Infinite );
112
-
113
- if (TR_DidHit (trace ))
114
- {
115
- TR_GetEndPosition (floor , trace );
116
- TeleportEntity (bombEntity , floor , NULL_VECTOR , NULL_VECTOR );
117
- }
118
- }
102
+ GroundEntity (bombEntity );
119
103
}
120
104
}
121
105
}
@@ -131,9 +115,9 @@ public void SendBombPlanted(int client)
131
115
132
116
if (event != null )
133
117
{
134
- event .SetInt (" userid" , GetClientUserId (client ));
135
- event .SetInt (" site" , bombsite );
136
- event .Fire ();
118
+ event .SetInt (" userid" , GetClientUserId (client ));
119
+ event .SetInt (" site" , bombsite );
120
+ event .Fire ();
137
121
}
138
122
}
139
123
@@ -165,21 +149,21 @@ stock bool SafeRemoveWeapon(int client, int weapon)
165
149
}
166
150
}
167
151
}
168
-
152
+
169
153
return AcceptEntityInput (weapon , " Kill" );
170
154
}
171
155
172
156
stock int GetBomber ()
173
157
{
174
- for (int i = 1 ; i <= MaxClients ; i ++ )
175
- {
176
- if (IsValidClient (i ) && HasBomb (i ))
177
- {
178
- return i ;
179
- }
180
- }
181
-
182
- return - 1 ;
158
+ for (int i = 1 ; i <= MaxClients ; i ++ )
159
+ {
160
+ if (IsValidClient (i ) && HasBomb (i ))
161
+ {
162
+ return i ;
163
+ }
164
+ }
165
+
166
+ return - 1 ;
183
167
}
184
168
185
169
stock bool HasBomb (int client )
@@ -195,30 +179,65 @@ stock bool IsWarmup()
195
179
196
180
stock int GetNearestBombsite (int client )
197
181
{
198
- float pos [3 ];
199
- GetClientAbsOrigin (client , pos );
200
-
201
- int playerResource = GetPlayerResourceEntity ();
202
- if (playerResource == - 1 )
203
- {
204
- return BOMBSITE_INVALID ;
205
- }
206
-
207
- float aCenter [3 ], bCenter [3 ];
208
- GetEntPropVector (playerResource , Prop_Send , " m_bombsiteCenterA" , aCenter );
209
- GetEntPropVector (playerResource , Prop_Send , " m_bombsiteCenterB" , bCenter );
210
-
211
- float aDist = GetVectorDistance (aCenter , pos , true );
212
- float bDist = GetVectorDistance (bCenter , pos , true );
213
-
214
- if (aDist < bDist )
215
- {
216
- return BOMBSITE_A ;
217
- }
218
-
219
- return BOMBSITE_B ;
182
+ float pos [3 ];
183
+ GetClientAbsOrigin (client , pos );
184
+
185
+ int playerResource = GetPlayerResourceEntity ();
186
+ if (playerResource == - 1 )
187
+ {
188
+ return BOMBSITE_INVALID ;
189
+ }
190
+
191
+ float aCenter [3 ], bCenter [3 ];
192
+ GetEntPropVector (playerResource , Prop_Send , " m_bombsiteCenterA" , aCenter );
193
+ GetEntPropVector (playerResource , Prop_Send , " m_bombsiteCenterB" , bCenter );
194
+
195
+ float aDist = GetVectorDistance (aCenter , pos , true );
196
+ float bDist = GetVectorDistance (bCenter , pos , true );
197
+
198
+ if (aDist < bDist )
199
+ {
200
+ return BOMBSITE_A ;
201
+ }
202
+
203
+ return BOMBSITE_B ;
204
+ }
205
+
206
+ /* *
207
+ * https://forums.alliedmods.net/showpost.php?p=2239502&postcount=2
208
+ */
209
+ void GroundEntity (int entity )
210
+ {
211
+ float flPos [3 ], flAng [3 ];
212
+
213
+ GetEntPropVector (entity , Prop_Send , " m_vecOrigin" , flPos );
214
+ flAng [0 ] = 90.0 ;
215
+ flAng [1 ] = 0.0 ;
216
+ flAng [2 ] = 0.0 ;
217
+ Handle hTrace = TR_TraceRayFilterEx (flPos , flAng , MASK_SHOT , RayType_Infinite , TraceFilterIgnorePlayers , entity );
218
+ if (hTrace != INVALID_HANDLE && TR_DidHit (hTrace ))
219
+ {
220
+ float endPos [3 ];
221
+ TR_GetEndPosition (endPos , hTrace );
222
+ CloseHandle (hTrace );
223
+ TeleportEntity (entity , endPos , NULL_VECTOR , NULL_VECTOR );
224
+ }
225
+ else
226
+ {
227
+ PrintToServer (" Attempted to put entity on ground, but no end point found!" );
228
+ }
220
229
}
221
230
231
+ public bool TraceFilterIgnorePlayers (int entity , int contentsMask , int client )
232
+ {
233
+ if (entity >= 1 && entity <= MaxClients )
234
+ {
235
+ return false ;
236
+ }
237
+
238
+ return true ;
239
+ }
240
+
222
241
stock bool IsValidClient (int client )
223
242
{
224
243
return client > 0 && client <= MaxClients && IsClientConnected (client ) && IsClientInGame (client );
0 commit comments