Run script.on_event from my mod after all other mods

Place to get help with not working mods / modding interface.
User avatar
<NO_NAME>
Filter Inserter
Filter Inserter
Posts: 295
Joined: Tue Aug 02, 2016 9:52 am
Contact:

Run script.on_event from my mod after all other mods

Post by <NO_NAME> »

I've created a very simple mod that removes all items that are given to a player on respawn.
control.lua
The problem is that other mod are using the same event ("defines.events.on_player_respawned") to give more items to a player so if one of these mods happens to load after mine, it is unaffected by my code.

I would like to load my mod or add this event after all other mods.
The only way I know to achieve this is to add all other mods that use this event to dependencies in my "info.json" but this is not a viable solution. There is to many of them and I don't intend to constantly maintain the list.
I am a translator. And what did you do for Factorio?
Check out my mod "Realistic Ores" and my other mods!
User avatar
steinio
Smart Inserter
Smart Inserter
Posts: 2638
Joined: Sat Mar 12, 2016 4:19 pm
Contact:

Re: Run script.on_event from my mod after all other mods

Post by steinio »

If you like it dirty just call your mod zzz_[modname].
The zzz loads it at a very least position. No garanty to be the last one but worth the try.
Image

Transport Belt Repair Man

View unread Posts
User avatar
<NO_NAME>
Filter Inserter
Filter Inserter
Posts: 295
Joined: Tue Aug 02, 2016 9:52 am
Contact:

Re: Run script.on_event from my mod after all other mods

Post by <NO_NAME> »

steinio wrote: Tue May 12, 2020 6:45 pm If you like it dirty just call your mod zzz_[modname].
The zzz loads it at a very least position. No garanty to be the last one but worth the try.
According to this topic my mod would still load near the beginning because it has no dependencies.
I am a translator. And what did you do for Factorio?
Check out my mod "Realistic Ores" and my other mods!
User avatar
<NO_NAME>
Filter Inserter
Filter Inserter
Posts: 295
Joined: Tue Aug 02, 2016 9:52 am
Contact:

Re: Run script.on_event from my mod after all other mods

Post by <NO_NAME> »

It seems like there is currently no good way to do that.
Could some mod move this topic to modding interface requests?
I am a translator. And what did you do for Factorio?
Check out my mod "Realistic Ores" and my other mods!
Rseding91
Factorio Staff
Factorio Staff
Posts: 14319
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Run script.on_event from my mod after all other mods

Post by Rseding91 »

"run after all other mods" doesn't work because as soon as 2 mods want to do that, you're right back where you are now.

You have to add dependencies on any mod you want to run after. Also that post you linked is from 2015 and is just wrong. Dependencies then name are how mods are ordered.
If you want to get ahold of me I'm almost always on Discord.
User avatar
<NO_NAME>
Filter Inserter
Filter Inserter
Posts: 295
Joined: Tue Aug 02, 2016 9:52 am
Contact:

Re: Run script.on_event from my mod after all other mods

Post by <NO_NAME> »

Well, of course "run after all other mods" won't do that if there are more mods which request it.
What about we call it "put it after all mods which didn't specify this option unless some dependency specify otherwise" instead.

Although, I don't think we have to go as far as creating ways to change order of mods. It would be enough to add "control-final-fixes.lua".
I am a translator. And what did you do for Factorio?
Check out my mod "Realistic Ores" and my other mods!
User avatar
raiguard
Factorio Staff
Factorio Staff
Posts: 579
Joined: Wed Dec 13, 2017 8:29 pm
Contact:

Re: Run script.on_event from my mod after all other mods

Post by raiguard »

Alternative idea, kind of terrifying: when the player respawns, set a flag in global stating that that player needs its items cleared. Then, in an on_tick handler, clear the items for any players with that flag set. That will delegate the clearing to the next tick, guaranteeing that it will run last. Assuming that the other mods aren't doing this already.

You'll definitely want to conditionally register the on_tick handler so your mod isn't constantly taking update time that you don't need.
Don't forget, you're here forever.
User avatar
<NO_NAME>
Filter Inserter
Filter Inserter
Posts: 295
Joined: Tue Aug 02, 2016 9:52 am
Contact:

Re: Run script.on_event from my mod after all other mods

Post by <NO_NAME> »

@Raiguard It would probably work but it would increase amount of code an order of magnitude. (Multiplayer and keeping track of things like: which player to clear, is the event already registered, is the event ready to be unregistered.)
Beside I can imagine that this would do a number on any mod that tries to keep track of the inventory.
Let's leave this the plan D.
I am a translator. And what did you do for Factorio?
Check out my mod "Realistic Ores" and my other mods!
Post Reply

Return to “Modding help”