void Inventory_delete(entity e) { delete(e.inventory); }
void Inventory_update(entity e) { e.inventory.SendFlags = 0xFFFFFF; }
-void InventoryStorage_attach(entity e) { e.inventory_store = NEW(Inventory); e.inventory_store.drawonlytoclient = e; }
-void InventoryStorage_delete(entity e) { delete(e.inventory_store); }
-void InventoryStorage_clear(entity e)
+void Inventory_clear(entity store)
{
- // we don't need to network the changes, that is done when the inventory is detached
+ // NOTE: you will need to perform Inventory_update after this to update the storage entity
+ // (unless store is the storage entity)
FOREACH(Items, true, {
.int fld = inv_items[it.m_id];
- e.inventory_store.(fld) = 0;
+ store.(fld) = 0;
});
}
+
+void InventoryStorage_attach(entity e) { e.inventory_store = NEW(Inventory); e.inventory_store.drawonlytoclient = e; }
+void InventoryStorage_delete(entity e) { delete(e.inventory_store); }
#endif
void Inventory_new(PlayerState this);
void Inventory_delete(entity this);
+void Inventory_clear(PlayerState this);
void InventoryStorage_attach(PlayerState this);
void InventoryStorage_delete(PlayerState this);
-void InventoryStorage_clear(PlayerState this);
void PlayerState_attach(entity this)
{
PlayerState ps = PS(this);
if (!ps) return; // initial connect
PS(this) = NULL;
- InventoryStorage_clear(this);
+ Inventory_clear(this.inventory_store); // no need to network updates, as there is no inventory attached
if (ps.m_client != this) return; // don't own state, spectator
ps.ps_push(ps, this);
entity store = PS(it);
if (store)
{
- for (int j = 0; j < REGISTRY_COUNT(Items); j++)
- store.inventory.inv_items[j] = 0;
+ Inventory_clear(store.inventory);
Inventory_update(store);
}
});