added support for spawning preloaded ammo using a single meta element
This commit is contained in:
parent
cc309bb6f2
commit
33bc4da625
1
TODO.txt
1
TODO.txt
@ -41,6 +41,7 @@
|
||||
( ) AR15
|
||||
( ) Berreta m12 (smg)
|
||||
|
||||
( ) remove total_bullets as a meta property.
|
||||
( ) `textures` should be in visuals!!!
|
||||
( ) `inventory_image_magless` should be in visuals!!!
|
||||
( ) leave round in chamber if reloading the same type of Ammunition
|
||||
|
27
ammo_api.lua
27
ammo_api.lua
@ -31,7 +31,15 @@ end
|
||||
function Guns4d.ammo.update_mag(def, itemstack, meta)
|
||||
def = def or Guns4d.ammo.registered_magazines[itemstack:get_name()]
|
||||
meta = meta or itemstack:get_meta()
|
||||
local bullets = minetest.deserialize(meta:get_string("guns4d_loaded_bullets"))
|
||||
local bullets
|
||||
if meta:get_int("guns4d_spawn_with_ammo") > 0 then
|
||||
bullets = {
|
||||
[def.accepted_bullets[1]]=meta:get_int("guns4d_spawn_with_ammo")
|
||||
}
|
||||
meta:set_int("guns4d_spawn_with_ammo")
|
||||
else
|
||||
bullets = minetest.deserialize(meta:get_string("guns4d_loaded_bullets"))
|
||||
end
|
||||
local count = 0
|
||||
for i, v in pairs(bullets) do
|
||||
count = count + v
|
||||
@ -186,3 +194,20 @@ function Guns4d.ammo.register_magazine(def)
|
||||
--register the actual recipe to add ammo to a mag
|
||||
end
|
||||
|
||||
function Guns4d.ammo.magazine(magname)
|
||||
local mag = ItemStack()
|
||||
end
|
||||
|
||||
function Guns4d.ammo.magazine_of_gun(gunname, full, string)
|
||||
local gprops = Guns4d.gun.registered[gunname].properties
|
||||
local magname = gprops.ammo.accepted_magazines[1]
|
||||
assert(magname, "magazines are not accepted")
|
||||
local mag = ItemStack(magname)
|
||||
local meta = mag:get_meta()
|
||||
local new_ammo_table = {}
|
||||
if full then
|
||||
new_ammo_table[gprops.ammo.accepted_bullets[1]] = Guns4d.ammo.registered_magazines[magname].capacity
|
||||
end
|
||||
meta:set_string("guns4d_loaded_bullets", minetest.serialize(new_ammo_table))
|
||||
return (string and mag:to_string()) and mag
|
||||
end
|
||||
|
@ -9,17 +9,33 @@ Ammo_handler = Instantiatable_class:inherit({
|
||||
local gun = def.gun
|
||||
def.ammo = {}
|
||||
if gun.properties.ammo then
|
||||
if meta:get_string("guns4d_loaded_bullets") == "" then
|
||||
def.ammo.loaded_mag = gun.properties.ammo.comes_with or "empty"
|
||||
def.ammo.next_bullet = "empty"
|
||||
def.ammo.total_bullets = 0
|
||||
def.ammo.loaded_bullets = {}
|
||||
if meta:get_int("guns4d_spawn_with_ammo") > 0 then
|
||||
local bullets = meta:get_int("guns4d_spawn_with_ammo")
|
||||
if gun.properties.ammo.magazine_only then
|
||||
def.ammo.loaded_mag = gun.properties.ammo.accepted_magazines[1]
|
||||
def.ammo.loaded_bullets = {
|
||||
[Guns4d.registered_magazines[gun.properties.ammo.accepted_magazines[1]].accepted_bullets[1]] = bullets
|
||||
}
|
||||
else
|
||||
def.ammo.loaded_mag = "empty"
|
||||
def.ammo.loaded_bullets = gun.properties.accepted_bullets[1]
|
||||
end
|
||||
def.ammo.total_bullets = bullets
|
||||
meta:set_int("guns4d_spawn_with_ammo")
|
||||
def:update_meta()
|
||||
else
|
||||
def.ammo.loaded_mag = meta:get_string("guns4d_loaded_mag")
|
||||
def.ammo.loaded_bullets = minetest.deserialize(meta:get_string("guns4d_loaded_bullets"))
|
||||
def.ammo.total_bullets = meta:get_int("guns4d_total_bullets")
|
||||
def.ammo.next_bullet = meta:get_string("guns4d_next_bullet")
|
||||
if meta:get_string("guns4d_loaded_bullets") == "" then
|
||||
def.ammo.loaded_mag = gun.properties.ammo.comes_with or "empty"
|
||||
def.ammo.next_bullet = "empty"
|
||||
def.ammo.total_bullets = 0
|
||||
def.ammo.loaded_bullets = {}
|
||||
def:update_meta()
|
||||
else
|
||||
def.ammo.loaded_mag = meta:get_string("guns4d_loaded_mag")
|
||||
def.ammo.loaded_bullets = minetest.deserialize(meta:get_string("guns4d_loaded_bullets"))
|
||||
def.ammo.total_bullets = meta:get_int("guns4d_total_bullets") --TODO: REMOVE TOTAL_BULLETS AS A META
|
||||
def.ammo.next_bullet = meta:get_string("guns4d_next_bullet")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -29,6 +29,20 @@ local gun_default = {
|
||||
burst = "inventory_overlay_burst.png",
|
||||
safe = "inventory_overlay_safe.png"
|
||||
},
|
||||
bloom = {
|
||||
base_aiming = 0, --amount of bloom at a full rest while aiming down sights (if possible)
|
||||
base_hip = 0, --amount of bloom at rest while not aiming down sights.
|
||||
recoil = {
|
||||
decay = 1, --decay rate
|
||||
amount = 0,
|
||||
ratio = 0, --ratio of x to y
|
||||
},
|
||||
walking = {
|
||||
decay = 1,
|
||||
amount = 0,
|
||||
ratio = 0,
|
||||
}
|
||||
},
|
||||
infinite_inventory_overlay = "inventory_overlay_inf_ammo.png",
|
||||
recoil = { --used by update_recoil()
|
||||
velocity_correction_factor = { --velocity correction factor is currently very broken.
|
||||
@ -162,6 +176,13 @@ local gun_default = {
|
||||
}
|
||||
},
|
||||
},
|
||||
--[[
|
||||
ammo = {
|
||||
accepted_magazines = {},
|
||||
accepted_bullets = {},
|
||||
magazine_only = false
|
||||
}
|
||||
]]
|
||||
initial_vertical_rotation = -60,
|
||||
--inventory_image
|
||||
--inventory_image_empty
|
||||
@ -192,10 +213,11 @@ local gun_default = {
|
||||
player_axial = Vec.new(),
|
||||
},
|
||||
},
|
||||
animation_rotation = vector.new(),
|
||||
spread = {
|
||||
|
||||
recoil = vector.new(),
|
||||
walking = vector.new()
|
||||
},
|
||||
animation_rotation = vector.new(),
|
||||
--[[total_offset_rotation = { --can't be in offsets, as they're added automatically.
|
||||
gun_axial = Vec.new(),
|
||||
player_axial = Vec.new(),
|
||||
|
Loading…
x
Reference in New Issue
Block a user