Browse files

(OPTIONAL) Add VPhysics to ttt_crashcatcher

  • Loading branch information...
Bara committed Dec 8, 2018
1 parent ba05318 commit 97f5eb2c5c9ba69b28961b124149edde8d58e5bf
@@ -3,7 +3,6 @@ addons/sourcemod/scripting/.atom-build.json
@@ -0,0 +1,117 @@
#if defined _sdktools_phys_included
#define _sdktools_phys_included

native bool Phys_IsPhysicsObject(int iEntity);

native bool Phys_IsStatic(int iEntity);
native bool Phys_IsAsleep(int iEntity);
native bool Phys_IsHinged(int iEntity);
native bool Phys_IsCollisionEnabled(int iEntity);
native bool Phys_IsGravityEnabled(int iEntity);
native bool Phys_IsDragEnabled(int iEntity);
native bool Phys_IsMotionEnabled(int iEntity);
native void Phys_EnableCollisions(int iEntity, bool enable);
native void Phys_EnableGravity(int iEntity, bool enable);
native void Phys_EnableDrag(int iEntity, bool enable);
native void Phys_EnableMotion(int iEntity, bool enable);
native void Phys_Wake(int iEntity);
native void Phys_Sleep(int iEntity);
native void Phys_SetMass(int iEntity, float mass);
native float Phys_GetMass(int iEntity);
native void Phys_SetMaterialIndex(int iEntity, int materialIndex);
native int Phys_GetMaterialIndex(int iEntity);
native void Phys_BecomeHinged(int iEntity, int axis);
native void Phys_RemoveHinged(int iEntity);
native void Phys_LocalToWorld(int iEntity, float[3] worldPosition, const float[3] localPosition);
native void Phys_WorldToLocal(int iEntity, float[3] localPosition, const float[3] worldPosition);

native void Phys_CalculateForceOffset(int iEntity, const float[3] forceVector, const float[3] worldPosition, float[3] centerForce, float[3] centerTorque);
native void Phys_CalculateVelocityOffset(int iEntity, const float[3] forceVector, const float[3] worldPosition, float[3] centerVelocity, float[3] centerAngularVelocity);
native void Phys_ApplyForceCenter(int iEntity, const float[3] forceVector);
native void Phys_ApplyTorqueCenter(int iEntity, const float[3] torque);
native void Phys_AddVelocity(int iEntity, const float[3] velocity, const float[3] angularVelocity);
native void Phys_SetVelocity(int iEntity, const float[3] velocity, const float[3] angularVelocity, bool instantaneous = false);

native void Phys_GetEnvironmentGravity(float[3] gravity);
native void Phys_SetEnvironmentGravity(const float[3] gravity);
native float Phys_GetEnvironmentAirDensity();
native void Phys_SetEnvironmentAirDensity(float density);

native Handle Phys_CreateConstraintGroup(int additionalIterations = 0, int minErrorTicks = 15, float errorTolerance = 3.0);

native Handle Phys_CreateSpring(int startObject, int endObject, const float[3] startPos, const float[3] endPos, bool useLocalPositions, float naturalLength, float constant, float damping, float relativeDamping, bool onlyStretch);

native Handle Phys_CreateFixedConstraint(int referenceObject, int attachedObject, Handle constraintGroup, float strength = 1.0, float forceLimit = 0.0, float torqueLimit = 0.0, float bodyMassScaleRef = 1.0, float bodyMassScaleAttached = 1.0, bool isActive = true);
native Handle Phys_CreateLengthConstraint(int referenceObject, int attachedObject, Handle constraintGroup, const float[3] refPosition, const float[3] attachedPosition, float totalLength, float minLength = 0.0, float strength = 1.0, float forceLimit = 0.0, float torqueLimit = 0.0, float bodyMassScaleRef = 1.0, float bodyMassScaleAttached = 1.0, bool isActive = true);
native Handle Phys_CreateHingeConstraint(int referenceObject, int attachedObject, Handle constraintGroup, const float[3] worldPosition, const float[3] worldAxisDirection, float minRotation = 0.0, float maxRotation = 0.0, float angularVelocity = 0.0, float torque = 0.0, float strength = 1.0, float forceLimit = 0.0, float torqueLimit = 0.0, float bodyMassScaleRef = 1.0, float bodyMassScaleAttached = 1.0, bool isActive = true);

