Skip to content

Commit a7e8fd0

Browse files
v5.41
- Add a easter egg: Orange Physics Gun - Add a credits menu - Fix multiple viewmodel error
1 parent bc24edd commit a7e8fd0

2 files changed

Lines changed: 105 additions & 16 deletions

File tree

plugins/TF2Sandbox-PhysicsGun.smx

1.52 KB
Binary file not shown.

scripting/TF2Sandbox-PhysicsGun.sp

Lines changed: 105 additions & 16 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.4"
6+
#define PLUGIN_VERSION "5.41"
77

88
#include <sourcemod>
99
#include <sdkhooks>
@@ -41,13 +41,17 @@ public const float ZERO_VECTOR[3] = {0.0, 0.0, 0.0};
4141

4242
#define MODEL_PHYSICSLASER "materials/sprites/physbeam.vmt"
4343
#define MODEL_HALOINDEX "materials/sprites/halo01.vmt"
44-
#define MODEL_PHYSICSGUNVM "models/weapons/v_superphyscannon.mdl"
44+
char g_strPhysGunVM[2][] =
45+
{
46+
"models/weapons/v_physcannon.mdl",
47+
"models/weapons/v_superphyscannon.mdl"
48+
};
4549
#define MODEL_PHYSICSGUNWM "models/weapons/w_physics.mdl" //"models/weapons/w_superphyscannon.mdl" <- broken world model
4650

4751
static const int g_iPhysicsGunWeaponIndex = 423;//Choose Saxxy(423) because the player movement won't become a villager
4852
static const int g_iPhysicsGunQuality = 1;
4953
static const int g_iPhysicsGunLevel = 99-128; //Level displays as 99 but negative level ensures this is unique
50-
static const int g_iPhysicsGunColor[4] = {0, 191, 255, 255};
54+
int g_iPhysicsGunColor[2][4] = { {255, 50, 0, 255}, {0, 191, 255, 255} };
5155

