Shared definition of the cw_factoryrationdispenser entity of the Ration Factory plugin, with the networked ration timer, flash timer, lock state and ration count, and IsLocked and GetRationCount.

Originally written for the Iron Wall community.

Summary

Methods

Starts dispensing a ration to a player after a delay.
Blocks every toolgun action on the dispenser.
Spawns a prop in front of the dispenser to play the dispensing animation with.
Draw()client
Draws the status light: blinking blue while dispensing, red when flashing, orange when locked, else green.
Plays one of the Combine button sounds at random.
Returns how many rations the dispenser has left.
Draws the dispenser's name and ration count for Combine players looking at it.
Attaches the Combine dispenser model, sets up the collision box and starts with five rations.
Returns whether the dispenser is locked.
Lock()server
Locks the dispenser so citizens cannot take rations, with a button sound.
Keeps the dispenser still unless a player holds it or it is constrained.
Flashes the dispenser's light red with a denial sound.
Sets how many rations the dispenser holds.
Sets up the networked ration timer, flash timer, lock state and ration count.
Toggle()server
Locks the dispenser when it is unlocked and unlocks it otherwise.
Unlock()server
Unlocks the dispenser so citizens can take rations again, with a button sound.
Makes the dispenser always transmit to clients.
Handles a player using the dispenser, at most once every three seconds.

Methods

Starts dispensing a ration to a player after a delay.

The ration's quality and delay depend on the player's civ_reputation character data: ration_high after 8 seconds above 50 reputation (or for CWU members), ration_medium after 12 above 25, ration_standard after 18 above 10, and ration_normal after 26 otherwise. When the delay ends the dispenser animates a package and spawns the ration item for the player. Does nothing while a previous ration is still being dispensed.

Parameters

  • activator Player The player who receives the ration
  • duration Number optional, defaults to nil Unused; the delay always comes from the reputation
  • force Boolean optional, defaults to nil Dispense even while a previous ration is still pending

Blocks every toolgun action on the dispenser.

Parameters

  • player
  • trace
  • tool

Spawns a prop in front of the dispenser to play the dispensing animation with.

Parameters

  • model String Model of the prop

Returns

  • Entity The prop_physics prop

Draws the status light: blinking blue while dispensing, red when flashing, orange when locked, else green.

Plays one of the Combine button sounds at random.

Returns how many rations the dispenser has left.

Returns

  • Number The ration count

Draws the dispenser's name and ration count for Combine players looking at it.

Parameters

  • x
  • y
  • alpha

Attaches the Combine dispenser model, sets up the collision box and starts with five rations.

Returns whether the dispenser is locked.

Returns

  • Boolean Whether the dispenser is locked

Locks the dispenser so citizens cannot take rations, with a button sound.

Keeps the dispenser still unless a player holds it or it is constrained.

Parameters

  • physicsObject

Flashes the dispenser's light red with a denial sound.

Parameters

  • duration Number How long the light stays red, in seconds

Sets how many rations the dispenser holds.

Parameters

  • count Number The new ration count

Sets up the networked ration timer, flash timer, lock state and ration count.

Locks the dispenser when it is unlocked and unlocks it otherwise.

Unlocks the dispenser so citizens can take rations again, with a button sound.

Makes the dispenser always transmit to clients.

Handles a player using the dispenser, at most once every three seconds.

Citizens get a ration when the dispenser is unlocked, has rations left and their nextration character data time has passed, which is then set ten wage intervals ahead; otherwise the light flashes red. Combine players load a ration_standard from their inventory into it, or toggle the lock when they carry none.

Parameters

  • activator
  • caller

Defined in