How to implement automatic ammunition loading through scripts on the platform

Place to post guides, observations, things related to modding that are not mods themselves.
sdgmlj
Fast Inserter
Fast Inserter
Posts: 168
Joined: Sun Jul 04, 2021 11:12 pm
Contact:

How to implement automatic ammunition loading through scripts on the platform

Post by sdgmlj »

I wrote a mod that automatically loads ammunition through a script. It works normally on Earth, but is not effective on the platform. Can anyone help me modify it? thank you

Code: Select all

function ammo.stowage_on_tick(event)
	if event.tick % filling_time == 0 then
		for _, surface in pairs(game.surfaces) do
			local entitys = surface.find_entities_filtered{name = "v2-ammo-stowage"}
			if next(entitys) == nil then return end
			for _, entity in pairs(entitys) do
				local chest_inventory = entity.get_inventory(defines.inventory.chest)
				if chest_inventory.is_empty() then return end		
				if entity and entity.valid then
					local position = entity.position
					local radiu = entity_quality_radiu(entity)
					for _,name in pairs(turrets) do
						local turret_s = surface.find_entities_filtered{name = name, position = position, radius = radiu}
						if next(turret_s) ~= nil then
							for _, turret in pairs(turret_s) do
								if turret and turret.valid 
								then ammo_loading(entity,turret)
								end
							end	
						end
					end
				end
			end
		end
	end
end
Post Reply

Return to “Modding discussion”