events.on_robot_built_entity

Looking for a mod? Have a review on a mod you'd like to share?
Post Reply
User avatar
darius456
Fast Inserter
Fast Inserter
Posts: 222
Joined: Thu Jan 02, 2014 6:33 am
Contact:

events.on_robot_built_entity

Post 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.
Lenovo Y580 8GB Ram GF660m 128GB SSD W7

betrok
Fast Inserter
Fast Inserter
Posts: 101
Joined: Wed Feb 28, 2018 12:08 pm
Contact:

Re: events.on_robot_built_entity

Post 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

User avatar
darius456
Fast Inserter
Fast Inserter
Posts: 222
Joined: Thu Jan 02, 2014 6:33 am
Contact:

Re: events.on_robot_built_entity

Post 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.
Lenovo Y580 8GB Ram GF660m 128GB SSD W7

Post Reply

Return to “Questions, reviews and ratings”