[Tutorial] Modding 101 - actions

Post your mods and custom content here

[Tutorial] Modding 101 - actions

Postby JackPS9 » Wed Oct 10, 2012 9:41 pm

Okay guys, I'm sure some of you have noticed but there are little to no tutorials on modding "Towns".
And hoping instead of everyone asking a ton of questions they will be able to just look in here and find the info they need.
Anything to do with map gen files I will have to leave to someone else to fill in the info cause I really don't understand that stuff.

Actions.xml
But being probably the most edited file in the whole game being the actions.xml file thought it would be a nice place to start.
So we are just going to make our own little action.

Any action you code into towns will be inside 2 sets of these tags.
Code: Select all
<actions>
</actions>

The first set is to tell "Towns" that everything inside the file is a action.
The second set are the actions the Townies will perform, such as chopping a tree or harvesting wheat.

So now lets begin, at the bottom of the actions.xml file just above the last line
Code: Select all
</action>

Put in
Code: Select all
<action>
</action>

Within those will be our action to create a wooden chair. Now don't ask why a chair, but you will be making a chair for this tutorial.

Without your action tags we will need a ID for this action.
A ID of a action is the name of the action sorta.
So for the ID you can put anything you want really, but to keep it all simple right now we will call it "qchair0"
Where you place the ID is between ID tags
Code: Select all
<id>ID</id>


Now for the name the player (You) will see in game while playing. Yes the ID is not the name you will see in game but what the game reads to find out how to perform a action.
So once again being simple "Chair" will do. The tags for a name are simple enough.
Code: Select all
<name esES="">Name</chair>

Now some may look and see this
esES=""
what goes in those quotes are the spanish word for the name.
For Chop it is Talar.
As for chair I have no idea, but I'm sure someone will tell me.

So here is what the action should look like so far.
Code: Select all
   <action>
      <id>qchair0</id>
      <name esES="Chair">Chair</name>
   </action>


Now cause we are making a placed item we wont need this tag but I'll tell you how it is used anyways.
Code: Select all
<generatedItem>Item ID</generatedItem>