native Handle Phys_CreateFrictionSnapshot(int iEntity);
native bool Phys_IsFrictionSnapshotValid(Handle snapshot);
native bool Phys_NextFrictionData(Handle snapshot);
native int Phys_GetTouchingEntity(Handle snapshot);
native void Phys_GetContactPoint(Handle snapshot, float[3] contactPoint);

native int Phys_GetIndexOfMaterial(const char[] material);

forward void Phys_OnObjectWake(int iEntity);
forward void Phys_OnObjectSleep(int iEntity);

stock void Phys_ApplyForceOffset(int iEntity, const float[3] forceVector, const float[3] worldPosition)
float centerForce[3];
float centerTorque[3];

Phys_CalculateForceOffset(iEntity, forceVector, worldPosition, centerForce, centerTorque);

Phys_ApplyForceCenter(iEntity, centerForce);
Phys_ApplyTorqueCenter(iEntity, centerTorque);

stock void Phys_AddVelocityOffset(int iEntity, const float[3] forceVector, const float[3] worldPosition)
float centerVelocity[3];
float centerAngularVelocity[3];

Phys_CalculateVelocityOffset(iEntity, forceVector, worldPosition, centerVelocity, centerAngularVelocity);

Phys_AddVelocity(iEntity, centerVelocity, centerAngularVelocity);

stock bool Phys_IsTouchingEntity(int iEntity, int other)
Handle snapshot = Phys_CreateFrictionSnapshot(iEntity);

bool touching = false;

while (Phys_IsFrictionSnapshotValid(snapshot))
if (Phys_GetTouchingEntity(snapshot) == other)
touching = true;


delete snapshot;

return touching;

* Do not edit below this line!
public Extension __ext_vphysics =
name = "VPhysics",
file = "vphysics.ext",
autoload = 1,
required = 1,
required = 0,
@@ -0,0 +1,119 @@
#pragma semicolon 1

#include <sourcemod>
#include <sdktools>
#include <sdkhooks>

public void OnPluginStart()
RegAdminCmd("sm_dronegun", Command_DroneGun, ADMFLAG_BAN);

for (int i = 1; i <= MaxClients; i++)
if (IsClientInGame(i))

public void OnClientPutInServer(int client)
SDKHook(client, SDKHook_TraceAttack, OnTraceAttack);

public Action OnTraceAttack(int victim, int &attacker, int &inflictor, float &damage, int &damagetype, int &ammotype, int hitbox, int hitgroup)
if (IsValidEntity(attacker))
char sClass[32];
GetEntityClassname(attacker, sClass, sizeof(sClass));
PrintToChatAll("Attacker Class: %s", sClass);

if (StrEqual(sClass, "env_gunfire", false))
SetEntProp(attacker, Prop_Send, "m_bHasTarget", false);
return Plugin_Handled;

return Plugin_Continue;

public void OnMapStart()
int precache = PrecacheModel("models/props_survival/dronegun/dronegun.mdl", true);

