Recovering my character ?

Place to get help with not working mods / modding interface.
User avatar
binbinhfr
Smart Inserter
Smart Inserter
Posts: 1525
Joined: Sat Feb 27, 2016 7:37 pm
Contact:

Recovering my character ?

Post by binbinhfr »

As I'm playing with mod and god mode, I sometimes have problem to switch back to human. In general, I record my player.character into a variable before going into god, but, for example, if I forgot to go back into human before saving, I save in god mode, and when I came back later, reloading the file, I lost my character variable...

So my question : is there a way to retrieve a character connected to a player and probably stored in the map file ?

EDIT : I suppose that I should look for an entity named "player". But I wonder in multiplayer, what would be the name of these character entities... And I don't know how to browse entities... :-)
My mods on the Factorio Mod Portal :geek:
User avatar
binbinhfr
Smart Inserter
Smart Inserter
Posts: 1525
Joined: Sat Feb 27, 2016 7:37 pm
Contact:

Re: Recovering my character ?

Post by binbinhfr »

Well, after a few headaches, I found that this should do the trick in single player mode :

Code: Select all

function find_lost_character()
	surf = game.get_surface(1)
	for ch in surf.get_chunks() do
		a = {{ch.x * 32, ch.y * 32}, {ch.x * 32 + 32, ch.y * 32 + 32}}
		for k, entity in pairs(surf.find_entities_filtered({area=a, name= "player"})) do
			return entity
		end
	end
end
But I wonder what name to search in multiplayer mode... But is there a god mode in multiplayer ?
My mods on the Factorio Mod Portal :geek:
Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

Re: Recovering my character ?

Post by Choumiko »

binbinhfr wrote:So my question : is there a way to retrieve a character connected to a player and probably stored in the map file ?
You are looking for global : https://wiki.factorio.com/index.php?tit ... _Lifecycle

everything you add to global is stored in the save file, each mod has it's own global. I suggest indexing the table by player_index
Rotn240
Manual Inserter
Manual Inserter
Posts: 1
Joined: Mon Aug 14, 2017 10:27 am
Contact:

Re: Recovering my character ?

Post by Rotn240 »

binbinhfr wrote:Well, after a few headaches, I found that this should do the trick in single player mode :

Code: Select all

function find_lost_character()
	surf = game.get_surface(1)
	for ch in surf.get_chunks() do
		a = {{ch.x * 32, ch.y * 32}, {ch.x * 32 + 32, ch.y * 32 + 32}}
		for k, entity in pairs(surf.find_entities_filtered({area=a, name= "player"})) do
			return entity
		end
	end
end
But I wonder what name to search in multiplayer mode... But is there a god mode in multiplayer ?
Hello i wunder how i can use this code? do i use it ingame or what? i could not find any infoation about how to use this on google so i trying to contact you insteed then

Yes i know the post is old but if i could get a answer it's worth it in my opinion
Post Reply

Return to “Modding help”