Now if your item being created out of thin air. Alot of the time this tag is not needed. Morely fore actions like chopping down a tree, and stuff like that. (I could be wrong but I haven't had to use this tag that much)

The next tag basicly says how important the item is make.
Code: Select all
<priorityID></priorityID>

There are 8 priorities in "Towns" unless modded.
Those priorities are
foodmaking = anything baking or cooking related
gatheringharvesting = Anything like gathering and harvesting crops
_MINEDIG_ = Mining and Digging
terrainchange = Tilling ground or chopping trees
itemconstruction = the creation of items (most stuff falls under this)
wallconstruction = the creation of walls
butcheringkilling = butchering animals for meat or bones
_HAUL_ = hauling items to a container or a stockpile

We are creating a item so our priority ID is itemconstruction which will go between our priority tags

Now to get to the fun part of the actions. How they are made.
Everything from here on will be wrapped in these tags here
Code: Select all
<queue>
</queue>


So first we need our townies to pick up some wood to start the crafting process.
Any items that are needed go in these tags here.
Code: Select all
<pick></pick>


now the item ID for wood is rmwood rm = raw material.
and in order to craft the chair he is going to need a place to craft it so we are going to need the move tag
Code: Select all
<move></move>

so we will need to put carpentrybench between the move tags.

I haven't fully figured out this next part on how the timing works.
So how long does it take to craft our chair?
Well we get to edit the length ourselves in the wait tags
Code: Select all
<wait></wait>

I would put it around 20

Before we can either make the item take more resources and time we have to destroy the item the townie is holding. The tag is easy enough to use, no ID or anything just one tag.
Code: Select all
<destroyItem />


This will destroy the wood the townie is holding and allow me to continue on without the wood.
You can repeat the process of Pick/Move/Wait/Destroy as many times as you wish. When you are finally happy with the action it is time to create the chair!
Code: Select all
<createItem></createItem>

Whatever item is put in those tags will be placed in the townies hands for them to place in the location the player wanted it placed, or the townie will just toss the item on the ground till its hauling priority comes up.

So here is what your action should look like
Code: Select all
   <action>
      <id>qchair0</id>
      <name esES="Chair">Chair</name>
      
      <priorityID>terrainchangeAuto</priorityID>
      <queue>
         <pick>rmwood</pick>
         <move>carpentrybench</move>
         <wait>20</wait>
         <destroyItem />
         <createItem>woodenchair</createItem>
      </queue>
   </action>



Okay sad part is, that we aren't done yet cause you still need to be able to access that action in game.
So now we are going to need the menu_right.xml file for this part

Just to get this to work quickly we are going to put this in the first window of the right menu.
Code: Select all
      <item code="QUEUEANDPLACE" parameter="qcarpentrybench" />

The chair is a item that has a placement selected by the player hence the
Code: Select all
code="QUEUEANDPLACE"


Now where it says
Code: Select all
parameter="qcarpentrybench"

we need to change that parameter to our action ID which is qchair0

so the top of the menu_right.xml file should end up looking something like this.
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>

<menu>
      <item code="QUEUEANDPLACE" parameter="qchair0" />


Now you just have to save both files and load up towns.
NO graphic changes or no graphic needed cause we used a already coded in item for this tutorial.

Once in game you should be able to open the right menu and your wood chair should be at the top left corner of the menu.

Hope you enjoyed this small tutorial on actions.
If I get the chance I will make a second one on some of the tags I skipped in this one to keep this tutorial simple.
Last edited by JackPS9 on Fri Oct 12, 2012 12:35 pm, edited 1 time in total.
JackPS9
 
Posts: 1088
Joined: Mon Sep 03, 2012 4:15 pm

Re: Modding 101 - actions

Postby 8BitHazey » Wed Oct 10, 2012 10:46 pm

Jack, don't forget to jam this up onto the wiki.

http://www.townswiki.com/wiki/Main_Page
User avatar
8BitHazey
 
Posts: 61
Joined: Mon Oct 08, 2012 10:00 am
Location: Keeping it Dapper somewhere.

Re: Modding 101 - actions

Postby JackPS9 » Wed Oct 10, 2012 10:51 pm

8BitHazey wrote:Jack, don't forget to jam this up onto the wiki.

http://www.townswiki.com/wiki/Main_Page

I'll have to put a link from the wiki to the OP cause the wiki don't allow code posting.
JackPS9
 
Posts: 1088
Joined: Mon Sep 03, 2012 4:15 pm

Re: Modding 101 - actions

Postby 8BitHazey » Wed Oct 10, 2012 11:23 pm

JackPS9 wrote:
8BitHazey wrote:Jack, don't forget to jam this up onto the wiki.

http://www.townswiki.com/wiki/Main_Page

I'll have to put a link from the wiki to the OP cause the wiki don't allow code posting.


For sure, its a great tutorial for new players to understand the modding API. Just don't want people to miss it as it will eliminate some questions on the forum once the game starts to pick up more momentum.
User avatar
8BitHazey
 
Posts: 61
Joined: Mon Oct 08, 2012 10:00 am
Location: Keeping it Dapper somewhere.

Re: Modding 101 - actions

Postby JackPS9 » Wed Oct 10, 2012 11:39 pm

8BitHazey wrote:
JackPS9 wrote:
8BitHazey wrote:Jack, don't forget to jam this up onto the wiki.

http://www.townswiki.com/wiki/Main_Page

I'll have to put a link from the wiki to the OP cause the wiki don't allow code posting.


For sure, its a great tutorial for new players to understand the modding API. Just don't want people to miss it as it will eliminate some questions on the forum once the game starts to pick up more momentum.

The modding for this game is pretty simple.
Probably the easiest game ever to mod.
Though I'm sthinking the modding section should be split into three sections
MODs, Tutorials, Support
Just so that mods aren't mixed in with all the questions people ask.


I still have like 3 more tags in the actions I have to do.

<move useSource="true">item ID</move>
For things like chopping trees

<destroyCellItem />
Deleting the item in the cell the townie is in

<replaceCellItem>Item ID</replaceCellItem>
replacing cell item with another item.

Those are all for actions I think.
JackPS9
 
Posts: 1088
Joined: Mon Sep 03, 2012 4:15 pm

Re: Modding 101 - actions

Postby ericb1800 » Wed Oct 10, 2012 11:58 pm

Thanks it explains alot!
ericb1800
 
Posts: 815
Joined: Sun Nov 25, 2012 7:17 pm

Re: Modding 101 - actions

Postby molten2metal » Thu Oct 11, 2012 2:15 am

It's a great tutorial you have there, but the Wiki is used for articles, not links to other website. It would be great if you could try and transfer all the information to the wiki article. If I have the time, I'll do it for you if you wish. =D

If you can do this, I'll link the article to the main page.
Come help out! http://www.townswiki.com (Molten2metal - Townswiki Moderator)
User avatar
molten2metal
 
Posts: 51
Joined: Sun Mar 25, 2012 3:18 pm
Location: Australia

Re: Modding 101 - actions

Postby Atoning Unifex » Thu Oct 11, 2012 9:56 am

JackPS9 wrote:I haven't fully figured out this next part on how the timing works.
So how long does it take to craft our chair?
Well we get to edit the length ourselves in the wait tags
Code: Select all
<wait></wait>

I would put it around 20


Nice tutorial.

I believe timing is done in 'ticks' and there are 8 to a second (although this will presumably vary with the speed you are playing at). So a wait of 20 will be 2.5 seconds.

I think you also need to include the <changeTerrain> action too...
Atoning Unifex
 
Posts: 340
Joined: Wed Sep 05, 2012 11:28 am

Re: Modding 101 - actions

Postby smithforge » Thu Oct 11, 2012 10:14 am

Atoning Unifex wrote:
I think you also need to include the <changeTerrain> action too...


There are also others like <pickFriendly> and <createFriendly> etc.
If we want to be more organized, I think we should put together a complete list of tags so far into a table (in wiki. I believe there is already something like that), then put some short explanation to each tag, potentially followed by examples as OP post. The basic list of tags is just to make sure we cover all tags in the current game version so far.

also, some additional discoveries which might be useful:
- useSource only works with <move>, <pickFriendly> and <moveTerrain>. atm, it doesn't work with <pick>.
- <move> automatically locks the target item. if not <unlock>, other citizens cannot use it (until end of action queue i think). iow, atm, only 1 citizen can <move> to 1 item at a time.
- a citizen can only hold 1 thing in hand (using <pick>, <pickFriendly>, <createItem>, <createFriendly>). Using any one of the tags will destroy any existing item in hand (and replaces it with the new one).
- <pick> does not seem to lock an item until after a citizen reaches it. Thus, it is possible for more than 1 citizen to go after an item via <pick> and fail. (not sure about pickFriendly, but I think likely to be same)

I'll try to put down others when I recall them.
smithforge
 
Posts: 222
Joined: Mon Sep 24, 2012 3:23 pm

Re: Modding 101 - actions

Postby 8BitHazey » Thu Oct 11, 2012 11:13 am

Honestly, we should all just work together to rebuild the Modding section of the wiki... haha
User avatar
8BitHazey
 
Posts: 61
Joined: Mon Oct 08, 2012 10:00 am
Location: Keeping it Dapper somewhere.

Next

Return to Modding

Who is online

Users browsing this forum: No registered users and 5 guests

cron