Oxeye Game Studio Forum

News, Discussions, Support
It is currently 29 Jul 2014, 23:53

All times are UTC [ DST ]




Post new topic Reply to topic  [ 20 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: How To Create Mods
PostPosted: 12 Apr 2008, 23:28 
Offline
Site Admin

Joined: 21 Apr 2007, 14:17
Posts: 524
Updated: 2008-06-18

Step 1 - Create a Harvest mod description file
From Harvest version 1.10 and later, there's a new "mods" folder in your Harvest client data folder. This is located in ~/Library/Application Support/Harvest on Mac, and in the installation folder on Windows. The description file should be placed in this "mods" folder and have the extension ".hmd".

The description file currently has one block called "mod" and two values, the name of the mod (displayed in the game) and the mod's folder. For example:
Code:
mod
{
   name = jeb's Awesome Mod;
   folder = jebawesome;
   author = jeb;
}

Please note that this is not lua code, so the semi-colons are required.

Step 2 - Create your main.lua file
When a player selects to load your mod in the game, the game will attempt to open a file called "main.lua" in the folder you have named in your description file (a sub-folder to "mods", such as "harvestClientData/sandbox/jebawesome"). This is a simple text document containing your lua code. It will be executed as soon as the game starts, either from the menu or through loading a saved game that has been saved with your mod activated.

For example, if you want to start the game with lots and lots of credits, you simply create a main.lua with the following line:
Code:
harvest.addCredits(100000)


Step 3 - Creating an update function
Most of the time you want your mod to be updated every frame loop. You do this by adding a "hook" on the game. Hooks are identified by a hook name, in this case "frameUpdate", and are added by calling hook.add(hookName, function). Here's a really simple example:
Code:
local function myTestFunction(updateTime)
end
hook.add("frameUpdate", myTestFunction)


Let's say you want the player to receive credits every 10 seconds. You will then have to keep a counter in your mod, which you place "outside" of the functions, like this:
Code:
local myCounter = 0
local function myTestFunction(updateTime)
   myCounter = myCounter + updateTime
   if myCounter >= 10 then
      myCounter = myCounter - 10
      harvest.addCredits(5)
   end
end
hook.add("frameUpdate", myTestFunction)


Check the other threads for a list of possible hooks and functions that you can call.

Step 4 - Adding support for save and load
A proper mod will need to store its game variables when the game is saved, and then restore them again when it's loaded. This is managed through hooking "gameSave" and "gameLoad". Here's an example that shows how to save the 'myCounter' variable:
Code:
local function mySaveFunction(variables)
   -- insert my variables with some kind of unique name
   variables.jebawesome = { c = myCounter }
end
hook.add("gameSave", mySaveFunction)

local function myLoadFunction(variables)
   if variables.jebawesome then
      myCounter = variables.jebawesome.c
   end
end
hook.add("gameLoad", myLoadFunction)

However, this way of saving is quite simplistic and only supports simple arrays of variables. If you have longer arrays or matrices, I recommend you serialize your tables first. Harvest includes chillcode's table serialization on startup, which you can use like this:
Code:
local function mySaveFunction(variables)
   variables.jebawesome = table.save(myTable)
end
hook.add("gameSave", mySaveFunction)

local function myLoadFunction(variables)
   if variables.jebawesome then
      myTable = table.load(variables.jebawesome)
   end
end
hook.add("gameLoad", myLoadFunction)


Step 5 - Publishing your mod
When you're pleased with your mod you should also create a mod icon for it. This is optional, of course, but will make your mod look a lot cooler in the mod list!

The mod icon is a 32x32 TGA file with alpha channel (32 bits) that should be placed in your mod folder. The filename must be "favicon.tga" (case sensitive). If the game finds it you will see it in the mod list when you start a Creative Mode game.

The last step is to zip your mod so that others may use it. Simply use your favourite zip tool to create a package with your .hmd file and the mod's folder. To verify that your mod was zipped correctly, leave the zip file in your mods folder and check the mods list ingame. Your mod should now show up twice (first your .hmd file and then the same version in the zip).


 
 Profile  
 
 Post subject: Re: How To Create Mods
PostPosted: 12 Apr 2008, 23:32 
I guess the release is soon? Laughing


 
  
 
 Post subject: Re: How To Create Mods
PostPosted: 13 Apr 2008, 11:34 
Offline

Joined: 07 Mar 2008, 15:37
Posts: 33
We can only hope...Smile

_________________
Clean...Simple...Devious...I like it


 
 Profile  
 
 Post subject: Re: How To Create Mods
PostPosted: 13 Apr 2008, 13:48 
Offline

Joined: 24 Feb 2008, 23:31
Posts: 409
Location: Netherlands
we can already make them XD but only the testing wil have to wait

_________________
Dear Lord, please save us from your followers.


 
 Profile  
 
 Post subject: Re: How To Create Mods
PostPosted: 14 Apr 2008, 12:21 
Offline

Joined: 07 Mar 2008, 15:37
Posts: 33
Well, sure, we can write scripts already, but they will have to be revalidated anyways, since the Oxeye guys may reimplement certain function or hooks or something, so it's better to simply wait for a stable version.

_________________
Clean...Simple...Devious...I like it


 
 Profile  
 
 Post subject: Re: How To Create Mods
PostPosted: 28 Apr 2008, 21:46 
Offline
Site Admin

Joined: 21 Apr 2007, 14:17
Posts: 524
Updated with some changes... the mods folder is now it's own "mods" instead of sharing "sandbox".


 
 Profile  
 
 Post subject: Re: How To Create Mods
PostPosted: 04 May 2008, 13:00 
Offline

Joined: 24 Feb 2008, 23:31
Posts: 409
Location: Netherlands
another question, how much of the mods can we copy into our own, everything as long as we give credit to the person who made the parts that we copied?

_________________
Dear Lord, please save us from your followers.


 
 Profile  
 
 Post subject: Re: How To Create Mods
PostPosted: 04 May 2008, 17:26 
Offline
Site Admin

Joined: 21 Apr 2007, 14:17
Posts: 524
Feone wrote:
another question, how much of the mods can we copy into our own, everything as long as we give credit to the person who made the parts that we copied?


Good question, I guess you should give credit where credit is due. You can copy anything you like from my mods, at least.


 
 Profile  
 
 Post subject: Re: How To Create Mods
PostPosted: 04 May 2008, 18:09 
Offline

Joined: 24 Feb 2008, 23:31
Posts: 409
Location: Netherlands
good cause i took the starhawk and normal mode (with credits given to Oxeye) Smile

_________________
Dear Lord, please save us from your followers.


 
 Profile  
 
 Post subject: Re: How To Create Mods
PostPosted: 04 May 2008, 18:14 
Offline

Joined: 11 Dec 2007, 21:12
Posts: 47
jeb wrote:
Feone wrote:
another question, how much of the mods can we copy into our own, everything as long as we give credit to the person who made the parts that we copied?


Good question, I guess you should give credit where credit is due. You can copy anything you like from my mods, at least.

Yeah, Lua is open source and released under the GNU General Public License (GPL). So I guess it's the same for scripts unless other specified.


 
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 20 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2002, 2006 phpBB Group
[ Time : 0.044s | 16 Queries | GZIP : Off ]