Skip to content

Commit 59dc1e5

Browse files
committed
Improved prop handling
1 parent 83b7c37 commit 59dc1e5

File tree

4 files changed

+38
-61
lines changed

4 files changed

+38
-61
lines changed

tf2gravihands.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
#endif
44
#define _tf2_gravihands
55

6-
#define GRAVIHANDS_VERSION "22w08a"
7-
#define GRAVIHANDS_BUILD 220801
6+
#define GRAVIHANDS_VERSION "22w41a"
7+
#define GRAVIHANDS_BUILD 224101
88

99
/**
1010
* There are two flags that might not be immediately obvious:

tf2gravihands.sp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#pragma newdecls required
3535
#pragma semicolon 1
3636

37-
#define PLUGIN_VERSION "22w13a"
37+
#define PLUGIN_VERSION "22w41a"
3838
//#define PLUGIN_DEBUG
3939

4040
public Plugin myinfo = {
@@ -146,12 +146,6 @@ public void OnLibraryRemoved(const char[] name) {
146146
if (StrEqual(name, "pvpoptin")) { depOptInPvP = false; }
147147
}
148148

149-
//public Action OnLevelInit(const char[] mapName, char mapEntities[2097152]) {
150-
// bPuzzleMap = (StrContains(mapName, "puzzle_")>=0);
151-
// return (bPuzzleMap && ScanOutputs(mapEntities)) ? Plugin_Changed : Plugin_Continue;
152-
//}
153-
154-
155149
public void OnMapStart() {
156150
PrecacheModel(DUMMY_MODEL);
157151
PrecacheSound(GH_SOUND_PICKUP);
@@ -346,7 +340,7 @@ public Action OnNotifyGravihandsActive(Handle timer) {
346340
/** convar **/
347341

