optional infinite ammo

This commit is contained in:
Lars 2022-03-03 15:54:57 -08:00
parent 2957951e9b
commit 0870636171
2 changed files with 14 additions and 8 deletions

@ -71,6 +71,7 @@ if GunCaps ~= nil then
gun_reload = GunCaps.gun_reload or 0.25
end
local inf_ammo = minetest.settings:get_bool("infinite_ammo") or false
local playerMeta = player:get_meta()
local gunMeta = itemstack:get_meta()
@ -122,9 +123,11 @@ local ammoCount = gunMeta:get_int("RW_bullets")
local ammoName = gunMeta:get_string("RW_ammo_name")
local inv = player:get_inventory()
if inf_ammo then
gunMeta:set_int("RW_bullets",clipSize)
else
inv:add_item("main",ammoName.." "..ammoCount)
if inv:contains_item("main",reload_ammo:get_name().." "..clipSize) then
inv:remove_item("main",reload_ammo:get_name().." "..clipSize)
gunMeta:set_int("RW_bullets",clipSize)
@ -132,6 +135,7 @@ else
gunMeta:set_int("RW_bullets",reload_ammo:get_count())
inv:remove_item("main",reload_ammo:get_name().." "..reload_ammo:get_count())
end
end
gunMeta:set_string("RW_ammo_name",reload_ammo:get_name())

2
settingtypes.txt Normal file

@ -0,0 +1,2 @@
# If true, a gun can always be reloaded (just need at least one matching bullet in the inventory)
infinite_ammo (Inifinite Ammo) bool false