| 
									
										
										
										
											2021-04-07 01:55:53 +02:00
										 |  |  | function get_any_stack_size(name) | 
					
						
							|  |  |  |     local item = game.item_prototypes[name] | 
					
						
							|  |  |  |     if item ~= nil then | 
					
						
							|  |  |  |         return item.stack_size | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |     item = game.equipment_prototypes[name] | 
					
						
							|  |  |  |     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) | 
					
						
							|  |  |  |     return {x=position.x+math.random(-offset, offset), y=position.y+math.random(-1024, 1024)} | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function fire_entity_at_players(entity_name, speed) | 
					
						
							|  |  |  |     for _, player in ipairs(game.forces["player"].players) do | 
					
						
							|  |  |  |         current_character = player.character | 
					
						
							|  |  |  |         if current_character ~= nil then | 
					
						
							|  |  |  |             current_character.surface.create_entity{name=entity_name, | 
					
						
							|  |  |  |                 position=random_offset_position(current_character.position, 128), | 
					
						
							|  |  |  |                 target=current_character, speed=speed} | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2021-04-07 01:55:53 +02:00
										 |  |  | end |