348342
void CreateConvars() {
349-
ConVar version = CreateConVar("tf2gravihands_version", PLUGIN_VERSION, "TF2 Puzzle Version", FCVAR_NOTIFY|FCVAR_DONTRECORD);
343+
ConVar version = CreateConVar("tf2gravihands_version", PLUGIN_VERSION, "TF2 Gravity Hands Version", FCVAR_NOTIFY|FCVAR_DONTRECORD);
350344
version.AddChangeHook(OnCVarLockedChange);
351345

352346
cvarGraviHandsMaxWeight = CreateConVar("tf2gravihands_maxmass", "250.0", _, _, true, 0.0);

tf2gravihands_prophandling.sp

Lines changed: 15 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,11 @@ static void computeBounds(int entity, float mins[3], float maxs[3]) {
8787
Entity_GetMinSize(entity, mins);
8888
Entity_GetMaxSize(entity, maxs);
8989
AddVectors(mins,maxs,mins);
90-
ScaleVector(mins,0.5); //mins = now COM
91-
90+
ScaleVector(mins,0.5); //mins = now Center
91+
//now rotate with the prop
92+
float r[3];
93+
Entity_GetAbsAngles(entity, r);
94+
Math_RotateVector(mins, r, mins);
9295
//create equidistant box to keep origin of prop in world
9396
AddVectors(mins,v,maxs);
9497
SubtractVectors(mins,v,mins);
@@ -102,7 +105,6 @@ static int pew(int client, float targetPoint[3], float scanDistance) {
102105
float eyePos[3], eyeAngles[3], fwrd[3];
103106
GetClientEyePosition(client, eyePos);
104107
GetClientEyeAngles(client, eyeAngles);
105-
// GetAngleVectors(eyeAngles, fwrd, NULL_VECTOR, NULL_VECTOR);
106108
Handle trace = TR_TraceRayFilterEx(eyePos, eyeAngles, MASK_SOLID, RayType_Infinite, grabFilter, client);
107109
int cursor = INVALID_ENT_REFERENCE;
108110
if(TR_DidHit(trace)) {
@@ -128,30 +130,14 @@ static int pew(int client, float targetPoint[3], float scanDistance) {
128130
return cursor;
129131
}
130132

131-
//public bool seeCenterFilter(int entity, int contentsMask, int prop) {
132-
// return !entity || (entity > MaxClients && entity != prop);
133-
//}
134-
//
135-
//static bool checkPropCenterVisible(int client, int prop) {
136-
// //require los to COM to be unobstructed
137-
// float vec1[3], vec2[3];
138-
// Entity_GetMinSize(prop, vec1);
139-
// Entity_GetMaxSize(prop, vec2);
140-
// AddVectors(vec1, vec2, vec1);
141-
// ScaleVector(vec1, 0.5);
142-
// GetClientEyePosition(client, vec2);
143-
// TR_TraceRayFilter(vec1, vec2, MASK_SOLID, RayType_EndPoint, seeCenterFilter, prop);
144-
// return !TR_DidHit();
145-
//}
146-
147133
static bool movementCollides(int client, float endpos[3], bool onlyTarget) {
148134
//check if prop would collide at target position
149135
float offset[3], from[3], to[3], mins[3], maxs[3];
150136
int grabbed = EntRefToEntIndex(GravHand[client].grabbedEnt);
151137
if (grabbed == INVALID_ENT_REFERENCE) ThrowError("%L is not currently grabbing anything", client);
152138
//get movement
153139
SubtractVectors(endpos, GravHand[client].lastValid, offset);
154-
Entity_GetAbsOrigin(grabbed, from);
140+
GetEntPropVector(grabbed, Prop_Data, "m_vecAbsOrigin", from);
155141
AddVectors(from, offset, to);
156142
if (onlyTarget) {
157143
from[0]=to[0]-0.1;
@@ -160,9 +146,8 @@ static bool movementCollides(int client, float endpos[3], bool onlyTarget) {
160146
}
161147
computeBounds(grabbed, mins, maxs);
162148
//trace it
163-
Handle trace = TR_TraceHullFilterEx(from, to, mins, maxs, MASK_SOLID, grabFilter, client);
164-
bool result = TR_DidHit(trace);
165-
delete trace;
149+
TR_TraceHullFilter(from, to, mins, maxs, MASK_SOLID, grabFilter, client);
150+
bool result = TR_DidHit();
166151
return result;
167152
}
168153

@@ -171,8 +156,6 @@ static bool movementCollides(int client, float endpos[3], bool onlyTarget) {
171156
* have to check if gravity hands are out.
172157
*/
173158
bool clientCmdHoldProp(int client, int &buttons, float velocity[3], float angles[3]) {
174-
// float yawAngle[3];
175-
// yawAngle[1] = angles[1];
176159
if ((buttons & IN_ATTACK2) && !GravHand[client].forceDropProp) {
177160
if (GetEntPropFloat(client, Prop_Send, "m_flNextAttack") - GetGameTime() < 0.1) {
178161
SetEntPropFloat(client, Prop_Send, "m_flNextAttack", GetGameTime() + 0.5);
@@ -198,7 +181,6 @@ bool clientCmdHoldProp(int client, int &buttons, float velocity[3], float angles
198181
}
199182
return true;
200183
} else if (!(buttons & IN_ATTACK2)) {
201-
// SetEntPropFloat(client, Prop_Send, "m_flFirstPrimaryAttack", GetGameTime()+0.5);
202184
SetEntPropFloat(client, Prop_Send, "m_flNextAttack", GetGameTime());
203185
buttons &=~ IN_ATTACK2;
204186
}
@@ -301,9 +283,10 @@ static bool TryPickupCursorEnt(int client, float yawAngle[3]) {
301283
TeleportEntity(cursorEnt, NULL_VECTOR, NULL_VECTOR, killVelocity);
302284
//grab entity
303285
GravHand[client].grabbedEnt = EntIndexToEntRef(cursorEnt);
304-
float vec[3];
286+
float vec[3], vec2[3];
305287
GetClientEyePosition(client, vec);
306-
GravHand[client].grabDistance = Entity_GetDistanceOrigin(rotProxy, vec);
288+
GetEntPropVector(rotProxy, Prop_Data, "m_vecAbsOrigin", vec2);
289+
GravHand[client].grabDistance = GetVectorDistance(vec2, vec);
307290
//parent to make rotating easier
308291
SetVariantString("!activator");
309292
AcceptEntityInput(cursorEnt, "SetParent", rotProxy);
@@ -392,7 +375,7 @@ bool ForceDropItem(int client, bool punt=false, const float dvelocity[3]=NULL_VE
392375
int entity;
393376
if ((entity = EntRefToEntIndex(GravHand[client].grabbedEnt))!=INVALID_ENT_REFERENCE) {
394377
float vec[3], origin[3];
395-
Entity_GetAbsOrigin(entity, origin);
378+
GetEntPropVector(entity, Prop_Data, "m_vecAbsOrigin", origin);
396379
AcceptEntityInput(entity, "ClearParent");
397380
//fling
398381
bool didPunt;
@@ -401,7 +384,6 @@ bool ForceDropItem(int client, bool punt=false, const float dvelocity[3]=NULL_VE
401384
GetAngleVectors(dvangles, vec, NULL_VECTOR, NULL_VECTOR);
402385
ScaleVector(vec, gGraviHandsPuntForce * 100.0 / Phys_GetMass(entity));
403386
// AddVectors(vec, fwd, vec);
404-
// PrintToServer("Punting Prop with Mass %f", Phys_GetMass(entity));
405387
didPunt=true;
406388
} else if (!movementCollides(client, vec, false)) { //throw with swing
407389
SubtractVectors(vec, GravHand[client].previousEnd, vec);
@@ -411,8 +393,8 @@ bool ForceDropItem(int client, bool punt=false, const float dvelocity[3]=NULL_VE
411393
}
412394
if (!IsNullVector(dvelocity)) AddVectors(vec, dvelocity, vec);
413395
float zeros[3];
414-
TeleportEntity(entity, origin, NULL_VECTOR, zeros); //rest entity
415-
Phys_AddVelocity(entity, vec, zeros);//use vphysics to accelerate, is more stable
396+
TeleportEntity(entity, origin, NULL_VECTOR, zeros); //reset entity
397+
Phys_SetVelocity(entity, vec, zeros, true);//use vphysics to accelerate, is more stable
416398

417399
//fire output that the ent was dropped
418400
{ char classname[64];
@@ -430,7 +412,7 @@ bool ForceDropItem(int client, bool punt=false, const float dvelocity[3]=NULL_VE
430412
didStuff = true;
431413
}
432414
if ((entity = EntRefToEntIndex(GravHand[client].rotProxyEnt))!=INVALID_ENT_REFERENCE) {
433-
RequestFrame(killEntity, entity);
415+
AcceptEntityInput(entity, "Kill");
434416
GravHand[client].rotProxyEnt = INVALID_ENT_REFERENCE;
435417
didStuff = true;
436418
}
@@ -472,11 +454,6 @@ void PlayActionSound(int client, int sound) {
472454
}
473455
}
474456

475-
static void killEntity(int entity) {
476-
if (IsValidEntity(entity))
477-
AcceptEntityInput(entity, "Kill");
478-
}
479-
480457
bool FixPhysPropAttacker(int victim, int& attacker, int& inflictor, int& damagetype) {
481458
if (attacker == inflictor && victim != attacker && !IsValidClient(attacker)) {
482459
char classname[64];

tf2gravihands_weapons.sp

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,23 @@ int EquipPlayerMelee(int client, int definitionIndex, int level=9000, int qualit
6262
}
6363

6464
bool HolsterMelee(int client) {
65-
if (!IsValidClient(client, false))
65+
if (!IsValidClient(client, false)) {
6666
return false; //not for bots
67-
if (player[client].holsteredWeapon != INVALID_ITEM_DEFINITION)
67+
}
68+
if (player[client].holsteredWeapon != INVALID_ITEM_DEFINITION) {
6869
return false; //already holstered
69-
if (player[client].weaponsStripped)
70+
}
71+
if (player[client].weaponsStripped) {
7072
return false; //wow hey, don't holster grav hands
73+
}
7174

7275
int active = Client_GetActiveWeapon(client);
73-
int melee = GetPlayerWeaponSlot(client, TFWeaponSlot_Melee);
76+
int melee = Client_GetWeaponBySlot(client, TFWeaponSlot_Melee);
7477
bool switchTo = (melee == INVALID_ENT_REFERENCE || active != melee); //if melee was not active switch, to holster guns
75-
int holsterIndex = melee == INVALID_ENT_REFERENCE
76-
? INVALID_ITEM_DEFINITION
77-
: GetEntProp(melee, Prop_Send, "m_iItemDefinitionIndex");
78-
78+
int holsterIndex = INVALID_ITEM_DEFINITION;
79+
if (melee != INVALID_ENT_REFERENCE) {
80+
holsterIndex = GetEntProp(melee, Prop_Send, "m_iItemDefinitionIndex");
81+
}
7982
if ((GetClientButtons(client) & (IN_ATTACK|IN_ATTACK2))!=0) {
8083
//holstering while healing someone breaks the medic beam (infinite heal)
8184
PrintToChat(client, "[SM] You can not holster while holding attack buttons!");
@@ -101,7 +104,7 @@ bool HolsterMelee(int client) {
101104
//needs to be set after Equip call due to event order
102105
player[client].holsteredWeapon = holsterIndex;
103106
if (switchTo) Client_SetActiveWeapon(client, fists);
104-
107+
105108
NotifyWeaponHolsterPost(client, holsterIndex);
106109
return true;
107110
}
@@ -113,13 +116,15 @@ void UnholsterMelee(int client) {
113116
RequestFrame(ActualUnholsterMelee, client);
114117
}
115118
void ActualUnholsterMelee(int client) {
116-
if (!IsValidClient(client, false))
119+
if (!IsValidClient(client, false)) {
117120
return; //not for bots
118-
if (player[client].holsteredWeapon == INVALID_ITEM_DEFINITION || player[client].weaponsStripped)
121+
}
122+
if (player[client].holsteredWeapon == INVALID_ITEM_DEFINITION || player[client].weaponsStripped) {
119123
return; //no weapon holstered
120-
121-
if (!NotifyWeaponUnholster(client, player[client].holsteredWeapon))
124+
}
125+
if (!NotifyWeaponUnholster(client, player[client].holsteredWeapon)) {
122126
return; //was cancelled
127+
}
123128

124129
int restore = player[client].holsteredWeapon;
125130
player[client].holsteredWeapon = INVALID_ITEM_DEFINITION;
@@ -130,6 +135,7 @@ void ActualUnholsterMelee(int client) {
130135
player[client].holsteredAttributeCount,
131136
player[client].holsteredAttributeIds,
132137
player[client].holsteredAttributeValues);
138+
player[client].holsteredWeapon = INVALID_ITEM_DEFINITION;
133139
}
134140
NotifyWeaponUnholsterPost(client, restore, false);
135141
}

0 commit comments

Comments
 (0)