station/assets/scripts/vending.rn

13 lines
443 B
Plaintext
Raw Normal View History

// Free bread while stock lasts. Stock is a per-machine variable that is saved
// with the world, so every machine keeps its own count.
pub fn dispense(ctx) {
let stock = ctx.get_var("stock");
if stock <= 0 {
ctx.message("The vending machine is empty.");
return false;
}
ctx.set_var("stock", stock - 1);
ctx.give_item("bread", 1);
ctx.message(`The machine dispenses some bread. (${stock - 1} left)`);
}