Skip to content

Commit 35bbfa1

Browse files
committed
add storage monitor info to readme
1 parent 869573a commit 35bbfa1

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,44 @@ rustplus.on('message', (message) => {
156156
});
157157
```
158158

159+
#### Storage Monitor
160+
161+
The Storage Monitor that was recently added to Rust sends Entity Changed Broadcasts when items are added and removed from the Storage Container that the Storage Monitor is associated with.
162+
163+
You will receive two broadcasts for the Storage Monitor, one with the `entityChanged.payload.value` set to `true` and the second with the `entityChanged.payload.value` set to `false`. When using the official Rust+ app you'll see the storage monitor entity change to green, then back to grey.
164+
165+
You can use the following snippet as an idea of how to listen for changes to a Storage Monitor and print out the current items in it.
166+
167+
As above, make sure to call `getEntityInfo` with the Storage Monitor entity id so you are sent the broadcasts by the server.
168+
169+
```js
170+
rustplus.on('message', (message) => {
171+
if(message.broadcast && message.broadcast.entityChanged){
172+
173+
var entityChanged = message.broadcast.entityChanged;
174+
175+
var entityId = entityChanged.entityId;
176+
var value = entityChanged.payload.value;
177+
var capacity = entityChanged.payload.capacity;
178+
var items = entityChanged.payload.items;
179+
180+
// only print info when second broadcast is received
181+
if(!value){
182+
183+
console.log(`entity ${entityId} has a capacity of ${capacity}`);
184+
console.log(`entity ${entityId} contains ${items.length} item(s)`);
185+
186+
// print out the items in this storage entity
187+
items.forEach((item) => {
188+
console.log(item);
189+
});
190+
191+
}
192+
193+
}
194+
});
195+
```
196+
159197
## Handle Messages
160198

161199
A message is a payload of data sent to you from the Rust Server. This shouldn't be confused with Chat Messages.

0 commit comments

Comments
 (0)