| 
									
										
										
										
											2021-04-07 01:55:53 +02:00
										 |  |  | function get_any_stack_size(name) | 
					
						
							| 
									
										
										
										
											2024-11-11 11:43:16 +01:00
										 |  |  |     local item = prototypes.item[name] | 
					
						
							| 
									
										
										
										
											2021-04-07 01:55:53 +02:00
										 |  |  |     if item ~= nil then | 
					
						
							|  |  |  |         return item.stack_size | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2024-11-11 11:43:16 +01:00
										 |  |  |     item = prototypes.equipment[name] | 
					
						
							| 
									
										
										
										
											2021-04-07 01:55:53 +02:00
										 |  |  |     if item ~= nil then | 
					
						
							|  |  |  |         return item.stack_size | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |     -- failsafe | 
					
						
							|  |  |  |     return 1 | 
					
						
							| 
									
										
										
										
											2021-07-04 15:25:56 +02:00
										 |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | -- from https://stackoverflow.com/a/40180465 | 
					
						
							|  |  |  | -- split("a,b,c", ",") => {"a", "b", "c"} | 
					
						
							|  |  |  | function split(s, sep) | 
					
						
							|  |  |  |     local fields = {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     sep = sep or " " | 
					
						
							|  |  |  |     local pattern = string.format("([^%s]+)", sep) | 
					
						
							|  |  |  |     string.gsub(s, pattern, function(c) fields[#fields + 1] = c end) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return fields | 
					
						
							| 
									
										
										
										
											2023-03-15 17:03:33 +01:00
										 |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function random_offset_position(position, offset) | 
					
						
							| 
									
										
										
										
											2024-11-11 11:43:16 +01:00
										 |  |  |     return {x=position.x+math.random(-offset, offset), y=position.y+math.random(-offset, offset)} | 
					
						
							| 
									
										
										
										
											2023-03-15 17:03:33 +01:00
										 |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function fire_entity_at_players(entity_name, speed) | 
					
						
							| 
									
										
										
										
											2024-11-30 06:53:28 +01:00
										 |  |  |     local entities = {} | 
					
						
							| 
									
										
										
										
											2023-03-15 17:03:33 +01:00
										 |  |  |     for _, player in ipairs(game.forces["player"].players) do | 
					
						
							| 
									
										
										
										
											2024-11-30 06:53:28 +01:00
										 |  |  |         if player.character ~= nil then | 
					
						
							|  |  |  |             table.insert(entities, player.character) | 
					
						
							| 
									
										
										
										
											2023-03-15 17:03:33 +01:00
										 |  |  |         end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2024-11-30 06:53:28 +01:00
										 |  |  |     return fire_entity_at_entities(entity_name, entities, speed) | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function fire_entity_at_entities(entity_name, entities, speed) | 
					
						
							|  |  |  |     for _, current_entity in ipairs(entities) do | 
					
						
							|  |  |  |         local target = current_entity | 
					
						
							|  |  |  |         if target.health == nil then | 
					
						
							|  |  |  |             target = target.position | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |         current_entity.surface.create_entity{name=entity_name, | 
					
						
							|  |  |  |             position=random_offset_position(current_entity.position, 128), | 
					
						
							|  |  |  |             target=target, speed=speed} | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2024-11-11 11:43:16 +01:00
										 |  |  | end |