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 gun_reload = GunCaps.gun_reload or 0.25
end end
local inf_ammo = minetest.settings:get_bool("infinite_ammo") or false
local playerMeta = player:get_meta() local playerMeta = player:get_meta()
local gunMeta = itemstack: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 ammoName = gunMeta:get_string("RW_ammo_name")
local inv = player:get_inventory() local inv = player:get_inventory()
inv:add_item("main",ammoName.." "..ammoCount) if inf_ammo then
gunMeta:set_int("RW_bullets",clipSize)
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 else
gunMeta:set_int("RW_bullets",reload_ammo:get_count()) inv:add_item("main",ammoName.." "..ammoCount)
inv:remove_item("main",reload_ammo:get_name().." "..reload_ammo:get_count())
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 end
gunMeta:set_string("RW_ammo_name",reload_ammo:get_name()) 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