5256
enum PhysicsGunSequence
5357
{
@@ -67,7 +71,7 @@ ConVar g_cvbFullDuplicate;
6771

6872
int g_iModelIndex;
6973
int g_iHaloIndex;
70-
int g_iPhysicsGunVM;
74+
int g_iPhysicsGunVM[2];
7175
int g_iPhysicsGunWM;
7276

7377
bool g_bPhysGunMode[MAXPLAYERS + 1];
@@ -99,6 +103,8 @@ public void OnPluginStart()
99103
RegAdminCmd("sm_physgun", Command_EquipPhysicsGun, 0, "Equip a Physics Gun");
100104
RegAdminCmd("sm_physicsgun", Command_EquipPhysicsGun, 0, "Equip a Physics Gun");
101105

106+
RegAdminCmd("sm_physguncredits", Command_PhysicsGunCredits, 0, "Open physgun credits menu");
107+
102108
g_cvbCanGrabBuild = CreateConVar("sm_tf2sb_physgun_cangrabbuild", "0", "Enable/disable grabbing buildings", 0, true, 0.0, true, 1.0);
103109
g_cvbFullDuplicate = CreateConVar("sm_tf2sb_physgun_fullduplicate", "0", "Enable/disable full duplicate feature - Disable = Only prop_dynamic", 0, true, 0.0, true, 1.0);
104110

@@ -113,7 +119,8 @@ public void OnMapStart()
113119
{
114120
g_iModelIndex = PrecacheModel(MODEL_PHYSICSLASER);
115121
g_iHaloIndex = PrecacheModel(MODEL_HALOINDEX);
116-
g_iPhysicsGunVM = PrecacheModel(MODEL_PHYSICSGUNVM);
122+
g_iPhysicsGunVM[0] = PrecacheModel(g_strPhysGunVM[0]);
123+
g_iPhysicsGunVM[1] = PrecacheModel(g_strPhysGunVM[1]);
117124
g_iPhysicsGunWM = PrecacheModel(MODEL_PHYSICSGUNWM);
118125

119126
PrecacheSound(SOUND_MODE);
@@ -216,6 +223,12 @@ public Action Command_EquipPhysicsGun(int client, int args)
216223
int weapon = CreateEntityByName("tf_weapon_builder");
217224
if (IsValidEntity(weapon))
218225
{
226+
int iTFViewModel = EntRefToEntIndex(g_iClientVMRef[client]);
227+
if (IsValidEntity(iTFViewModel))
228+
{
229+
AcceptEntityInput(iTFViewModel, "Kill");
230+
}
231+
219232
SetEntityModel(weapon, MODEL_PHYSICSGUNWM);
220233
SetEntProp(weapon, Prop_Send, "m_iItemDefinitionIndex", g_iPhysicsGunWeaponIndex);
221234
SetEntProp(weapon, Prop_Send, "m_bInitialized", 1);
@@ -249,6 +262,55 @@ public Action Command_EquipPhysicsGun(int client, int args)
249262
return Plugin_Continue;
250263
}
251264

265+
public Action Command_PhysicsGunCredits(int client, int args)
266+
{
267+
char menuinfo[1024];
268+
Menu menu = new Menu(Handler_PhysicsGunCredits);
269+
270+
Format(menuinfo, sizeof(menuinfo), "TF2 Physics Gun - Credits\n \nDeveloper: BattlefieldDuck, LeadKiller\n \nEaster EGG:");
271+
menu.SetTitle(menuinfo);
272+
273+
Format(menuinfo, sizeof(menuinfo), "Orange Physgun");
274+
menu.AddItem("ORANGE", menuinfo);
275+
276+
menu.ExitBackButton = false;
277+
menu.ExitButton = false;
278+
menu.Display(client, MENU_TIME_FOREVER);
279+
}
280+
281+
public int Handler_PhysicsGunCredits(Menu menu, MenuAction action, int client, int selection)
282+
{
283+
if (action == MenuAction_Select)
284+
{
285+
char info[32];
286+
menu.GetItem(selection, info, sizeof(info));
287+
288+
if (StrEqual(info, "ORANGE"))
289+
{
290+
Command_EquipPhysicsGun(client, -1);
291+
292+
int weapon = GetPlayerWeaponSlot(client, WEAPON_SLOT);
293+
if (IsValidEntity(weapon))
294+
{
295+
SetEntProp(weapon, Prop_Send, "m_nSkin", 0);
296+
}
297+
}
298+
299+
Command_PhysicsGunCredits(client, -1);
300+
}
301+
else if (action == MenuAction_Cancel)
302+
{
303+
if (selection == MenuCancel_ExitBack)
304+
{
305+
306+
}
307+
}
308+
else if (action == MenuAction_End)
309+
{
310+
delete menu;
311+
}
312+
}
313+
252314
public void Event_PlayerSpawn(Event event, const char[] name, bool dontBroadcast)
253315
{
254316
int client = GetClientOfUserId(event.GetInt("userid"));
@@ -474,7 +536,7 @@ int TF2_EquipWearable(int client, int entity)
474536
if (g_hSdkEquipWearable != INVALID_HANDLE) SDKCall(g_hSdkEquipWearable, client, entity);
475537
}
476538

477-
int CreateOutline(int entity)
539+
int CreateOutline(int client, int entity)
478540
{
479541
int ent = CreateEntityByName("tf_glow");
480542
if(IsValidEntity(ent))
@@ -489,7 +551,15 @@ int CreateOutline(int entity)
489551
DispatchKeyValue(ent, "target", strName);
490552

491553
DispatchKeyValue(ent, "Mode", "0");
492-
DispatchKeyValue(ent, "GlowColor", "135 224 230 255");
554+
555+
if (GetPhysGunWorldModelSkin(client))
556+
{
557+
DispatchKeyValue(ent, "GlowColor", "135 224 230 255");
558+
}
559+
else
560+
{
561+
DispatchKeyValue(ent, "GlowColor", "255 170 0 255");
562+
}
493563

494564
DispatchSpawn(ent);
495565

@@ -513,9 +583,10 @@ int CreateGlow(int client)
513583

514584
SetVariantString("4");
515585
AcceptEntityInput(ent, "brightness");
516-
517-
char strColor[18];
518-
Format(strColor, sizeof(strColor), "%i %i %i %i", g_iPhysicsGunColor[0], g_iPhysicsGunColor[1], g_iPhysicsGunColor[2], g_iPhysicsGunColor[3]);
586+
587+
int color = GetPhysGunWorldModelSkin(client);
588+
char strColor[32];
589+
Format(strColor, sizeof(strColor), "%i %i %i %i", g_iPhysicsGunColor[color][0], g_iPhysicsGunColor[color][1], g_iPhysicsGunColor[color][2], g_iPhysicsGunColor[color][3]);
519590
SetVariantString(strColor);
520591
AcceptEntityInput(ent, "color");
521592

@@ -605,7 +676,7 @@ stock void ClientSettings(int client, int &buttons, int &impulse, float vel[3],
605676
SetEntProp(iViewModel, Prop_Send, "m_fEffects", GetEntProp(iViewModel, Prop_Send, "m_fEffects") | EF_NODRAW);
606677

607678
//Create client physics gun viewmodel
608-
g_iClientVMRef[client] = EntIndexToEntRef(CreateVM(client, g_iPhysicsGunVM));
679+
g_iClientVMRef[client] = EntIndexToEntRef(CreateVM(client, g_iPhysicsGunVM[GetPhysGunWorldModelSkin(client)]));
609680

610681
int iTFViewModel = EntRefToEntIndex(g_iClientVMRef[client]);
611682
if (IsValidEntity(iTFViewModel))
@@ -774,7 +845,7 @@ stock void PhysGunSettings(int client, int &buttons, int &impulse, float vel[3],
774845
AcceptEntityInput(iGrabOutline, "Kill");
775846
}
776847

777-
iGrabOutline = CreateOutline(iEntity);
848+
iGrabOutline = CreateOutline(client, iEntity);
778849
if (IsValidEntity(iGrabOutline))
779850
{
780851
g_iGrabOutlineRef[client] = EntIndexToEntRef(iGrabOutline);
@@ -1040,7 +1111,7 @@ stock void PhysGunSettings(int client, int &buttons, int &impulse, float vel[3],
10401111
int beamspeed = (iEntity != INVALID_ENT_REFERENCE) ? 20 : 10;
10411112

10421113
//Set up client's beam
1043-
TE_SetupBeamEnts(iGrabPoint, clientvm, g_iModelIndex, g_iHaloIndex, 0, 10, 0.1, beamwidth, beamwidth, 0, 0.0, g_iPhysicsGunColor, beamspeed, 20);
1114+
TE_SetupBeamEnts(iGrabPoint, clientvm, g_iModelIndex, g_iHaloIndex, 0, 10, 0.1, beamwidth, beamwidth, 0, 0.0, GetPhysGunColor(client), beamspeed, 20);
10441115
TE_SendToClient(client);
10451116

10461117
//Set up global beam
@@ -1050,7 +1121,7 @@ stock void PhysGunSettings(int client, int &buttons, int &impulse, float vel[3],
10501121
if (client != i && IsClientInGame(i))
10511122
{
10521123
int iWeaponWM = GetPlayerWeaponSlot(client, WEAPON_SLOT);
1053-
TE_SetupBeamEnts(iGrabPoint, IsValidEntity(iWeaponWM) ? iWeaponWM : client, g_iModelIndex, g_iHaloIndex, 0, 10, 0.1, beamwidth, beamwidth, 0, 0.0, g_iPhysicsGunColor, beamspeed, 20);
1124+
TE_SetupBeamEnts(iGrabPoint, IsValidEntity(iWeaponWM) ? iWeaponWM : client, g_iModelIndex, g_iHaloIndex, 0, 10, 0.1, beamwidth, beamwidth, 0, 0.0, GetPhysGunColor(client), beamspeed, 20);
10541125

10551126
TE_SendToClient(i);
10561127
}
@@ -1137,7 +1208,8 @@ stock void PhysGunSettings(int client, int &buttons, int &impulse, float vel[3],
11371208
char strMode[50], strHints[256];
11381209
strMode = (g_bPhysGunMode[client]) ? "Garry's Mod" : "TF2Sandbox";
11391210

1140-
SetHudTextParams(0.75, 0.45, 0.05, g_iPhysicsGunColor[0], g_iPhysicsGunColor[1], g_iPhysicsGunColor[2], g_iPhysicsGunColor[3], 0, 0.0, 0.0, 0.0);
1211+
int color = GetPhysGunWorldModelSkin(client);
1212+
SetHudTextParams(0.75, 0.45, 0.05, g_iPhysicsGunColor[color][0], g_iPhysicsGunColor[color][1], g_iPhysicsGunColor[color][2], g_iPhysicsGunColor[color][3], 0, 0.0, 0.0, 0.0);
11411213

11421214
int iEntity = EntRefToEntIndex(g_iGrabEntityRef[client]);
11431215
if (iEntity != INVALID_ENT_REFERENCE)
@@ -1207,6 +1279,24 @@ char[] GetEntityName(int entity)
12071279
return strName;
12081280
}
12091281

1282+
int GetPhysGunWorldModelSkin(int client)
1283+
{
1284+
int weapon = GetPlayerWeaponSlot(client, WEAPON_SLOT);
1285+
return GetEntProp(weapon, Prop_Send, "m_nSkin");
1286+
}
1287+
1288+
int[] GetPhysGunColor(int client)
1289+
{
1290+
int color = GetPhysGunWorldModelSkin(client);
1291+
int acolor[4];
1292+
acolor[0] = g_iPhysicsGunColor[color][0];
1293+
acolor[1] = g_iPhysicsGunColor[color][1];
1294+
acolor[2] = g_iPhysicsGunColor[color][2];
1295+
acolor[3] = g_iPhysicsGunColor[color][3];
1296+
1297+
return acolor;
1298+
}
1299+
12101300
void SetAdjustedAngleX(float fAngle[3])
12111301
{
12121302
AnglesNormalize(fAngle);
@@ -1221,7 +1311,6 @@ void SetAdjustedAngleX(float fAngle[3])
12211311
else if(-45.0 > fAngle[0] && fAngle[0] > -90.0) fAngle[0] = -90.0;
12221312
}
12231313

1224-
12251314
void SetAdjustedAngleY(float fAngle[3])
12261315
{
12271316
AnglesNormalize(fAngle);

0 commit comments

Comments
 (0)