Quote:
Originally Posted by CliptonHeist
If velfloat already has assigned values you can just pass it into SetEntPropVector directly.
|
Uh... thanks for pointing that out. I feel dumb.
I've gotten the velocity on player movement working. I'd like to get force from damage, but I don't know how.
Here's my code that applied the velocity:
PHP Code:
// This is the value initialized + hook
float g_saveVelocity[MAXPLAYERS+1][3];
HookEvent("player_hurt", Player_Hurt_Pre, EventHookMode_Pre);
// Below code is in the ragdoll spawning function.
if (!IsPlayerAlive(client))
{
float multiply[3];
multiply[0] = g_saveVelocity[client][0]*25;
multiply[1] = g_saveVelocity[client][1]*25;
multiply[2] = g_saveVelocity[client][2]*25;
SetEntPropVector(Ragdoll, Prop_Send, "m_vecForce", multiply);
//PrintToChatAll("Applied force!");
g_saveVelocity[client][0] = 0.0
g_saveVelocity[client][1] = 0.0
g_saveVelocity[client][2] = 0.0
}
else
{
float velfloat[3];
velfloat[0] = GetEntPropFloat(client, Prop_Send, "m_vecVelocity[0]")*25
velfloat[1] = GetEntPropFloat(client, Prop_Send, "m_vecVelocity[1]")*25
velfloat[2] = GetEntPropFloat(client, Prop_Send, "m_vecVelocity[2]")*25
SetEntPropVector(Ragdoll, Prop_Send, "m_vecForce", velfloat);
}
// Below code is the hooked damage event, which prepares the g_saveVelocity for the above code.
public void Player_Hurt_Pre(Handle event, const char[] name, bool dontbroadcast)
{
int userID = GetEventInt(event, "userid");
int user = GetClientOfUserId(userID);
if (user <= 0)
return;
int health = GetEventInt(event, "health");
if (health > 0)
{
return;
}
if(!g_IsSequel || !g_RagdollModeEnabled)
return;
if (GetClientTeam(user) != 2 && GetClientTeam(user) != 4)
return;
float velfloat[3];
velfloat[0] = GetEntPropFloat(user, Prop_Send, "m_vecVelocity[0]")
velfloat[1] = GetEntPropFloat(user, Prop_Send, "m_vecVelocity[1]")
velfloat[2] = GetEntPropFloat(user, Prop_Send, "m_vecVelocity[2]")
g_saveVelocity[user] = velfloat;
}