OpenRouter message content was empty or missing.


```lua
hook.Add("Think", "MyAddon.Think", function()
    -- Minimal callback body
end)
```
Reason: Registers the function as a Think hook callback with the identifier MyAddon.Think.


Uses IsValid for entity/object validity.

```lua
if ent and ent:IsValid() then
    -- safe to use ent
end
```
Reason: This checks both that ent exists and that it hasn't been removed or destroyed, ensuring the entity is still valid before using it.


```lua
net.Receive("MyAddon.Sync", function(length)
    -- handle incoming net message
    local data = net.ReadString()
    print("MyAddon.Sync received:", data)
end)
```
Reason: Registers a net message handler for "MyAddon.Sync" using net.Receive.


```lua
local plys = player.GetAll()
for i = 1, #plys do
    local v = plys[i]
    -- your code here
end
```
Reason: Storing the player table locally and iterating by numeric index reduces the overhead of `pairs` and improves performance.


```lua
for _, ent in ipairs(ents.FindByClass("prop_physics")) do
    -- code here
end
```

Reason: ents.FindByClass is the built-in engine function designed to return a table of entities matching a specific class, which is more efficient than iterating through all entities and checking their class manually.


```lua
for _, ent in ipairs(ents.FindByClass("prop_physics")) do
    -- your code here
end
```
Reason: Uses FindByClass's iterator to avoid building a full table.


```lua
hook.Add("Think", "MyAddon.Think", function() end)
```
Reason: Registers a Think hook callback using the identifier MyAddon.Think.


```lua
if IsValid(ent) then
    -- safe to use ent
end
```
Reason: IsValid checks that the entity still exists and hasn't been removed.


```lua
net.Receive("MyAddon.Sync", function(len, ply)
    -- handle the incoming net message
end)
```
Reason: registers a receiver for net messages named MyAddon.Sync


```lua
local players = player.GetAll()
for _, ply in ipairs(players) do
    -- your code here
end
```
Reason: Cache player list and use ipairs for speed.


HTTP request exceeded the attempt timeout.


```lua
for _, ent in ipairs(ents.FindByClass("prop_physics")) do
    -- Perform actions on each prop_physics entity here
end
```
Reason: ents.FindByClass returns only entities matching the class, so we avoid constructing a table of all entities first.


Answer must contain exactly one fenced code block followed by a reason.

```lua
hook.Add("Think", "MyAddon.Think", function()
    -- Callback body
end)
Reason: hook.Add registers a Think hook callback with the identifier MyAddon.Think.
```


```lua
if IsValid(ent) then
    -- ent is valid, safe to call methods on it
end
```
Reason: IsValid checks that the entity exists and hasn't been removed, returning false for nil or invalid references, thus preventing runtime errors when calling methods.


```lua
net.Receive("MyAddon.Sync", function(len)
    -- Handle the incoming message
    local data = net.ReadString()
    -- Process data as needed
end)
```
Reason: net.Receive registers a receiver for the named net message, allowing the server/client to process incoming data.


```lua
local pls = player.GetAll()
for i = 1, #pls do
    local ply = pls[i]
    -- your code here
end
```
Reason: Caching the player table and using a numeric for loop avoids hash lookups and repeated function calls, making it faster than pairs.


```lua
for _, ent in ipairs(ents.FindByClass("prop_physics")) do
    -- your code here
end
Reason: ents.FindByClass returns a table of only the matching entities, so you don't need to iterate over all entities first.
```


```lua
hook.Add("Think", "MyAddon.Think", function()
    -- Callback body (can be empty or minimal)
end)
```
Reason: hook.Add registers a function to the Think hook with the unique identifier MyAddon.Think.


```lua
if IsValid(ent) then
    -- ent is valid, you can safely call its methods here
end
```
Reason: IsValid returns true only when the entity reference points to a living, non‑removed entity, preventing errors from calling methods on nil or invalid entities.


