Author Topic: [mod] Ship Script Loader (A small mod to auto load scripts onto a players ship)  (Read 17401 times)

Dirtyredz

  • Full Member
  • ***
  • Status:
    Offline
    Posts:
    225
  • David McClain - Dirtyredz
    • View Profile
    • Dirtyredz.com
ShipScriptLoader

A small mod designed to automatically load a script onto the players ship, regardless of if they change ships or not.
The script will always be loaded.

This mod will be extremly usefull to other modders and server owners.

INSTALLATION


Step 1.
Unzip the zip file and drag/drop the contents into the avorion directory.

Step 2.
Navigate to:
   
Quote
data/scripts/server/server.lua

and place these 2 lines of code at the bottom of the file:

   
Code: [Select]
    local s, b = pcall(require, 'mods/ShipScriptLoader/scripts/server/server')
    if s then if b.onPlayerLogIn then local a = onPlayerLogIn; onPlayerLogIn = function(c) a(c); b.onPlayerLogIn(c); end end end
   

Step 3.
Navigate to:
   
Quote
mods/ShipScriptLoader/config/ShipScriptLoader.lua

and add the script path of the script you want to autoload using the Config.Add() function

DOWNLOAD

ShipScriptLoader v1.1.0

ShipScriptLoader v1.0.0


GITHUB

https://github.com/dirtyredz/ShipScriptLoader


DONATE

Wanna show your appreciation?
http://dirtyredz.com/donate

Become a patron:
https://www.patreon.com/Dirtyredz

MY OTHER MODS

Spoiler: show

DSM
-A project dedicated to server deployment, management, and exposing features to a web interface.
http://www.avorion.net/forum/index.php/topic,3507.0.html

Reganerative Asteroid Fields
-Regenerates designated sectors, and randomly appearing sectors, of minable asteroids.
http://www.avorion.net/forum/index.php/topic,3055.0.html

MoveUI
-A mod for adding custom UIs to the screen.
http://www.avorion.net/forum/index.php/topic,3834.0.html

Subspace Corridor
-A modders recources, designed to mimick /teleport, due to server commands not being available through the api.
http://www.avorion.net/forum/index.php/topic,3148.0.html

Dirty Buoy's
-Allows players to spawn Navigational and Sentry Buoys, More to come soon.
-These buoys have unique features players cant get in normal game play, for example: Navigational buoys are invincible and cannot be moved. A great way to mark a distance wreckage or minarable rich asteroid field.
--Rusty Servers only at the moment.

LogLevels
-LogLevels gives modders the ability to set levels for there print functions.
-Aswell as allowing server owners to clean up there consoles, making it easier to read.
http://www.avorion.net/forum/index.php/topic,3799.0.html

NoNeutralCore
-A small script for stopping the creation of neutral zones inside the core.
http://www.avorion.net/forum/index.php/topic,3472.0.html

DirtyCargoExtender
-Extends the cargo hold of any NPC station discovered with low cargo holds.
--Patreon Members only

DirtySecure
-A mod which assigned PVP or PVE sectors based on distance from core.
-Provides Offline Protection to Players ships.
-Provides protection for NPC stations.
--Rusty Servers only at the moment

Reganerative Claimable Asteroids
-A mod which respawns claimable asteroids, when theyve been moved or turned into a mine.
-Also will unclaim or unsell an asteroid after a configured number of days
-Keeps the galaxy alive, providing claimable asteroids for new players.
--Rusty Servers only at the moment

Death Info
-Used to track cords of a players death point, assigning player values, for other mods to use.
--Rusty Servers only at the moment.

/Back
-A command using DeathInfo and Subspace Corridor, to teleport a players drone BACK to there death point.
--Rusty Servers only at the moment.

DistCore HUD
-Displays distance to the core on the players hud
--Rusty Servers only at the moment.

Any mod listed as Rusty Servers only, are live and active on the Rusty Servers.
Want the mod for your server? Lets talk and ill see about releasing the mod to you/public.
Not all mods on Rusty will remain there, they will eventually be released to the public.

