Skip to content

Commit fe6c945

Browse files
authored
Merge pull request #6 from b3none/ground-bomb
ground bomb if not already on the ground
2 parents c2e7fa7 + 24034c5 commit fe6c945

File tree

1 file changed

+99
-80
lines changed

1 file changed

+99
-80
lines changed

scripting/retakes_autoplant.sp

Lines changed: 99 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -35,42 +35,42 @@ public Plugin myinfo =
3535
public void OnPluginStart()
3636
{
3737
isPluginEnabled = CreateConVar("sm_autoplant_enabled", "1", "Should the autoplant plugin be enabled", _, true, 0.0, true, 1.0);
38-
38+
3939
freezeTime = FindConVar("mp_freezetime");
40-
40+
4141
bombTicking = FindSendPropInfo("CPlantedC4", "m_bBombTicking");
42-
42+
4343
HookEvent("round_start", OnRoundStart, EventHookMode_PostNoCopy);
4444
HookEvent("round_end", OnRoundEnd, EventHookMode_PostNoCopy);
4545
}
4646

4747
public Action OnRoundStart(Event eEvent, const char[] sName, bool bDontBroadcast)
4848
{
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;
7474
}
7575

7676
public void OnRoundEnd(Event event, const char[] sName, bool bDontBroadcast)
@@ -99,23 +99,7 @@ public Action PlantBomb(Handle timer, int client)
9999
ActivateEntity(bombEntity);
100100
TeleportEntity(bombEntity, bombPosition, NULL_VECTOR, NULL_VECTOR);
101101

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);
119103
}
120104
}
121105
}
@@ -131,9 +115,9 @@ public void SendBombPlanted(int client)
131115

132116
if (event != null)
133117
{
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();
137121
}
138122
}
139123

@@ -165,21 +149,21 @@ stock bool SafeRemoveWeapon(int client, int weapon)
165149
}
166150
}
167151
}
168-
152+
169153
return AcceptEntityInput(weapon, "Kill");
170154
}
171155

172156
stock int GetBomber()
173157
{
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;
183167
}
184168

185169
stock bool HasBomb(int client)
@@ -195,30 +179,65 @@ stock bool IsWarmup()
195179

196180
stock int GetNearestBombsite(int client)
197181
{
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+
}
220229
}
221230

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+
222241
stock bool IsValidClient(int client)
223242
{
224243
return client > 0 && client <= MaxClients && IsClientConnected(client) && IsClientInGame(client);

0 commit comments

Comments
 (0)