Page 1 of 1

events.on_robot_built_entity

Posted: Sat May 05, 2018 8:19 pm
by darius456
Hi everydody,

I have simple question that i cant find answer.
When on_robot_built_entity event occur, there is a table named event that contains: robot, created_entity and stack, unfortunately no player_index.

How can i determine which player is owner of this robot? or How can i determine which player is owner of created_entity?

Thank you for answer.

Re: events.on_robot_built_entity

Posted: Sat May 05, 2018 11:26 pm
by betrok
Do you really need an accurate player? Why not to use force-wide logic?
Anyway something like this could work(untested):

Code: Select all

function robot_owner(robot)
	local cells = robot.logistic_network.cells
	if #cells ~= 1 then
		return nil
	end
	if not cells[1].mobile then
		return nil
	end
	local owner = cells[1].owner
	if owner.type ~= "character" then
		return nil
	end	
	return cells[1].owner.associated_player
end

Re: events.on_robot_built_entity

Posted: Sun May 06, 2018 2:59 pm
by darius456
betrok wrote:Do you really need an accurate player? Why not to use force-wide logic?
Anyway something like this could work(untested):

Code: Select all

function robot_owner(robot)
	local cells = robot.logistic_network.cells
	if #cells ~= 1 then
		return nil
	end
	if not cells[1].mobile then
		return nil
	end
	local owner = cells[1].owner
	if owner.type ~= "character" then
		return nil
	end	
	return cells[1].owner.associated_player
end
Thx for answer, but your function allways return nil. But this give me a clue. Im checking event.created_entity.owner.name and that works.