Throw an error when attempting to remove worldspawn in RemoveEntity/RemoveEdict (#2104)

* Check for worldspawn in RemoveEntity and RemoveEdict

* A little more info
This commit is contained in:
CookieCat 2024-02-20 10:14:00 -05:00 committed by GitHub
parent 06dcb991e8
commit 8dcbe14ea0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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;
@ -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.