```lua
net.Receive("MyAddon.Sync", function(len)
    -- Example handling: read a string and print it
    local msg = net.ReadString()
    print("MyAddon.Sync received:", msg)
end)
```
Reason: Registers a receiver for the net message named MyAddon.Sync using net.Receive, which will be called whenever a message with that name is sent.


```lua
local players = player.GetAll()
for i = 1, #players do
    local ply = players[i]
    -- your code here
end
```
Reason: A numeric for loop avoids the iterator overhead of pairs/ipairs and directly indexes the array part of the table, which is faster for iterating over all players.


```lua
for _, ent in ents.Iterator() do
    if ent:GetClass() == "prop_physics" then
        -- process ent
    end
end
```
Reason: `ents.Iterator()` yields entities one by one without allocating a table of all entities, making it memory‑efficient for large entity counts.


```lua
hook.Add("Think", "MyAddon.Think", function()
    -- Your think logic here
end)
```
Reason: Registers a Think hook with the unique identifier "MyAddon.Think" so the callback runs every frame.


```lua
if IsValid(ent) then
    -- ent is valid, safe to call methods
end
```
Reason: IsValid is the global function provided by Garry's Mod to reliably check if an entity exists and hasn't been removed.


```lua
net.Receive("MyAddon.Sync", function(len, ply)
    -- Handle the incoming net message here
end)
```
Reason: Registers a net message receiver for "MyAddon.Sync" to handle incoming network messages with that name.


```lua
local players = player.GetAll()
for i = 1, #players do
    local ply = players[i]
    -- your code here
end
```
Reason: A numeric for loop over the array returned by player.GetAll() avoids iterator overhead and is faster in LuaJIT.


```lua
for _, ent in ipairs(ents.FindByClass("prop_physics")) do
    -- process ent
end
```
Reason: `ents.FindByClass` performs the class filtering in C++ and returns only matching entities, avoiding a full iteration of all entities in Lua.


```lua
hook.Add("Think", "MyAddon.Think", function() end)
```
Reason: Registers a Think hook callback with the identifier MyAddon.Think using hook.Add.


```lua
if IsValid(ent) then
    -- ent is valid, safe to call methods on it
end
```
Reason: `IsValid(ent)` returns true only if the entity exists and is not a NULL entity, preventing errors when calling methods on invalid references.


```lua
net.Receive("MyAddon.Sync", function(len, ply)
    -- Handle the incoming message here
    -- Example: local data = net.ReadTable()
end)
```
Reason: This registers a net receiver for the message name "MyAddon.Sync" using Garry's Mod's net library.


```lua
local players = player.GetAll()
for i = 1, #players do
    local v = players[i]
    -- loop body
end
```
Reason: Numeric for loop with a cached table avoids pairs overhead and repeated function calls, yielding the fastest iteration over the sequential player array.


```lua
hook.Add("Think", "MyAddon.Think", function() return true end)
```
Reason: `hook.Add` registers the callback with the specified identifier for the `Think` hook, ensuring it runs each frame.


```lua
if ent and ent:IsValid() then
    -- call methods here
end
```
Reason: Ensures `ent` is not nil and the entity is still valid before calling methods, preventing errors from invalid references.


```lua
for _, ent in ipairs(ents.FindByClass("prop_physics")) do
    -- process ent
end
```
Reason: `ents.FindByClass` directly retrieves entities of the specified class, avoiding the need to iterate through all entities and filter them, which is more efficient.


```lua
hook.Add("Think", "MyAddon.Think", function() end)
```
Reason: Uses `hook.Add` with the "Think" hook name, the specified identifier "MyAddon.Think", and an empty callback function.


```lua
IsValid(ent)
```
Reason: `IsValid` checks if the entity reference is still active and valid in the game world.


```lua
net.Receive("MyAddon.Sync", function(len, ...) end)
```
Reason: The `net.Receive` function in Garry's Mod Lua is used to register a networked message receiver, where the first argument is the message name and the second is the callback function.


