Thread: [Solved] [L4D2] cs_ragdoll usage?
View Single Post
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 06-03-2019 , 11:14   Re: [L4D2] cs_ragdoll usage?
Reply With Quote #8

Quote:
Originally Posted by Shadowysn View Post
I wanted to attempt spawning survivor ragdolls without removing the original death model. So far, I got the ragdoll death to an extent.
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.
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]

Last edited by Dragokas; 06-03-2019 at 11:16.
Dragokas is offline