Skip to content

Commit

Permalink
Revert "Create Ragdoll in a new frame"
Browse files Browse the repository at this point in the history
This reverts commit 12c1e13.
  • Loading branch information
Bara committed Oct 31, 2018
1 parent 12c1e13 commit 7ae8c52
Showing 1 changed file with 68 additions and 96 deletions.
164 changes: 68 additions & 96 deletions addons/sourcemod/scripting/ttt/ttt.sp
Original file line number Diff line number Diff line change
Expand Up @@ -1958,8 +1958,7 @@ bool IsDamageForbidden()

public Action Event_PlayerDeathPre(Event event, const char[] menu, bool dontBroadcast)
{
int userid = event.GetInt("userid");
int client = GetClientOfUserId(userid);
int client = GetClientOfUserId(event.GetInt("userid"));

if (!TTT_IsClientValid)
{
Expand All @@ -1977,17 +1976,76 @@ public Action Event_PlayerDeathPre(Event event, const char[] menu, bool dontBroa
if (g_iRole[client] > TTT_TEAM_UNASSIGNED)
{
g_bAlive[client] = false;
char sModel[128];
GetClientModel(client, sModel, sizeof(sModel));

float origin[3], angles[3], velocity[3];

GetClientAbsOrigin(client, origin);
GetClientAbsAngles(client, angles);
GetEntPropVector(client, Prop_Data, "m_vecAbsVelocity", velocity);

int iEntity = CreateEntityByName("prop_ragdoll");
DispatchKeyValue(iEntity, "model", sModel);
SetEntProp(iEntity, Prop_Data, "m_nSolidType", SOLID_VPHYSICS);
SetEntProp(iEntity, Prop_Data, "m_CollisionGroup", COLLISION_GROUP_PLAYER);
SetEntityMoveType(iEntity, MOVETYPE_NONE);
AcceptEntityInput(iEntity, "DisableMotion");

ActivateEntity(iEntity);
if (DispatchSpawn(iEntity))
{
float speed = GetVectorLength(velocity);
if (speed >= 500)
{
TeleportEntity(iEntity, origin, angles, NULL_VECTOR);
}
else
{
TeleportEntity(iEntity, origin, angles, velocity);
}
}
else
{
LogToFileEx(g_sErrorFile, "Unable to spawn ragdoll for %N (Auth: %i)", client, GetSteamAccountID(client));
}

SetEntProp(iEntity, Prop_Data, "m_CollisionGroup", COLLISION_GROUP_DEBRIS_TRIGGER);
AcceptEntityInput(iEntity, "EnableMotion");
SetEntityMoveType(iEntity, MOVETYPE_VPHYSICS);

int iUAttacker = event.GetInt("attacker");
int iAttacker = GetClientOfUserId(iUAttacker);
char sWeapon[32];
event.GetString("weapon", sWeapon, sizeof(sWeapon));
int iARole = 0;
char sName[MAX_NAME_LENGTH];
GetClientName(client, sName, sizeof(sName));
int iRagdollC[Ragdolls];
iRagdollC[Ent] = EntIndexToEntRef(iEntity);
iRagdollC[Victim] = GetClientUserId(client);
iRagdollC[VictimTeam] = g_iRole[client];
Format(iRagdollC[VictimName], MAX_NAME_LENGTH, sName);
iRagdollC[Scanned] = false;

if (TTT_IsClientValid(iAttacker))
{
GetClientName(iAttacker, sName, sizeof(sName));
iARole = g_iRole[iAttacker];
}
else
{
Format(sName, sizeof(sName), "Unknown attacker");
iUAttacker = 0;
}

iRagdollC[Attacker] = iUAttacker;
iRagdollC[AttackerTeam] = iARole;
Format(iRagdollC[AttackerName], MAX_NAME_LENGTH, sName);
iRagdollC[GameTime] = GetGameTime();
event.GetString("weapon", iRagdollC[Weaponused], sizeof(iRagdollC[Weaponused]));

g_aRagdoll.PushArray(iRagdollC[0]);

DataPack pack = new DataPack();
RequestFrame(Frame_CreateRagdoll, pack);
pack.WriteCell(userid);
pack.WriteCell(iUAttacker);
pack.WriteString(sWeapon);
SetEntPropEnt(client, Prop_Send, "m_hRagdoll", iEntity);

Action res = Plugin_Continue;

Expand Down Expand Up @@ -2053,92 +2111,6 @@ public Action Event_PlayerDeathPre(Event event, const char[] menu, bool dontBroa
return Plugin_Changed;
}

public void Frame_CreateRagdoll(DataPack pack)
{
pack.Reset();
int client = GetClientOfUserId(pack.ReadCell());
int iUAttacker = pack.ReadCell();
int iAttacker = GetClientOfUserId(iUAttacker);

char sWeapon[32];
pack.ReadString(sWeapon, sizeof(sWeapon));
delete pack;

if (!TTT_IsClientValid(client))
{
return;
}

char sModel[128];
GetClientModel(client, sModel, sizeof(sModel));

float origin[3], angles[3], velocity[3];
GetClientAbsOrigin(client, origin);
GetClientAbsAngles(client, angles);
GetEntPropVector(client, Prop_Data, "m_vecAbsVelocity", velocity);

int iEntity = CreateEntityByName("prop_ragdoll");
DispatchKeyValue(iEntity, "model", sModel);
SetEntProp(iEntity, Prop_Data, "m_nSolidType", SOLID_VPHYSICS);
SetEntProp(iEntity, Prop_Data, "m_CollisionGroup", COLLISION_GROUP_PLAYER);
SetEntityMoveType(iEntity, MOVETYPE_NONE);
AcceptEntityInput(iEntity, "DisableMotion");

ActivateEntity(iEntity);
if (DispatchSpawn(iEntity))
{
float speed = GetVectorLength(velocity);
if (speed >= 500)
{
TeleportEntity(iEntity, origin, angles, NULL_VECTOR);
}
else
{
TeleportEntity(iEntity, origin, angles, velocity);
}
}
else
{
LogToFileEx(g_sErrorFile, "Unable to spawn ragdoll for %N (Auth: %i)", client, GetSteamAccountID(client));
}

SetEntProp(iEntity, Prop_Data, "m_CollisionGroup", COLLISION_GROUP_DEBRIS_TRIGGER);
AcceptEntityInput(iEntity, "EnableMotion");
SetEntityMoveType(iEntity, MOVETYPE_VPHYSICS);


int iARole = 0;
char sName[MAX_NAME_LENGTH];
GetClientName(client, sName, sizeof(sName));
int iRagdollC[Ragdolls];
iRagdollC[Ent] = EntIndexToEntRef(iEntity);
iRagdollC[Victim] = GetClientUserId(client);
iRagdollC[VictimTeam] = g_iRole[client];
Format(iRagdollC[VictimName], MAX_NAME_LENGTH, sName);
iRagdollC[Scanned] = false;

if (TTT_IsClientValid(iAttacker))
{
GetClientName(iAttacker, sName, sizeof(sName));
iARole = g_iRole[iAttacker];
}
else
{
Format(sName, sizeof(sName), "Unknown attacker");
iUAttacker = 0;
}

iRagdollC[Attacker] = iUAttacker;
iRagdollC[AttackerTeam] = iARole;
Format(iRagdollC[AttackerName], MAX_NAME_LENGTH, sName);
iRagdollC[GameTime] = GetGameTime();
strcopy(iRagdollC[Weaponused], sizeof(iRagdollC[Weaponused]), sWeapon);

g_aRagdoll.PushArray(iRagdollC[0]);

SetEntPropEnt(client, Prop_Send, "m_hRagdoll", iEntity);
}

public void OnClientPostAdminCheck(int client)
{
char name[MAX_NAME_LENGTH];
Expand Down Expand Up @@ -3378,6 +3350,7 @@ public int TTT_OnButtonPress(int client, int button)

if (button & IN_USE)
{

int iEntity = GetClientAimTarget(client, false);
if (iEntity > 0)
{
Expand Down Expand Up @@ -3407,7 +3380,6 @@ public int TTT_OnButtonPress(int client, int button)
if (IsPlayerAlive(client) && !g_bIsChecking[client])
{
g_bIsChecking[client] = true;

Action res = Plugin_Continue;
Call_StartForward(g_hOnBodyCheck);
Call_PushCell(client);
Expand Down

0 comments on commit 7ae8c52

Please sign in to comment.