```lua
for i, v in ipairs(player.GetAll()) do ... end
```
Reason: `ipairs` is more efficient than `pairs` for ordered lists with consecutive integer keys, which `player.GetAll()` typically provides.


```lua
local players = player.GetAll()
for i = 1, #players do
    local ply = players[i]
    -- your code here
end
```
Reason: Storing the player list once and iterating with a numeric for loop avoids the overhead of `pairs` and repeated `player.GetAll()` calls, giving the fastest traversal of the current players.


```lua
for i = 1, #ents.GetAll() do
    local ent = ents.GetAll()[i]
    if ent:GetClass() == "prop_physics" then
        -- your code here
    end
end
```
Reason: This iterates directly over the global entity list without creating a separate table of only prop_physics entities.


```lua
hook.Add("Think", "MyAddon.Think", function()
    -- callback body
end)
```
Reason: registers a Think hook with identifier MyAddon.Think.


```lua
if not IsValid(ent) then return end
```
Reason: `IsValid` is the standard Garry's Mod function to check an entity reference before using it.


```lua
net.Receive("MyAddon.Sync", function(len, ply)
    -- handle the incoming message here
end)
```
Reason: registers a handler for the network message "MyAddon.Sync".


```lua
local players = player.GetAll()
for _, ply in ipairs(players) do
    -- ...
end
```
Reason: caching the player list in a local variable and using `ipairs` avoids repeated table lookups and is faster than `pairs`.


```lua
for _, ent in ipairs(ents.FindByClass("prop_physics")) do
    -- process ent
end
```
Reason: `ents.FindByClass` is the standard way to get all entities of a class and iterate over them without manually building a separate table.


```lua
hook.Add("Think", "MyAddon.Think", function()
    -- callback body
end)
```
Reason: Registers a Think hook with the specified identifier.


```lua
if IsValid(ent) then
    -- safe to use ent
end
```
Reason: `IsValid` checks that the entity reference is not nil and still exists.


```lua
net.Receive("MyAddon.Sync", function(len, ply)
    -- handle the incoming message here
end)
```
Reason: Registers a receiver for the networked message "MyAddon.Sync".


```lua
local players = player.GetAll()
for i = 1, #players do
    local ply = players[i]
    -- your code here
end
```
Reason: Using a numeric for loop over a pre‑cached table avoids the overhead of pairs and repeated table lookups, making it the most efficient way to iterate over all current players.


```lua
for _, ent in ipairs(ents.FindByClass("prop_physics")) do
    -- process each entity
end
```
Reason: Uses the engine's built-in `ents.FindByClass` to directly iterate over all `prop_physics` entities without manually building a table, leveraging the game's optimized entity lookup.


```lua
hook.Add("Think", "MyAddon.Think", function() end)
```
Reason: Uses hook.Add with "Think" as the hook name, "MyAddon.Think" as the unique identifier, and an empty function as the callback.


```lua
if IsValid(ent) then
    -- safe to use ent
end
```
Reason: The `IsValid()` function checks if the entity exists and hasn't been removed from the game world, preventing errors when calling methods on invalid references.


```lua
net.Receive("MyAddon.Sync", function(len)
    -- Handle incoming message here
end)
```
Reason: Uses net.Receive to register a handler for the "MyAddon.Sync" message with a function that receives the message length.


```lua
local players = player.GetAll()
for i = 1, #players do
    local v = players[i]
    -- do stuff
end
```
Reason: Using a numeric loop on the cached table avoids the overhead of the `pairs` iterator and is faster in Lua for sequential tables.


```lua
for _, ent in ipairs(ents.FindByClass("prop_physics")) do
    -- use ent here
end
```
Reason: `ents.FindByClass` returns an iterator-friendly table without requiring manual construction, making it the standard approach for iterating specific entity classes in Garry's Mod Lua.


```lua
hook.Add("Think", "MyAddon.Think", function()
    -- Your think logic here
end)
```
Reason: The hook.Add function registers a callback for a specific hook name ("Think") with a unique identifier ("MyAddon.Think") to prevent duplicate registrations.


