Shared definition of the cw_factory_garbage_metal entity, a spawnable garbage recycler that turns metal junk items into scrap_metal items, with its settings, network vars and think logic.

ENT.GARBAGE_ITEMS lists the accepted items (empty cans and melee weapons), ENT.METAL_GARBAGE_COUNT_START (10) is the garbage needed for a cycle and ENT.WORK_TIME (30) its length in seconds. ENT:Think absorbs accepted cw_item entities above an idle recycler, each counting twice its weight, drains the count during a cycle and calls ENT:EndWork when the time is up. The single-file cw_factory_garbage_metal.lua next to this folder defines the same class and is loaded after it.

Summary

Methods

Returns whether the recycler accepts an item as garbage.
Draw()client
Draws the recycler and its indicator screen with the status, garbage count and progress bars.
Eject()server
Moves the collected garbage into the eject storage entity and empties the recycler.
EndWork()server
Finishes the cycle: stops the work sounds, uses up the collected garbage and spawns a scrap_metal item at the product position.
Returns the corners of the box above the recycler that garbage is collected from.
Sets up the recycler model, physics and empty garbage state.
Stops the recycler's work sound.
Declares the product position, garbage count, working state, work timing, eject storage and stop time network vars.
Spawns a metal recycler 25 units off the aimed surface.
Starts a recycling cycle, or resumes a stopped one where it left off.
Pauses the current cycle, remembering the time left, and stops the work sounds.
Think()shared
Collects garbage, plays the work sounds and advances the recycling cycle every tick on the server.
Does nothing; the recycler is operated through its entity menu options.

Methods

Returns whether the recycler accepts an item as garbage.

Parameters

  • item Item The item to check

Returns

  • Boolean Whether the item's unique ID is in ENT.GARBAGE_ITEMS

Draws the recycler and its indicator screen with the status, garbage count and progress bars.

While the local player holds the toolgun, a marker also shows the product position.

Moves the collected garbage into the eject storage entity and empties the recycler.

The storage is found by the creation ID set with SetEjectStorage. Does nothing while working or paused, when the storage does not exist or without the Storage plugin. Items that would push a known container over its weight limit are dropped on top of it instead.

Finishes the cycle: stops the work sounds, uses up the collected garbage and spawns a scrap_metal item at the product position.

Returns the corners of the box above the recycler that garbage is collected from.

Returns

  • List<Vector> The minimum and maximum corners, as passed to ents.FindInBox

On the server

Sets up the recycler model, physics and empty garbage state.

On the client

Creates the render target and material for the indicator screen.

Defined in

Stops the recycler's work sound.

Declares the product position, garbage count, working state, work timing, eject storage and stop time network vars.

Spawns a metal recycler 25 units off the aimed surface.

Parameters

  • ply
  • trace

Returns

  • Entity The spawned recycler

Starts a recycling cycle, or resumes a stopped one where it left off.

A new cycle only starts once the garbage count is at least ENT.METAL_GARBAGE_COUNT_START and lasts ENT.WORK_TIME seconds.

Pauses the current cycle, remembering the time left, and stops the work sounds.

Collects garbage, plays the work sounds and advances the recycling cycle every tick on the server.

Garbage cw_item entities inside ENT:GetSearchPos are taken while the recycler is idle and not full. During a cycle the garbage count drains step by step and ENT:EndWork runs when the time is up.

Does nothing; the recycler is operated through its entity menu options.

Parameters

  • activator

Defined in