From 899bda8ba0434f145e2163c62e1f7f75b6dbc51f Mon Sep 17 00:00:00 2001 From: z411 Date: Thu, 15 Oct 2020 14:06:28 -0300 Subject: [PATCH] Inventory fix --- qcsrc/client/hud/panel/scoreboard.qc | 7 +++++-- qcsrc/common/items/inventory.qh | 15 +++++++++++++++ qcsrc/common/items/item/pickup.qc | 1 + qcsrc/server/command/vote.qc | 6 +++++- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/qcsrc/client/hud/panel/scoreboard.qc b/qcsrc/client/hud/panel/scoreboard.qc index f53a29976..84412ec0c 100644 --- a/qcsrc/client/hud/panel/scoreboard.qc +++ b/qcsrc/client/hud/panel/scoreboard.qc @@ -1233,7 +1233,9 @@ void Scoreboard_Duel_DrawTable(vector pos, bool invert, entity pl, entity tm) int weapon_cnt_fired = pl.accuracy_cnt_fired[i - WEP_FIRST]; int weapon_cnt_hit = pl.accuracy_cnt_hit[i - WEP_FIRST]; - int weapon_acc = floor((weapon_cnt_hit / weapon_cnt_fired) * 100); + int weapon_acc = 0; + if(weapon_cnt_fired) + weapon_acc = floor((weapon_cnt_hit / weapon_cnt_fired) * 100); average_acc += weapon_acc; string draw_str; @@ -1271,7 +1273,8 @@ void Scoreboard_Duel_DrawTable(vector pos, bool invert, entity pl, entity tm) if(weapon_cnt_fired) total_weapons++; }); - average_acc = floor((average_acc / total_weapons) + 0.5); + if(total_weapons) + average_acc = floor((average_acc / total_weapons) + 0.5); // draw total accuracy now tmp_str = sprintf("%d%%", average_acc); diff --git a/qcsrc/common/items/inventory.qh b/qcsrc/common/items/inventory.qh index f4abe5eb5..761af2a9c 100644 --- a/qcsrc/common/items/inventory.qh +++ b/qcsrc/common/items/inventory.qh @@ -46,6 +46,7 @@ NET_HANDLE(ENT_CLIENT_INVENTORY, bool isnew) float entnum = ReadByte(); inventoryslots[entnum-1] = this; + LOG_INFO("Got inventory"); const int majorBits = Readbits(Inventory_groups_major); for (int i = 0; i < Inventory_groups_major; ++i) { @@ -89,6 +90,7 @@ void Inventory_Write(Inventory data) int maj = G_MAJOR(it.m_id); majorBits = BITSET(majorBits, BIT(maj), true); minorBitsArr[maj] = BITSET(minorBitsArr[maj], BIT(G_MINOR(it.m_id)), true); + data.inventory.(fld) = data.(fld); // z411 fix } }); @@ -145,4 +147,17 @@ void Inventory_new(PlayerState this) } void Inventory_delete(entity e) { delete(e.inventory.inventory); delete(e.inventory); } void Inventory_update(entity e) { e.inventory.SendFlags = 0xFFFFFF; } + +void Inventory_ClearAll() { + LOG_INFO("Clearing inventory"); + + FOREACH_CLIENT(IS_PLAYER(it), { + entity store = PS(it); + FOREACH(Items, true, { + store.inventory.inv_items[it.m_id] = 0; + }); + Inventory_update(store); + }); +} + #endif diff --git a/qcsrc/common/items/item/pickup.qc b/qcsrc/common/items/item/pickup.qc index a3c2d779e..aef34cc1b 100644 --- a/qcsrc/common/items/item/pickup.qc +++ b/qcsrc/common/items/item/pickup.qc @@ -15,6 +15,7 @@ METHOD(Pickup, giveTo, bool(Pickup this, entity item, entity player)) entity store = IS_PLAYER(player) ? PS(player) : player; store.inventory.inv_items[this.m_id]++; Inventory_update(store); + //store.inventory.inventory.inv_items[this.m_id]++; } return b; } diff --git a/qcsrc/server/command/vote.qc b/qcsrc/server/command/vote.qc index c24459762..edd898546 100644 --- a/qcsrc/server/command/vote.qc +++ b/qcsrc/server/command/vote.qc @@ -415,6 +415,7 @@ void ReadyRestart_think(entity this) restart_mapalreadyrestarted = true; reset_map(true); Score_ClearAll(); + Inventory_ClearAll(); delete(this); } @@ -491,7 +492,10 @@ void ReadyRestart() // Reset ALL scores, but only do that at the beginning of the countdown if sv_ready_restart_after_countdown is off! // Otherwise scores could be manipulated during the countdown. - if (!sv_ready_restart_after_countdown) Score_ClearAll(); + if (!sv_ready_restart_after_countdown) { + Score_ClearAll(); + Inventory_ClearAll(); + } ReadyRestart_force(); } -- 2.39.2