Skip to content

Commit d64beb6

Browse files
Better function to get weapon status
1 parent e348d10 commit d64beb6

1 file changed

Lines changed: 23 additions & 29 deletions

File tree

gamedata/scripts/talker_game_queries.script

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -219,40 +219,34 @@ end
219219
function get_weapon_info(npc)
220220
must_exist(npc, "get_weapon_info")
221221

222-
-- Check unstrapped state
222+
local active_item = try(npc.active_item, npc)
223+
local best_weapon = try(npc.best_weapon, npc)
223224
local is_unstrapped = try(npc.weapon_unstrapped, npc)
224225

225-
local weapon_str = nil
226-
local state = nil
226+
-- Pick the best available weapon object. For the player, active_item is primary.
227+
local weapon_obj = (active_item and is_weapon(active_item)) and active_item or best_weapon
227228

228-
-- Get best weapon (the one they would use)
229-
local best_weapon = try(npc.best_weapon, npc)
230-
-- Get active item (what is in hands)
231-
local active_item = try(npc.active_item, npc)
229+
if not weapon_obj then
230+
return nil, nil
231+
end
232232

233+
local weapon_str = get_item_description(weapon_obj)
234+
local state = "holstered"
235+
236+
-- Determine state (wielding/holstered)
233237
if is_unstrapped == true then
234-
-- Wielding
235-
local weapon_obj = (active_item and is_weapon(active_item)) and active_item or best_weapon
236-
if weapon_obj then
237-
weapon_str = get_item_description(weapon_obj)
238-
state = "wielding"
239-
end
240-
elseif is_unstrapped == false then
241-
-- Holstered (explicitly false)
242-
if best_weapon then
243-
weapon_str = get_item_description(best_weapon)
244-
state = "holstered"
245-
end
246-
else
247-
-- is_unstrapped returned nil (function missing or error)
248-
-- Fallback to active_item check
249-
if active_item and is_weapon(active_item) then
250-
weapon_str = get_item_description(active_item)
251-
state = "wielding"
252-
elseif best_weapon then
253-
weapon_str = get_item_description(best_weapon)
254-
state = "holstered"
255-
end
238+
state = "wielding"
239+
elseif is_unstrapped == nil then
240+
-- Fallback if engine support is missing
241+
if active_item and is_weapon(active_item) then
242+
state = "wielding"
243+
end
244+
end
245+
246+
-- Special case for the player: if they have a weapon in hand, it's effectively "wielding"
247+
-- even if unstrapped is false (e.g., during a reload animation)
248+
if is_player(npc) and active_item and is_weapon(active_item) then
249+
state = "wielding"
256250
end
257251

258252
return weapon_str, state

0 commit comments

Comments
 (0)