Garry's Mod Wiki

Revision Difference

game.CleanUpMap#562695

<function name="CleanUpMap" parent="game" type="libraryfunc"> <description> If called serverside it will remove **ALL** entities which were not created by the map (not players or weapons held by players). It won't remove Entities who have the <page text="EFL_KEEP_ON_RECREATE_ENTITIES">enums/EFL</page> Flag set. ⤶ On the client it will remove decals, sounds, gibs, dead NPCs, and entities created via <page>ents.CreateClientProp</page>. Removes most entities, and then respawns entities created by the map, as if the map was just loaded. ⤶ There are certain exclusions, such as players or weapons held by players, soundscapes and others. <page text="EFL_KEEP_ON_RECREATE_ENTITIES">enums/EFL</page> can be set on entities to preserve them through a map cleanup. ⤶ On the client it will remove decals, sounds, gibs, dead NPCs, and entities created via <page>ents.CreateClientProp</page>. This function is ran on all clients from server automatically, when it is called on the server.⤶ This function calls <page>GM:PreCleanupMap</page> before cleaning up the map and <page>GM:PostCleanupMap</page> after cleaning up the map. Beware of calling this function in hooks that may be called on map clean up (such as <page>ENTITY:StartTouch</page>) to avoid infinite loops. <bug issue="2874">Calling this destroys all BASS streams.</bug> <bug issue="3637">This can crash when removing `_firesmoke` entities. **You can use the example below to workaround this issue.**</bug> </description> <realm>Shared</realm> <args> <arg name="dontSendToClients" type="boolean" default="false">If set to `true`, don't run this functions on all clients.</arg> <arg name="extraFilters" type="table" default="{}">Entity classes not to reset during cleanup.</arg> <arg name="callback" type="function" default="nil" added="2024.01.04">If set, delays the map cleanup until the end of a server tick, allowing bypassing the entity limit on maps with large amounts of them. Otherwise the entities will not be cleaned up until the end of the server tick. The callback function will be called after the map cleanup has been performed.</arg> </args> </function> <example> <description>Quick fix for issue [#3637](https://github.com/Facepunch/garrysmod-issues/issues/3637) (from [Garry's Mod Github](https://github.com/Facepunch/garrysmod-issues/issues/3637#issuecomment-702478260)).</description> <code>game.CleanUpMap( false, { "env_fire", "entityflame", "_firesmoke" } )</code> </example>