From 0870636171b5228b4c4f75f953d5ca8a52e6fa0e Mon Sep 17 00:00:00 2001 From: Lars Date: Thu, 3 Mar 2022 15:54:57 -0800 Subject: [PATCH] optional infinite ammo --- init.lua | 20 ++++++++++++-------- settingtypes.txt | 2 ++ 2 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 settingtypes.txt diff --git a/init.lua b/init.lua index 2adf994..2884a45 100644 --- a/init.lua +++ b/init.lua @@ -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,15 +123,18 @@ local ammoCount = gunMeta:get_int("RW_bullets") local ammoName = gunMeta:get_string("RW_ammo_name") local inv = player:get_inventory() -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) +if inf_ammo then + gunMeta:set_int("RW_bullets",clipSize) else -gunMeta:set_int("RW_bullets",reload_ammo:get_count()) -inv:remove_item("main",reload_ammo:get_name().." "..reload_ammo:get_count()) + 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) + 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()) diff --git a/settingtypes.txt b/settingtypes.txt new file mode 100644 index 0000000..e406172 --- /dev/null +++ b/settingtypes.txt @@ -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