Skip to content

Commit

Permalink
Merge pull request #94 from RAX-Anomaly/one_in_chamber
Browse files Browse the repository at this point in the history
chamber single round with drag-drop
  • Loading branch information
ahuyn committed Aug 8, 2021
2 parents b62aef6 + 0d979e4 commit 3fe432f
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion gamedata/scripts/magazines.script
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,10 @@ function on_item_drag_dropped(item, weapon, from_slot, to_slot)
else
load_weapon(weapon, item)
end

end
-- bullet to weapon
if (IsAmmo(item) and IsWeapon(weapon)) then
chamber_single_round(item, weapon)
end
end

Expand Down Expand Up @@ -262,6 +265,27 @@ function delay_load_weapon(weapon, magazine, pre_table, first_round)
return false
end

-- put a single round in the chamber
--only works if they are compatible and there is no magazine inserted
function chamber_single_round(ammo, weapon)
local mag_data = get_mag_data(weapon:id())
print_dbg("do chamber one round")
if get_config("retain_round") and weapon:get_ammo_in_magazine() == 0 and is_supported_weapon(weapon) and mag_data == false then
local ammo_map = get_ammo_map(weapon:id())
local typ = ammo_map[ammo:section()]
if not typ then return end
print_dbg("chamber single round, ammo is %s, type is %s", ammo:section(), typ - 1)
weapon:set_ammo_elapsed(1)
weapon:set_ammo_type(typ - 1)
utils_obj.play_sound("handgun_unjam")
if ammo:ammo_get_count() == 1 then
alife_release_id(ammo:id())
else
ammo:ammo_set_count(ammo:ammo_get_count() - 1)
end
end
end

-- When weapon is reloaded in any way, it will subtract a box from player inventory. We don't want this to happen - loading should only happen from magazines. Record the prior amount of ammo before reload and refund it afterwards.
function count_ammo(weapon)
local ammo_table = {}
Expand Down

0 comments on commit 3fe432f

Please sign in to comment.