« Last Edit: November 25, 2017, 03:28:15 AM by Dirtyredz »
David McClain - Dirtyredz
Programmer, Web Development, Modder
http://www.Dirtyredz.com




Shrooblord

  • Hero Member
  • *****
  • Status:
    Offline
    Posts:
    578
    • View Profile
Sounds interesting, but could you give an example as to how this would be applied? What kind of script would I want to always auto-load onto the player ship?
Shrooblord



cyrusblaze

  • Newbie
  • *
  • Status:
    Offline
    Posts:
    4
    • View Profile
I would imagine a mod like Carrier commands could benefit from this as you currently have to exit/enter the ship for commands to appear and this seems to correct that issue :)



Dirtyredz

  • Full Member
  • ***
  • Status:
    Offline
    Posts:
    225
  • David McClain - Dirtyredz
    • View Profile
    • Dirtyredz.com
I would imagine a mod like Carrier commands could benefit from this as you currently have to exit/enter the ship for commands to appear and this seems to correct that issue :)

Exactly what those mod is best at,  any mod that has a menu/interface has to be attsched to the players ship. For example carrier commands, sector overview to name a few.

That is why this mod is primarily a modders resource.
David McClain - Dirtyredz
Programmer, Web Development, Modder
http://www.Dirtyredz.com




Shrooblord

  • Hero Member
  • *****
  • Status:
    Offline
    Posts:
    578
    • View Profile
Cool. I was mostly asking because I'm also looking into modding for in the near future and I was wondering if this is something I need to keep in mind for one of my planned projects. I'll keep tabs on it, for sure. Sounds useful.
Shrooblord



Dirtyredz

  • Full Member
  • ***
  • Status:
    Offline
    Posts:
    225
  • David McClain - Dirtyredz
    • View Profile
    • Dirtyredz.com
David McClain - Dirtyredz
Programmer, Web Development, Modder
http://www.Dirtyredz.com




heyfunny

  • Newbie
  • *
  • Status:
    Offline
    Posts:
    11
    • View Profile
I can't seem to get This or CarrierCommander to work in game is there some incompatibility with the current version? Is there some debug way of checking in game to see if the script loader itself is working? Just trying to troubleshoot from the starting point...  Also is there any other scripts besides CarrierCommander that work with your loader? I just wish the game had some way to show you what it loaded kinda like Minecraft for example with mods....

My Server.lua looks like this

"package.path = package.path .. ";data/scripts/lib/?.lua"
package.path = package.path .. ";data/scripts/server/?.lua"
require ("factions")
require ("stringutility")

function onStartUp()
    Server():registerCallback("onPlayerLogIn", "onPlayerLogIn")
    Server():registerCallback("onPlayerLogOff", "onPlayerLogOff")
    Galaxy():registerCallback("onPlayerCreated", "onPlayerCreated")
    Galaxy():registerCallback("onFactionCreated", "onFactionCreated")
end

function onShutDown()

end

function update(timeStep)
    local server = Server()

    local guardianRespawnTime = server:getValue("guardian_respawn_time")
    if guardianRespawnTime then

        guardianRespawnTime = guardianRespawnTime - timeStep;
        if guardianRespawnTime < 0 then
            guardianRespawnTime = nil
        end

        server:setValue("guardian_respawn_time", guardianRespawnTime)
    end

    local serverRuntime = server:getValue("online_time") or 0
    serverRuntime = serverRuntime + timeStep
    server:setValue("online_time", serverRuntime)

end

function onPlayerCreated(index)
    local player = Player(index)
    Server():broadcastChatMessage("Server", 0, "Player %s created!"%_t, player.name)
end

function onFactionCreated(index)

end

