Skip to content

Commit 1aad301

Browse files
v5.1
- Fix outline gitch - Add ConVar sm_tf2sb_physgun_fullduplicate
1 parent deba2dc commit 1aad301

File tree

2 files changed

+52
-54
lines changed

2 files changed

+52
-54
lines changed

plugins/TF2Sandbox-PhysicsGun.smx

-81 Bytes
Binary file not shown.

scripting/TF2Sandbox-PhysicsGun.sp

Lines changed: 52 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#define DEBUG
44

55
#define PLUGIN_AUTHOR "BattlefieldDuck"
6-
#define PLUGIN_VERSION "5.0"
6+
#define PLUGIN_VERSION "5.1"
77

88
#include <sourcemod>
99
#include <sdkhooks>
@@ -61,6 +61,7 @@ enum PhysicsGunSequence
6161
Handle g_hSyncHints;
6262

6363
ConVar g_cvbCanGrabBuild;
64+
ConVar g_cvbFullDuplicate;
6465

6566
int g_iModelIndex;
6667
int g_iHaloIndex;
@@ -95,6 +96,7 @@ public void OnPluginStart()
9596
RegAdminCmd("sm_physicsgun", Command_EquipPhysicsGun, 0, "Equip a Physics Gun");
9697

9798
g_cvbCanGrabBuild = CreateConVar("sm_tf2sb_physgun_cangrabbuild", "0", "Enable/disable grabbing buildings", 0, true, 0.0, true, 1.0);
99+
g_cvbFullDuplicate = CreateConVar("sm_tf2sb_physgun_fullduplicate", "0", "Enable/disable full duplicate feature - Disable = Only prop_dynamic", 0, true, 0.0, true, 1.0);
98100

99101
HookEvent("player_spawn", Event_PlayerSpawn);
100102

@@ -142,20 +144,37 @@ public void OnClientPutInServer(int client)
142144

143145
public void OnClientDisconnect(int client)
144146
{
147+
//Kill Grab Point
145148
int iGrabPoint = EntRefToEntIndex(g_iGrabPointRef[client]);
146149
if (iGrabPoint != INVALID_ENT_REFERENCE && iGrabPoint != 0)
147150
{
148151
AcceptEntityInput(iGrabPoint, "Kill");
149152
}
153+
154+
//Kill Grab Outline
155+
int iGrabOutline = EntRefToEntIndex(g_iGrabOutlineRef[client]);
156+
if (iGrabOutline != INVALID_ENT_REFERENCE && iGrabOutline != 0)
157+
{
158+
AcceptEntityInput(iGrabOutline, "Kill");
159+
}
160+
161+
//Kill Grab Glow
162+
int iGrabGlow = EntRefToEntIndex(g_iGrabGlowRef[client]);
163+
if (iGrabGlow != INVALID_ENT_REFERENCE && iGrabGlow != 0)
164+
{
165+
AcceptEntityInput(iGrabGlow, "Kill");
166+
}
150167
}
151168

