AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   [L4D2] Remove survivor dead body (https://forums.alliedmods.net/showthread.php?t=305592)

eyal282 02-25-2018 13:21

[L4D2] Remove survivor dead body
 
I would like to remove a survivor's dead body with a simple condition: It can be done at any time, without a warning, not only after the dead or in dead_survivor_visible event.

eyal282 03-05-2018 04:58

Re: [L4D2] Remove survivor dead body
 
I tried to extract the dead body with an SDKCall which I searched in pseudo code, 0 success since it uses a method I fail to understand to retrieve it.
Code:

CBaseEntity *__cdecl CItemDefibrillator::OnActionComplete(CItemDefibrillator *this, CTerrorPlayer *a2, CBaseEntity *a3)
{
  CBaseEntity *result; // eax@1
  CSurvivorDeathModel *v4; // ebx@2
  CBaseEntity *v5; // edi@3
  CBaseEntity *v6; // ebx@4
  void (__cdecl *v7)(CBaseEntity *, const char *, int); // ST1C_4@5
  int v8; // eax@5
  void (__cdecl *v9)(CBaseEntity *, char *, int); // esi@5
  int v10; // eax@5

  result = a3;
  if ( a3 )
  {
    result = (CBaseEntity *)_dynamic_cast(a3, &`typeinfo for'CBaseEntity, &`typeinfo for'CSurvivorDeathModel, 0);
    v4 = result;

    if ( result )
    {
      result = (CBaseEntity *)CTerrorPlayer::GetPlayerByCharacter(*((_DWORD *)result + 1526));
      v5 = result;
      if ( result )
      {
        CTerrorPlayer::OnRevivedByDefibrillator(result, a2, v4);
        CBasePlayer::RumbleEffect(a2, 33, 0, 4);
        result = (CBaseEntity *)(*(int (__cdecl **)(CCSPlayer *, const char *, _DWORD, _DWORD))(*(_DWORD *)gameeventmanager
                                                                                              + 28))(
                                  gameeventmanager,
                                  "defibrillator_used",
                                  0,
                                  0);
        v6 = result;
        if ( result )
        {
          v7 = *(void (__cdecl **)(CBaseEntity *, const char *, int))(*(_DWORD *)result + 48);
          v8 = (*(int (__cdecl **)(CBaseEntity *, _DWORD))(*(_DWORD *)engine + 64))(engine, *((_DWORD *)a2 + 12));
          v7(v6, "userid", v8);
          v9 = *(void (__cdecl **)(CBaseEntity *, char *, int))(*(_DWORD *)v6 + 48);
          v10 = (*(int (__cdecl **)(CBaseEntity *, _DWORD))(*(_DWORD *)engine + 64))(engine, *((_DWORD *)v5 + 12));
          v9(v6, "subject", v10);
          result = (CBaseEntity *)(*(int (__cdecl **)(_DWORD, _DWORD, _DWORD))(*(_DWORD *)gameeventmanager + 32))(
                                    gameeventmanager,
                                    v6,
                                    0);
        }
      }
    }
  }
  return result;
}


spumer 03-05-2018 07:19

Re: [L4D2] Remove survivor dead body
 
I add function to replace deathmodel for revive fix in post https://forums.alliedmods.net/showpo...&postcount=184

You can try to modify extension and add function for deleting deathmodel entity.

eyal282 03-05-2018 07:27

Re: [L4D2] Remove survivor dead body
 
Quote:

Originally Posted by spumer (Post 2581446)
I add function to replace deathmodel for revive fix in post https://forums.alliedmods.net/showpo...&postcount=184

You can try to modify extension and add function for deleting deathmodel entity.

I know nothing about scripting extensions, does your posted extension solve my issue?

Maybe you can add a native to retrieve the deathmodel entity in your extension?

Lux 03-07-2018 08:00

Re: [L4D2] Remove survivor dead body
 
Quote:

Originally Posted by eyal282 (Post 2581448)
I know nothing about scripting extensions, does your posted extension solve my issue?

Maybe you can add a native to retrieve the deathmodel entity in your extension?

I still don't really understand what your trying to do, however maybe my forward in LMC could help

PHP Code:

/**
*    This is called when lmc_hide_defib_model > -1 cvar
*
*    @param     iClient        Client Index who died.
*    @param     iEntity        Entity Index of Deathmodel for client who died
*    @param    iOverlayModel     Entity Index of Deathmodel overlaymodel -1 if don't exist
*    @no return
*/
forward void LMC_OnClientDeathModelCreated(int iClientint iDeathModelint iOverlayModel); 

https://github.com/LuxLuma/-L4D2-Lef....inc#L143-L151


Can't you check your conditions for removal of deathmodel in sourcemod?

cravenge 03-07-2018 08:26

Re: [L4D2] Remove survivor dead body
 
PHP Code:

int iDeathModel = -1;
while ((
iDeathModel FindEntityByClassname(iDeathModel"survivor_death_model")) != -1)
{
    
/* Some people forget to check if all the death models present are valid. */
    /* Hence, resulting to untimely random game/server crashes. */
    
if (!IsValidEntity(iDeathModel) || !IsValidEdict(iDeathModel))
    {
        continue;
    }
    
    
// do what you want here. :)



Visual77 03-07-2018 08:37

Re: [L4D2] Remove survivor dead body
 
Quote:

Originally Posted by cravenge (Post 2581755)
PHP Code:

    /* Some people forget to check if all the death models present are valid. */
    /* Hence, resulting to untimely random game/server crashes. */




This is untrue. Sourcemod's Native FindEntityByClassname already checks if the entity is valid internally.
If the entity is not valid, FindEntityByClassname reports -1. The while loop specificly only checks for valid entities (return value >= 0)

Edit: To clarify. If you check that the return value of FindEntityByClassname is >= 0 on the entity, (which is done in this while loop), you don't
have to add any aditonal IsValidEdict or IsValidEntity checks. To avoid crashes, always check the return value and don't remove the entity with RemoveEdict.

Example on how to use it on a single entity.
Code:

int entity = FindEntityByClassname(-1, "this_entities_name");
if (entity != -1) AcceptEntityInput(entity, "kill");  // this is perfectly fine on a perfectly validated entity.


cravenge 03-07-2018 09:22

Re: [L4D2] Remove survivor dead body
 
There are times when the entity is valid and invalid at the same time. This is due to said entity being in the process of removal.

Example: Deleting an entity that is about to be removed automatically from the map.
PHP Code:

int entity FindEntityByClassname(-1"survivor_death_model");
if (
entity != -1)
{
    
AcceptEntityInput(entity"Kill"); // In case this happens, the entity here is being removed twice which leads to a crash.
}

/* unless... */

int entity FindEntityByClassname(-1"survivor_death_model");
if (
entity != -1)
{
    if (!
IsValidEntity(entity)) // Here, we delay the process to actually confirm that the entity is still valid.
    
{
        return;
    }
    
    
AcceptEntityInput(entity"Kill"); // Plugin can safely delete the entity with no chances of the game/server crashing.



Visual77 03-07-2018 09:31

Re: [L4D2] Remove survivor dead body
 
Quote:

Originally Posted by cravenge (Post 2581771)
Example: Deleting an entity that is about to be removed automatically from the map.

Then this must be one of those rare cases then. Aren't entities only wiped automatically on two conditions: 1. Mapchange. 2 New round?

What happens if we have 2 plugins trying to delete the exact same entity model at the same time? Would it still delete the entity on pluginA and pluginB would maybe just ignore it? Or does the server crash?

cravenge 03-07-2018 09:34

Re: [L4D2] Remove survivor dead body
 
Quote:

Originally Posted by Visual77 (Post 2581774)
[...]

Unless there are other plugins installed that forces entity removal, yes, those are the only two.

But if eyal is using a repeating timer, he might need to do that or... stop the timer during OnMapEnd and restart it on OnMapStart.

Quote:

Originally Posted by Visual77 (Post 2581774)
[...]

Definitely a server crash is to be expected. I experienced it using Coder's Edict Overflow Prevention plugin and my own Ragdolls Remover.

Manually spawned ragdolls before game crashed when it reached 10-20 total.


All times are GMT -4. The time now is 18:23.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.