if (precache == 0) {
SetFailState("models/props_survival/dronegun/dronegun.mdl not precached !");

PrecacheModel("models/props_survival/dronegun/dronegun_gib1.mdl", true);
PrecacheModel("models/props_survival/dronegun/dronegun_gib2.mdl", true);
PrecacheModel("models/props_survival/dronegun/dronegun_gib3.mdl", true);
PrecacheModel("models/props_survival/dronegun/dronegun_gib4.mdl", true);
PrecacheModel("models/props_survival/dronegun/dronegun_gib5.mdl", true);
PrecacheModel("models/props_survival/dronegun/dronegun_gib6.mdl", true);
PrecacheModel("models/props_survival/dronegun/dronegun_gib7.mdl", true);
PrecacheModel("models/props_survival/dronegun/dronegun_gib8.mdl", true);

PrecacheSound("sound/survival/turret_death_01.wav", true);
PrecacheSound("sound/survival/turret_idle_01.wav", true);

PrecacheSound("sound/survival/turret_takesdamage_01.wav", true);
PrecacheSound("sound/survival/turret_takesdamage_02.wav", true);
PrecacheSound("sound/survival/turret_takesdamage_03.wav", true);

PrecacheSound("sound/survival/turret_lostplayer_01.wav", true);
PrecacheSound("sound/survival/turret_lostplayer_02.wav", true);
PrecacheSound("sound/survival/turret_lostplayer_03.wav", true);

PrecacheSound("sound/survival/turret_sawplayer_01.wav", true);

public Action Command_DroneGun(int client, int args)
return Plugin_Handled;

float vec[2][3];
GetClientEyePosition(client, vec[0]);
GetClientEyeAngles(client, vec[1]);

Handle trace = TR_TraceRayFilterEx(vec[0], vec[1], MASK_SOLID, RayType_Infinite, Filter_ExcludePlayers);

delete trace;
return Plugin_Handled;

TR_GetEndPosition(vec[0], trace);
delete (trace);

int dronegun = CreateEntityByName("dronegun");
if(dronegun == -1 || !IsValidEntity(dronegun))
PrintToServer("dronegun %d", dronegun);
return Plugin_Handled;

PrintToServer("A dronegun %d", dronegun);

vec[0][2] = vec[0][2] + 16.0;
TeleportEntity(dronegun, vec[0], NULL_VECTOR, NULL_VECTOR);
SetEntPropEnt(dronegun, Prop_Send, "m_hOwnerEntity", client);
SetEntProp(dronegun, Prop_Send, "m_iTeamNum", GetClientTeam(client));

return Plugin_Handled;

public bool Filter_ExcludePlayers(int entity, int contentsMask, any data)
return !((entity > 0) && (entity <= MaxClients));
@@ -0,0 +1,37 @@
#include <sourcemod>

enum eEnum {

public void OnPluginStart()
ArrayList aArray = new ArrayList(3);

int iPush[eEnum];
iPush[iInt1] = 1;
iPush[iInt2] = 10;
iPush[bBool] = true;

bool bTest = false;
PrintToServer("bTest: %d -> %d vs %d vs. %d", bTest, !bTest, (!bTest), !(bTest));

for (int j = 1; j <= 10; j++)
for (int i = 0; i < aArray.Length; i++)
int iGet[eEnum];
aArray.GetArray(i, iGet[0]);

PrintToServer("Try #%d -> Index: %d iInt1: %d, iInt2: %d, bBool: %d", j, i, iGet[iInt1], iGet[iInt2], iGet[bBool]);

iGet[bBool] = !iGet[bBool];
aArray.SetArray(i, iGet[0]);
@@ -5,6 +5,8 @@
#include <sdktools>
#include <sdkhooks>
#include <ttt>
#tryinclude <vphysics>

#define PLUGIN_NAME TTT_PLUGIN_NAME ... " - Crash Catcher"

@@ -99,3 +101,22 @@ public Action Timer_Restore(Handle timer, any ref2)

#if defined _sdktools_phys_included
public void Phys_OnObjectWake(int entity)
if (IsValidEntity(entity))
char sClass[64];
GetEntityClassname(entity, sClass, sizeof(sClass));

if (StrEqual(sClass, "prop_ragdoll", false))
if (Phys_IsPhysicsObject(entity))

0 comments on commit 97f5eb2

Please sign in to comment.