169+
//Block sound when client IN_ATTACK
170+
#define SOUND_BLOCK "common/wpn_denyselect.wav"
152171
public Action SoundHook(int clients[64], int& numClients, char sample[PLATFORM_MAX_PATH], int& entity, int& channel, float& volume, int& level, int& pitch, int& flags, char soundEntry[PLATFORM_MAX_PATH], int& seed)
153172
{
154173
for (int i = 1; i <= MaxClients; i++)
155174
{
156175
if (IsClientInGame(i) && IsPlayerAlive(i) && IsHoldingPhysicsGun(i))
157176
{
158-
if (StrEqual(sample, "common/wpn_denyselect.wav"))
177+
if (StrEqual(sample, SOUND_BLOCK))
159178
{
160179
return Plugin_Stop;
161180
}
@@ -188,17 +207,8 @@ public Action Command_EquipPhysicsGun(int client, int args)
188207
return Plugin_Continue;
189208
}
190209

191-
Build_PrintToChat(client, "You have equipped a Physics Gun (Sandbox version)!");
192-
193-
//Set physics gun as Active Weapon
194-
int weapon = GetPlayerWeaponSlot(client, WEAPON_SLOT);
195-
if (IsValidEntity(weapon))
196-
{
197-
SetEntPropEnt(client, Prop_Send, "m_hActiveWeapon", weapon);
198-
}
199-
200210
//Credits: FlaminSarge
201-
weapon = CreateEntityByName("tf_weapon_builder");
211+
int weapon = CreateEntityByName("tf_weapon_builder");
202212
if (IsValidEntity(weapon))
203213
{
204214
SetEntityModel(weapon, MODEL_PHYSICSGUNWM);
@@ -223,7 +233,12 @@ public Action Command_EquipPhysicsGun(int client, int args)
223233
TF2_RemoveWeaponSlot(client, WEAPON_SLOT);
224234
DispatchSpawn(weapon);
225235

226-
EquipPlayerWeapon(client, weapon);
236+
EquipPlayerWeapon(client, weapon);
237+
238+
//Set physics gun as Active Weapon
239+
SetEntPropEnt(client, Prop_Send, "m_hActiveWeapon", weapon);
240+
241+
Build_PrintToChat(client, "You have equipped a Physics Gun (Sandbox version)!");
227242
}
228243

229244
return Plugin_Continue;
@@ -441,52 +456,30 @@ int TF2_EquipWearable(int client, int entity)
441456
if (g_hSdkEquipWearable != INVALID_HANDLE) SDKCall(g_hSdkEquipWearable, client, entity);
442457
}
443458

444-
bool HasOutline(int iEnt)
459+
int CreateOutline(int entity)
445460
{
446-
int index = -1;
447-
while ((index = FindEntityByClassname(index, "tf_glow")) != -1)
461+
int ent = CreateEntityByName("tf_glow");
462+
if(IsValidEntity(ent))
448463
{
449-
if (GetEntPropEnt(index, Prop_Send, "m_hTarget") == iEnt)
450-
{
451-
return true;
452-
}
453-
}
454-
455-
return false;
456-
}
464+
char oldEntName[256];
465+
GetEntPropString(entity, Prop_Data, "m_iName", oldEntName, sizeof(oldEntName));
466+
467+
char strName[128], strClass[64];
468+
GetEntityClassname(entity, strClass, sizeof(strClass));
469+
Format(strName, sizeof(strName), "%s%i", strClass, EntIndexToEntRef(entity));
470+
DispatchKeyValue(entity, "targetname", strName);
471+
DispatchKeyValue(ent, "target", strName);
472+
473+
DispatchKeyValue(ent, "Mode", "0");
474+
DispatchKeyValue(ent, "GlowColor", "135 224 230 255");
475+
476+
DispatchSpawn(ent);
457477

458-
int CreateOutline(int iEnt)
459-
{
460-
if(!HasOutline(iEnt))
461-
{
462-
char oldEntName[64];
463-
GetEntPropString(iEnt, Prop_Data, "m_iName", oldEntName, sizeof(oldEntName));
478+
AcceptEntityInput(ent, "Enable");
464479

465-
char strName[126], strClass[64];
466-
GetEntityClassname(iEnt, strClass, sizeof(strClass));
467-
Format(strName, sizeof(strName), "%s%i", strClass, iEnt);
468-
DispatchKeyValue(iEnt, "targetname", strName);
480+
SetEntPropString(entity, Prop_Data, "m_iName", oldEntName);
469481

470-
int ent = CreateEntityByName("tf_glow");
471-
if(IsValidEntity(ent))
472-
{
473-
DispatchKeyValue(ent, "targetname", "GrabOutline");
474-
DispatchKeyValue(ent, "target", strName);
475-
DispatchKeyValue(ent, "Mode", "0");
476-
477-
char strColor[18];
478-
Format(strColor, sizeof(strColor), "%i %i %i %i", 135, 224, 230, 255);
479-
DispatchKeyValue(ent, "GlowColor", strColor);
480-
481-
DispatchSpawn(ent);
482-
483-
AcceptEntityInput(ent, "Enable");
484-
485-
//Change name back to old name because we don't need it anymore.
486-
SetEntPropString(iEnt, Prop_Data, "m_iName", oldEntName);
487-
488-
return ent;
489-
}
482+
return ent;
490483
}
491484

492485
return -1;
@@ -544,6 +537,11 @@ int Duplicator(int iEntity)
544537
szClass = "prop_physics_override";
545538
}
546539

540+
if (!g_cvbFullDuplicate.BoolValue)
541+
{
542+
szClass = "prop_dynamic_override";
543+
}
544+
547545
GetEntPropString(iEntity, Prop_Data, "m_ModelName", szModel, sizeof(szModel));
548546
GetEntPropVector(iEntity, Prop_Send, "m_vecOrigin", fOrigin);
549547
GetEntPropVector(iEntity, Prop_Data, "m_angRotation", fAngles);

0 commit comments

Comments
 (0)