Skip to content

Commit

Permalink
Throw an error when attempting to remove worldspawn in RemoveEntity/R…
Browse files Browse the repository at this point in the history
…emoveEdict (#2104)

* Check for worldspawn in RemoveEntity and RemoveEdict

* A little more info
  • Loading branch information
CookieCat45 committed Feb 20, 2024
1 parent 06dcb99 commit 8dcbe14
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions core/smn_entities.cpp
Expand Up @@ -285,6 +285,11 @@ static cell_t RemoveEdict(IPluginContext *pContext, const cell_t *params)
return pContext->ThrowNativeError("Edict %d (%d) is not a valid edict", g_HL2.ReferenceToIndex(params[1]), params[1]);
}

if (g_HL2.ReferenceToIndex(params[1]) == 0)
{
return pContext->ThrowNativeError("Cannot remove worldspawn (edict 0)");
}

engine->RemoveEdict(pEdict);

return 1;
Expand All @@ -298,6 +303,11 @@ static cell_t RemoveEntity(IPluginContext *pContext, const cell_t *params)
return pContext->ThrowNativeError("Entity %d (%d) is not a valid entity", g_HL2.ReferenceToIndex(params[1]), params[1]);
}

if (g_HL2.ReferenceToIndex(params[1]) == 0)
{
return pContext->ThrowNativeError("Cannot remove worldspawn (entity 0)");
}

// Some games have UTIL_Remove exposed on IServerTools, but for consistence, we'll
// use this method for all. Results in DeathNotice( this ) being called on parent,
// and parent being cleared (both if any parent) before UTIL_Remove is called.
Expand Down

0 comments on commit 8dcbe14

Please sign in to comment.