Modifying selection/collision boxes via control.lua

Place to get help with not working mods / modding interface.
Liquius
Long Handed Inserter
Long Handed Inserter
Posts: 64
Joined: Tue Nov 04, 2014 12:01 pm
Contact:

Modifying selection/collision boxes via control.lua

Post by Liquius »

I am trying to create a building where you get to choose its dimensions, however to do that you need to be able to modify selection/collision boxes.

When trying to modify the selection box I get this message "Lua doesn't contain property - selection_box".

Any idea what I am doing wrong, or if it's even possible in the first place?

Heres my code.

Code: Select all

require "defines"


game.onevent(defines.events.onbuiltentity, function(event)
	if event.createdentity.name == "nuclear-fission-reactor" then 
		localFissionReactorMarkers = game.findentitiesfiltered({area = {{x = event.createdentity.position.x -10, y = event.createdentity.position.y -10}, {x = event.createdentity.position.x + 10, y = event.createdentity.position.y + 10}}, name = "fission-reactor-marker"})
		
		local xCoordinates = {}
		local yCoordinates = {}
		local x = 1
		local y = 1

		for i,v in ipairs(localFissionReactorMarkers) do
			x = localFissionReactorMarkers[i].position.x
				if x < math.huge then table.insert(xCoordinates, x)
			end
			y = localFissionReactorMarkers[i].position.y
				if y < math.huge then table.insert(yCoordinates, y)
			end
		end

		maxX = math.max(unpack(xCoordinates))
		maxY = math.max(unpack(yCoordinates))
		minX = math.min(unpack(xCoordinates))
		minY = math.min(unpack(yCoordinates))
		
		centerX = event.createdentity.position.x
		centerY = event.createdentity.position.y

		local cornerAX = 0
		local cornerAY = 0
		local cornerBX = 0
		local cornerBY = 0		

		cornerAX = maxX - centerX 
		cornerAY = maxY - centerY
		cornerBX = minX - centerX 
		cornerBY = minY - centerY

		game.player.print(cornerAX)
		game.player.print(cornerAY)
		game.player.print(cornerBX)
		game.player.print(cornerBY)
		
		event.createdentity.selection_box = {{cornerAX, cornerAY}, {cornerBX, cornerBY}}
	end
end)
Edit: After a bit of playing around/reading I realise what I did wrong, and that what I want to do is impossible (at the moment).
User avatar
L0771
Filter Inserter
Filter Inserter
Posts: 516
Joined: Tue Jan 14, 2014 1:51 pm
Contact:

Re: Modifying selection/collision boxes via control.lua

Post by L0771 »

You can make more entities with diferents selection_box.

A example here i changing max_health in the first and fluid_box in the second :p
lol
Post Reply

Return to “Modding help”