Page 1 of 1

How to implement automatic ammunition loading through scripts on the platform

Posted: Tue Dec 10, 2024 10:33 am
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