function onPlayerLogIn(playerIndex)
    local player = Player(playerIndex)
    Server():broadcastChatMessage("Server", 0, "Player %s joined the galaxy"%_t, player.name)

    player:addScriptOnce("headhunter.lua")
    player:addScriptOnce("eventscheduler.lua")
    player:addScriptOnce("story/spawnswoks.lua")
    player:addScriptOnce("story/spawnai.lua")
    player:addScriptOnce("story/spawnguardian.lua")
    player:addScriptOnce("story/spawnadventurer.lua")

    matchResources(player)
end

function onPlayerLogOff(playerIndex)
    local player = Player(playerIndex)
    Server():broadcastChatMessage("Server", 0, "Player %s left the galaxy"%_t, player.name)

end
 
local s, b = pcall(require, 'mods/ShipScriptLoader/scripts/server/server') if s then if b.onPlayerLogIn then local a = onPlayerLogIn; onPlayerLogIn = function(c) a(c); b.onPlayerLogIn(c); end end end"

My mods folder has 3 things in it
CarrierCommander
mos
ShipScriptLoader
and it is in the base Avorion Folder

and my ShipScriptLoader.lua from your config folder looks like this

"local Config = {}
Config.author = 'Dirtyredz'
Config.name = 'Ship Script Loader'
Config.homepage = "https://github.com/dirtyredz/AvorionBoilerPlate"
Config.version = {
    major=1, minor=1, patch = 0,
    string = function()
        return  Config.version.major .. '.' ..
                Config.version.minor .. '.' ..
                Config.version.patch
    end
}

Config.Scripts = {}

function Config.Add(scriptPath)
  table.insert(Config.Scripts,scriptPath)
end

-- Example use to add a script to a players ship
-- Config.Add("mods/YourMod/scripts/entity/YourMod.lua")
Config.Add("mods/CarrierCommander/scripts/entity/CarrierCommander.lua")
return Config"

Anyone see my problem?






Shrooblord

  • Hero Member
  • *****
  • Status:
    Offline
    Posts:
    578
    • View Profile
What does your Avorion Steam Installation directory, including Carrier Commander, look like?

It should be like this:
Code: [Select]
(...)/Steam/steamapps/common/Avorion/
|-data
   |-scripts
       |-server
            |-server.lua
|-mods
    |-CarrierCommander
        |-scripts
            |-entity
                |-CarrierCommander.lua
I have only shown the two files you asked about, in their relative file directory structures. Other folders, like Documentation, are not shown here.

If you have it set up like this, it should work.

In-game, you can open the console window by pressing the quote key, the one with the ' and " characters on it. If either of the scripts is throwing an error, it will show in the Console window when you're playing the game.
Shrooblord



heyfunny

  • Newbie
  • *
  • Status:
    Offline
    Posts:
    11
    • View Profile
my Avorion folder has 2 folders

CarrierCommander
ShipScriptLoader

CarrierCommander has config and scripts folders
config has  CarrierCommanderConfig.lua
scripts has 2 folders, entity and lib
lib folder has 1 file lists.lua
entity folder has ai folder and CarrierCommander.lua
ai folder has 7 files all .lua
aggressiveCommand.lua
CarrierCivilCommandMine.lua
CarrierCivilCommandSalvage.lua
CarrierMilitaryCommand.lua
dockAllFighters.lua
mineCommand.lua
salvageCommand.lua

ShipScriptLoader folder has 2 Folders config and scripts + a README.md file
config folder has ShipScriptLoader.lua
scripts folder has 2 folders Player and server
Player folder has ShipScriptLoader.lua
server folder has server.lua

So confused...
I also hit the " button after the game started my game save and it just showed, "player events roughly every 12/02 seconds" and thats it

Steam version of Avorion
I'm on Windows 10 btw if that makes a difference
Also this shows up in the server log

2018-01-20 04-38-00| Loading global variables...
2018-01-20 04-38-00| Setting startup script...
2018-01-20 04-38-00| Error while adding file "data/scripts/server/server.lua":
2018-01-20 04-38-00|
2018-01-20 04-38-00| data/scripts/server/server.lua:67: attempt to index local 'b' (a boolean value)


