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 16:14:00 +01:00
committed by GitHub
parent 06dcb991e8
commit 8dcbe14ea0
+10
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.