Thread: [Solved] [L4D2] cs_ragdoll usage?
View Single Post
Shadowysn
Senior Member
Join Date: Sep 2015
Location: Location:
Old 06-05-2019 , 23:52   Re: [L4D2] cs_ragdoll usage?
Reply With Quote #9

Quote:
Originally Posted by Dragokas View Post
I'm not compeletely sure what do you try to accomplish ... "convert" client sided ragdoll to server-sided?

In L4D1 (not sure about L4d2) ragdoll entity is valid for a very small amount of time: "player_death" with EventHookMode_Pre and no more valid on Post-event.

A trick is to kill it right there and create your own by reproducing original preperties, something like this:
PHP Code:
#pragma semicolon 1
#pragma newdecls required

#include <sourcemod>
#include <sdktools>
#tryinclude <LMCCore>

public void OnPluginStart()
{
    
HookEvent("player_death"player_deathEventHookMode_Pre);
}

public 
Action player_death(Event event, const char [] namebool dontBroadcast)
{
    static 
char Tank_Model[PLATFORM_MAX_PATH];
    
int client GetClientOfUserId(event.GetInt("userid"));    
    
    
//required checks
    //if (client && IsClientInGame(client) && IsInfected(client, ZOMBIECLASS_TANK))
    
{
        
// note: tank_killed event is too late here to retrieve ragdoll entity!
        
int ragdoll GetEntPropEnt(clientProp_Send"m_hRagdoll"); // CCSRagdoll
        
if (ragdoll && IsValidEntity(ragdoll)) {
            
AcceptEntityInput(ragdoll"Kill");
        }
        
        
int r,g,b,a;
        
float vOrigin[3];
        
char sColor[16];
        
GetClientAbsOrigin(clientvOrigin);
        
GetEntityRenderColor(clientr,g,b,a);
        
Format(sColorsizeof(sColor), "%i %i %i"rgb);
        
        
/*
        int iOverlayModel = -1;
        
        #if defined _LMCCore_included
            if( bLMC_Available )
                iOverlayModel = LMC_GetClientOverlayModel(client);    
        #endif
        */
        
        //GetEntPropString(iOverlayModel < 1 ? client : iOverlayModel, Prop_Data, "m_ModelName", Tank_Model, sizeof(Tank_Model));
        
GetEntPropString(clientProp_Data"m_ModelName"Tank_Modelsizeof(Tank_Model));
        
        
CreateTankRagdoll(vOriginTank_ModelsColor);
    }
}

void CreateTankRagdoll(float pos[3], char[] sModelchar[] sColor)
{
    static 
int body;
    
body CreateEntityByName("prop_ragdoll");
    if (
body != -1) {
        
DispatchKeyValue(body"model"sModel);
        
DispatchKeyValue(body"RenderColor"sColor);
        
DispatchKeyValue(body"spawnflags""4");
        
DispatchSpawn(body);
        
TeleportEntity(bodyposNULL_VECTORNULL_VECTOR);
        
SetEntityKillTimer(body60.0);
    }
}

stock void SetEntityKillTimer(int entfloat time)
{
    
char sRemove[64];
    
Format(sRemovesizeof(sRemove), "OnUser1 !self:Kill::%f:1"time);
    
SetVariantString(sRemove);
    
AcceptEntityInput(ent"AddOutput");
    
AcceptEntityInput(ent"FireUser1");

Apply original velocity and direction is the only required to add to finish what you want.
This sample was for my tank plugin.
Basically, what I'm trying to do is make dead survivors create a client ragdoll like in the Restore Ragdolls plugin, while keeping the original death model albeit making it invisible.

Reasons:
* I wanted to try out something (almost) on my own.
* Death models created with CreateEntityByName aren't affected by gravity.
Sorry if what I wanted wasn't all that clear with you.

The problem was that the client ragdolls didn't automatically assume the velocity + bone positions of their owner. So far only velocity from owner itself was finished.

And yes, in L4D2 cs_ragdoll behaves similarly like in L4D1.

Last edited by Shadowysn; 06-06-2019 at 00:01.
Shadowysn is offline