Page 1 of 1

Run script.on_event from my mod after all other mods

Posted: Tue May 12, 2020 6:10 pm
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.

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

Posted: Tue May 12, 2020 6:45 pm
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.

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

Posted: Tue May 12, 2020 7:21 pm
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.

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

Posted: Tue May 19, 2020 11:36 pm
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?

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

Posted: Wed May 20, 2020 4:44 am
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.

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

Posted: Wed May 20, 2020 3:23 pm
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".

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

Posted: Wed May 20, 2020 3:54 pm
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.

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

Posted: Thu May 21, 2020 11:03 pm
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.