Vending Machine entity
Entity defined in plugin/entities/entities/nut_vend
Part of Nutscript Vending Machines
Defines the nut_vend entity of the Nutscript Vending Machines plugin, an admin-spawnable vending machine with four
buttons that sell drinks and supplements for tokens.
The file holds both realms. On the server ENT:Use finds the button the player aims at with ENT:GetNearestButton
and sells breens_water, smooth_breens_water, special_breens_water or citizen_supplements from that button's
stock, while Combine players switch the machine on and off or, holding sprint, refill an empty button for 25 tokens.
On the client ENT:Draw draws the product labels and a glowing sprite per button, green with stock, red when empty
and orange when the machine is off. The active state is kept in DT bool 0 and the four stocks in DT floats 1 to 4.
Summary
Methods
Methods
ENT:Draw()
client gamemodes/cwhl2rp/plugins/NutVendors/plugin/entities/entities/nut_vend/shared.lua:251Draws the machine with its product labels and a glowing sprite per button.
Sprites are green with stock, red when empty, orange when the machine is off, and the aimed-at button pulses.
ENT:GetNearestButton(client)
shared gamemodes/cwhl2rp/plugins/NutVendors/plugin/entities/entities/nut_vend/shared.lua:73Returns the index of the button the player is aiming at.
Traces 96 units from the player's eyes and picks the button within 2 units of the hit position. On the server the button positions are recomputed from the entity's current position first.
Parameters
- client Player optional, defaults to
nilThe player whose aim is checked; defaults to the local player on the client
Returns
- Number Button index from 1 to 4, or
nilwhen no button is aimed at
ENT:Initialize()
shared gamemodes/cwhl2rp/plugins/NutVendors/plugin/entities/entities/nut_vend/shared.lua:104On the server
Sets up the machine's model, frozen physics, button positions, full stock and active state.
A soda machine prop found inside its bounds is removed, and the machine takes over its position and angles.
On the client
Computes the button positions used for drawing the button sprites.
Defined in
ENT:SpawnFunction(client, trace)
shared gamemodes/cwhl2rp/plugins/NutVendors/plugin/entities/entities/nut_vend/shared.lua:51Spawns a vending machine at the trace hit position, facing the spawning player.
The yaw is snapped to 45 degrees. If a soda machine prop already sits in the new machine's
bounds, ENT:Initialize makes the machine take over that prop's position and angles.
Parameters
- client Player The player spawning the machine
- trace Map Trace result whose
HitPosis the spawn position
Returns
- Entity The new vending machine
ENT:Use(activator)
server gamemodes/cwhl2rp/plugins/NutVendors/plugin/entities/entities/nut_vend/shared.lua:148Handles a player pressing a button on the machine.
Combine toggle the machine on or off, or refill an empty button for 25 tokens while holding sprint. Other players buy the button's item (water, sparkling water, lemonade or supplements) if the machine is active, the button has stock and they can afford the price.
Parameters
- activator