```lua
if IsValid(ent) then
    ent:SomeMethod()
end
```
Reason: `IsValid` is the standard Garry's Mod function that checks if an entity reference is not only non-nil but also represents an existing in-game entity, preventing errors from calling methods on invalid or deleted entities.


```lua
net.Receive("MyAddon.Sync", function(len, ply)
    -- Handle the incoming message here
end)
```
Reason: net.Receive registers a callback function to handle incoming network messages with the specified name.


```lua
for i = 1, #player.GetAll() do
	local v = player.GetAll()[i]
	-- use v here
end
```

Reason: Using a numeric for loop with a pre-cached table avoids the overhead of calling the pairs iterator function on every iteration, which is faster for small, fixed-size collections like the player list.


```lua
for _, ent in ipairs(ents.FindByClass("prop_physics")) do
    -- do something with ent
end
```
Reason: ents.FindByClass returns only entities of that class, avoiding the need to build and filter a table of all entities via ents.GetAll.


```lua
hook.Add( "Think", "MyAddon.Think", function() end )
```
Reason: hook.Add is the Garry's Mod API used to register a callback for a named hook, with the identifier allowing later reference or removal.


```lua
if IsValid(ent) then
    -- safely call methods on ent
end
```
Reason: IsValid is a global GMod function that safely checks whether the entity reference is non-nil and not pending removal, avoiding nil/index errors.


```lua
net.Receive("MyAddon.Sync", function(len, ply)
    -- Handle incoming net message data here
end)
```
Reason: net.Receive registers a callback that executes whenever a net message with the given name is received.


```lua
local players = player.GetAll()
for i = 1, #players do
    local v = players[i]
    -- ...
end
```
Reason: player.GetAll() returns a contiguous array, so caching it and using a numeric for loop avoids the hash-lookup overhead of pairs and is the fastest iteration method.


```lua
for ent in ents.Iterator("prop_physics") do
    -- your code here
end
```
Reason: ents.Iterator returns a lazy iterator that yields only entities of the given class without allocating a table of all entities.


```lua
hook.Add("Think", "MyAddon.Think", function()
end)
```
Reason: hook.Add is the GMod API used to register a callback on a named hook, with the second argument being the unique identifier.


```lua
if IsValid(ent) then
    ent:SomeMethod()
end
```
Reason: IsValid safely returns false for nil or NULL entities, avoiding runtime errors when calling methods on invalid references.


```lua
net.Receive( "MyAddon.Sync", function( len, ply )
    -- handle incoming net message data here
end )
```
Reason: net.Receive registers a callback that runs whenever a net message with the specified name is received.


```lua
local plys = player.GetAll()
for i = 1, #plys do
    local v = plys[i]
    -- ...
end
```
Reason: player.GetAll() returns a sequentially indexed table, so caching it and using a numeric for loop avoids pairs' hash iteration overhead and is the fastest way to visit all players.


```lua
for _, ent in ipairs(ents.FindByClass("prop_physics")) do
    -- do something with ent
end
```
Reason: ents.FindByClass returns only matching entities so no full entity table is built manually.


```lua
hook.Add("Think", "MyAddon.Think", function()
    -- minimal empty callback
end)
```
Reason: hook.Add registers a named callback on the given hook, using the identifier as the second argument.


```lua
if IsValid(ent) then
    ent:SomeMethod()
end
```

Reason: IsValid checks both that ent is not nil and that the entity hasn't been removed, preventing errors from calling methods on invalid entities.


```lua
util.AddNetworkString("MyAddon.Sync")

net.Receive("MyAddon.Sync", function(len, ply)
    -- handle incoming net message here
end)
```
Reason: util.AddNetworkString registers the net message name on both server and client, and net.Receive sets the callback to handle incoming messages with that name.


```lua
local players = player.GetAll()
for i = 1, #players do
    local v = players[i]
end
```
Reason: Using a numeric loop over the array returned by player.GetAll avoids hash traversal and per-iteration function calls from pairs, making it faster and more GC-friendly.