« Last Edit: January 20, 2018, 05:40:52 PM by heyfunny »



Shrooblord

  • Hero Member
  • *****
  • Status:
    Offline
    Posts:
    578
    • View Profile
2018-01-20 04-38-00| Error while adding file "data/scripts/server/server.lua":
2018-01-20 04-38-00|
2018-01-20 04-38-00| data/scripts/server/server.lua:67: attempt to index local 'b' (a boolean value)
Well, there's your problem. Something is definitely breaking with the server.lua script, specifically in line 67 of that script.

In my server.lua, those lines are the hooks for the MoveUI and Ship Script Loader mods. I'm assuming your server.lua is similar: it's the hook for the Ship Script Loader mod you inserted there yourself. It should read:
Code: [Select]
local s, b = pcall(require, 'mods/ShipScriptLoader/scripts/server/server')
if s then if b.onPlayerLogIn then local a = onPlayerLogIn; onPlayerLogIn = function(c) a(c); b.onPlayerLogIn(c); end end end

And the game is failing to load the mod there. So I'm going to have to ask another time, although it may seem silly, to double-triple check that your Avorion installation looks similar to mine. I've made a short video going through my folder structure:



Ignore the fact that my folders will look slightly different because I have many more mods installed than you probably have. I highlight all the important parts of the folder structure and the server.lua script (which will also look slightly different to yours, because, again, I have more mods altering it than you probably have).

If you can confirm that that's indeed what your installation looks like, try reinstalling the affected server.lua by deleting it and running Steam Integrity Verification, and deleting and reinstalling the mods you've installed. Warning: SIV will delete any other files you may have modified to install mods, and will install vanilla Avorion files in their place. Backup anything you don't want to lose, first.

If that doesn't end up working, please let's continue trying to solve your problem. ;)
Shrooblord



heyfunny

  • Newbie
  • *
  • Status:
    Offline
    Posts:
    11
    • View Profile
I checked all my folders and they were all the same as yours but it wasn't working so I tried what you suggested and deleted a bunch of the game files and verified and re downloaded them then added the lines into the server.lua and your config one and it finally started working ^_^
Thanks for all the help.



Shrooblord

  • Hero Member
  • *****
  • Status:
    Offline
    Posts:
    578
    • View Profile
Good to hear! Sometimes, the "turn it off and on again" approach simply is the easiest, even if it doesn't give you much knowledge about where exactly it went wrong, in order to prevent problems in the future.
Shrooblord



Raio_Verusia

  • Newbie
  • *
  • Status:
    Offline
    Posts:
    11
    • View Profile
First off- Thank you for your service, D.R.

This is correct file structure, yes? The config holds the config lua, and the other folders are correct as well as far as I can tell. Yet this does not work, what-so-ever, at all, period.

What the gosh darn banana am I doing wrong here? It doesn't initialize anything when in game.




Raio_Verusia

  • Newbie
  • *
  • Status:
    Offline
    Posts:
    11
    • View Profile
-Doublepost :( Sorry, it wasn't going through and then suddenly did.



Dirtyredz

  • Full Member
  • ***
  • Status:
    Offline
    Posts:
    225
  • David McClain - Dirtyredz
    • View Profile
    • Dirtyredz.com
from what i can see your file structure looks good,
did you follow the other instructions (im assuming yes)  editing the server.lua is essential as thats what gets the mod started.
secondly this mod does nothing by itself except force Entity scripts (scripts/mods attach to a ship) to follow the ship your piloting.

the mod solves the issue of other modders having to write the same code for each mod and costing the players/server performance hits when 10 mods are all doing the EXACT same thing.

by adding a script path to this mods config file. this mod will track the player entering/leaving of a ship and keep any scripts in the config attached to the players current ship.

What mod are you trying to use with this mod?
can i see your config file?
also showing me the server.lua file you should have edited just to be sure would be helpfull.
David McClain - Dirtyredz
Programmer, Web Development, Modder
http://www.Dirtyredz.com