Jump to content

[MOD/FIX] Fix disappearing Gates (need a little help)


Avorimon

Recommended Posts

Hope the Mods section is ok for this fix proposal. I haven't written any code yet! I hope there are modders with more experience than me who can answer following questions. Btw i have lots of coding/modding but only moderate lua skills.

 

First about the bug: For an unknown reason some players had gates disappear from random sectors. It just happened twice to me and i looked through the avorion scripts for the first time to see if an easy fix might be possible. Obviously, i won't be able to fix the original bug but my goal is only to restore the missing gates which shouldn't be too hard.

 

I've isolated the code in 'SectorGenerator.lua' to create gates and luckily it is easy to understand and replicate. Only things i need to know are:

 

Where can i find the list of entities in a given sector? I need to loop through'em and see if a gate is missing (i already know how to acces the list of connected target sectors to check against)

 

How can i trigger my script every time the player enters a sector? (is there an event?)

 

Do i have to consider anything else so that it will be compatible with other mods and multiplayer mode? (for example not changing files that are frequently used by mods)

 

 

 

Shout out to all the modders working hard in their spare-time to raise the quality of this exceptional game without getting paid a cent. You guys are doing a great job, much appreciated!!

Link to comment
Share on other sites

Where can i find the list of entities in a given sector?

Documentation/Sector [server].html

There are different functions, but I think the best way to do this will be using following code (on the server side):

local wormholes = {Sector():getEntitiesByType(EntityType.WormHole)}

This code will result in a table of wormhole entities in current sector, though I didn't looked how to detect if it's a just wormhole or a gate (which is actually a wormhole too, but you can see the difference).

 

 

How can i trigger my script every time the player enters a sector?

There is "onPlayerEntered" in Documentation/Sector Callbacks.html

"onSectorEntered" in Documentation/Player Callbacks.html

Use

registerCallback(string callbackName, string functionName)

to attach your function to the event.

But if gates are missing only when sector is reloading, you can just add your code to the "DefaultSector.initialize" function (which is in "data/scripts/sector/sector.lua"). This way it will be called only when server is loading Sector in memory, not when each player re-enters a sector.

 

 

Do i have to consider anything else so that it will be compatible with other mods and multiplayer mode?

There are some mod folder style that was developed by a modding community to help make mods more compatible with each other. But I suggest you to just write your code as it is, any way that is comfortable for you. Later on, as you will make everything work, you can start to optimize things and make mod structure "right".

Link to comment
Share on other sites

Thanks a lot!

 

Didn't know about the Documentation folder  ;)

 

I put my code in the DefaultSector.Initialize() function but nothing changed in the game. Then i tried print() and printlog() from inside the function but saw nothing in-game or in the log file.

 

Now i'm not sure if it runs my code at all or if my code changes are even recognized. I restarted avarion each time and saved the lua file before that. It's only server-side and i'm running a single player game but that shouldn't make a difference, right?

Link to comment
Share on other sites

I put my code in the DefaultSector.Initialize() function but nothing changed in the game. Then i tried print() and printlog() from inside the function but saw nothing in-game or in the log file.
While in-game, did you press the quote key (displaying the ' and " characters) to bring up the console? Print messages are printed into the console, not into Chat.
Link to comment
Share on other sites

:L

 

I remember I had an epiphany when I first saw that Console window pop up. I hit the key by accident actually. I think I've seen others suggest pressing ~, but that definitely didn't work for me.

 

I just checked. You can check and change the key binding to show the Console in the Settings menu.

[*]Launch Avorion

[*]Click Settings

[*]Controls

[*]Key Bindings

[*]It's under "Show Console", around 2/3rds down the list

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...