Help with ammo prototypes

Place to post guides, observations, things related to modding that are not mods themselves.
Post Reply
Mernom
Fast Inserter
Fast Inserter
Posts: 122
Joined: Sun Jul 15, 2018 10:05 pm
Contact:

Help with ammo prototypes

Post by Mernom »

I'm having a lot of trouble wrangling that prototype. It's structure is VERY weird... what's with multiple sets of double brackets.
trying to run the following function:

Code: Select all

function mod_ammo_properties(ammo_name, speed, rn_div, dir_div)
	--data validation
	local ammo
	if data.raw.ammo[ammo_name].ammo_type.action then 
	  ammo = data.raw.ammo[ammo_name].ammo_type.action 
	else merlib.error("mod_ammo_properties: bad name detected for "..ammo_name) return end
	
	local r,s,d
	if speed and type(speed) == "number" then
	  if not speed == -1 then s = speed end
	else merlib.error("mod_ammo_properties: bad speed detected for "..ammo_name) end
	
	if rn_div and type(rn_div) == "number" then
	  if not rn_div == -1 then r = rn_div end
	else  merlib.error("mod_ammo_properties: bad range diveation detected for "..ammo_name) end
	
	if dir_div and type(dir_div) == "number" then
	  if not dir_div == -1 then d = dir_div end
	else  merlib.error("mod_ammo_properties: bad direction deviation detected for "..ammo_name) end
	
	--begin function
	for _, ammo_a in pairs(ammo) do
	  if not ammo_a.action_delivery[1] then merlib.error("mod_ammo_properties: final check failed for "..ammo_name) return else
	  if ammo_a.action_delivery[1].direction_deviation then
	    if d then
		  ammo_a.action_delivery[1].direction_deviation = d
		else merlib.error("mod_ammo_properties: direction mod failed for "..ammo_name) end
	  end
	  if ammo_a.action_delivery[1].range_deviation then
	    if r then 
	      ammo_a.action_delivery[1].range_deviation = r
		else merlib.error("mod_ammo_properties: range mod failed for "..ammo_name) end
	  end
	  if ammo_a.action_delivery[1].starting_speed then
	    if v then
	      ammo_a.action_delivery[1].starting_speed = s
		else merlib.error("mod_ammo_properties: speed mod failed for "..ammo_name) end
	  end
	end
	end

end
jumps the following errors when I try to run it on a list of the vanilla ammo:

Code: Select all

 5.677 Script @__KS-Combat-sniper-fix__/prototypes/ammo.lua:4: KSF: mod_ammo_properties: direction mod failed for firearm-magazine
   5.677 Script @__KS-Combat-sniper-fix__/prototypes/ammo.lua:4: KSF: mod_ammo_properties: range mod failed for firearm-magazine
   5.677 Script @__KS-Combat-sniper-fix__/prototypes/ammo.lua:4: KSF: mod_ammo_properties: speed mod failed for firearm-magazine
   5.677 Script @__KS-Combat-sniper-fix__/prototypes/ammo.lua:4: KSF: mod_ammo_properties: final check failed for piercing-rounds-magazine
   5.677 Script @__KS-Combat-sniper-fix__/prototypes/ammo.lua:4: KSF: mod_ammo_properties: final check failed for uranium-rounds-magazine
   
The thing is, I run a very similiar thing before, and it actually worked as far as I know:

Code: Select all

local bullet_speed 
for _, ammo in pairs(data.raw.ammo["firearm-magazine"].ammo_type.action) do
	if ammo.action_delivery[1].starting_speed then
		bullet_speed = ammo.action_delivery[1].starting_speed
	end
end
I'm not sure why one would work and not the other.

Post Reply

Return to “Modding discussion”