View Single Post
Visual77
Veteran Member
Join Date: Jan 2009
Old 03-07-2018 , 08:37   Re: [L4D2] Remove survivor dead body
Reply With Quote #7

Quote:
Originally Posted by cravenge View Post
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.

Last edited by Visual77; 03-07-2018 at 09:20.
Visual77 is offline