Jump to content

[QUESTION] Getting started modding


JayNic

Recommended Posts

Hey all,

 

I'd like to get started on some modding - but I'm having trouble right out of the gate. I've got lua documentation, I've got the api documentation, and I've seen this page on the wiki: http://avorion.gamepedia.com/Modding and http://avorion.gamepedia.com/Entity_scripts

 

Is there a hello world tutorial out there somewhere?

 

I'm attempting to just get a simple chat message to pop up.

 

So far I have:

-- file scripts\entity\jaynic_test.lua

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

-- init function fired after all functions registered
function initialize()
    displayChatMessage("This is a message", "SenderMonkey",3)

end

 

 

and I've added the script to be fired via the "defaultscripts.lua" in scripts\lib

-- file \scripts\lib\defaultscripts.lua
function AddDefaultShipScripts(ship)
    ship:addScriptOnce("data/scripts/entity/startbuilding.lua")
    ship:addScriptOnce("data/scripts/entity/entercraft.lua")
    ship:addScriptOnce("data/scripts/entity/exitcraft.lua")

    ship:addScriptOnce("data/scripts/entity/craftorders.lua")
    ship:addScriptOnce("data/scripts/entity/transfercrewgoods.lua")
    ship:addScriptOnce("data/scripts/entity/collaboration.lua")

ship:addScriptOnce("data/scripts/entity/jaynic_test.lua")
end

function AddDefaultStationScripts(station)
    station:addScriptOnce("data/scripts/entity/startbuilding.lua")
    station:addScriptOnce("data/scripts/entity/entercraft.lua")
    station:addScriptOnce("data/scripts/entity/exitcraft.lua")

    station:addScriptOnce("data/scripts/entity/crewboard.lua")
    station:addScriptOnce("data/scripts/entity/backup.lua")
    station:addScriptOnce("data/scripts/entity/bulletinboard.lua")
    station:addScriptOnce("data/scripts/entity/story/bulletins.lua")

    station:addScriptOnce("data/scripts/entity/craftorders.lua")
    station:addScriptOnce("data/scripts/entity/transfercrewgoods.lua")
    station:addScriptOnce("data/scripts/entity/collaboration.lua")
end

 

 

But no message is popping up. Any help would be great

 

On a related note: can I reccomend a sub forum for "modding help" - maybe even separate mod releases / requests? Just a thought

 

Link to comment
Share on other sites

oh... also... How do I use the "/run" command in game?

 

say I wanted to run this script - would it be:

 

/run "entity/jaynic_test.lua"

or

/run "scripts/entity/jaynic_test.lua"

 

do I need quotes? What's the path etc...

 

Thanks..

Link to comment
Share on other sites

From /run help:

This command runs the string following '/run' as a lua script.

 

So basically you can get it script running like this:

/run for _,s in pairs({"a", "b", "c"}) do print(s) end

This will print in console:

a

b

c

Link to comment
Share on other sites

oooh I see... I thought I could execute a script. Thanks

Actually. You can! With built-in Lua functions (loadfile, dofile). For instance:

 

<avorion>/data/scripts/test.lua:

return 1

 

In chat:

/run loadfile("data/scripts/test.lua")()

 

Prints in console:

4

 

 

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...