From bedf25b6f6e95edcc83bef18ca2f0c597e321de4 Mon Sep 17 00:00:00 2001 From: haunter Date: Tue, 5 May 2026 21:00:54 +0300 Subject: [PATCH] fix 1 --- bot_modules/02_state.js | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/bot_modules/02_state.js b/bot_modules/02_state.js index 5a5fa5d..a868dfb 100644 --- a/bot_modules/02_state.js +++ b/bot_modules/02_state.js @@ -17,18 +17,27 @@ function gatherState() { const total_points = uw.Game?.player_points ?? 0; const world = uw.Game?.world_id || ''; - let battle_points = { att: 0, def: 0, available: 0, used: 0 }; + let battle_points = { available: 0, used: 0 }; try { - const pk = uw.MM?.getModels?.()?.PlayerKillpoints; - if (pk) { - const m = pk[player_id] || Object.values(pk)[0]; - if (m && m.attributes) { - battle_points = { - att: m.attributes.att || 0, - def: m.attributes.def || 0, - available: m.attributes.available || 0, - used: m.attributes.used || 0 - }; + const pkModels = uw.MM?.getModels?.()?.PlayerKillpoints; + if (pkModels && pkModels[player_id]) { + const pk = pkModels[player_id]; + battle_points.used = pk.attributes?.used || 0; + if (typeof pk.getUnusedPoints === 'function') { + battle_points.available = pk.getUnusedPoints(); + } else if (pk.attributes?.available !== undefined) { + battle_points.available = pk.attributes.available; + } + } + + // Force sync with the exact UI number if available (e.g. 1986) + if (uw.$) { + const uiText = uw.$('.nui_battlepoints_container .points').text(); + if (uiText) { + const parsed = parseInt(uiText.replace(/[^\d]/g, ''), 10); + if (!isNaN(parsed)) { + battle_points.available = parsed; + } } } } catch (e) { log(`Failed to extract battle_points: ${e}`); }