At the time of writing scripts are allowed to be used with TownStar, as long as they don't do anything that breaks the game, but double check what the rules say to be sure: https://support.gala.games/town-star-rules
Use at your own risk, I have tested this and am satisfied it is free of bugs, but I am not responsible for any loss incurred by others that arose from using this script.
Now for the fun stuff...
This script is designed to be used with Tampermonkey, if you haven't used this extension before then please first install it. Then you can just create a new script through Tampermonkey and paste the contents of updated_sell_script.js
into it. Then open or refresh TownStar and it should load. If you open the developper tools you will see some info messages in the console.
This script supports both Trade Depots and Trade Piers. It does NOT currently support Freight Piers or Express Depots (though I might add it in future) If you want to use a Freight Pier you can always use the original script for that one item, or you can experiment with adding bits of your own code.
However, it does support any number of Trade Depots and Trade Piers (including a mix of both) and will use them all one after another in a loop! This is automatic and requires no configuration from the user.
Point to note: when you first load the game (or after a page refresh), you should manually open a trade terminal on each edge of your town, just to let the trades load for that side or it might cause the script to glith on the first trade (if all your depots are on one side then you only need to do one)
There are 3 things you need to configure:
sellTimer
: the optimal value is given by calculating longest_journey_time/number_of_trade_terminals (and it's better to always round up a bit)gasLimit
: the minimum amount of gas you want to keep (in case you want some spare for manual sales). Must also be enough for at least one trade (so0
is not ok!)sellItemsAndLimits
: the most important part, here you should add every item you want to be sold automatically and a threshold value. The threshold is the minimum amount you want to keep, so the script will only sell when you havethreshold+10
of that item. See Examples section for more details.
Thats's it! Simply configure those variables and you should be good to go (remember to refresh the game to load any changes you made to the script).
To illustrate the script's full functionality, here are some examples.
I'm running a wine build and also selling grapes for cash, I have two Trade Depots and travel time is 35secs at a cost of 1 fuel (lucky me!). I also sometimes have a surplus of Oak Wood but I want to keep between 10 and 20 of them. Everything else is assumed to be balanced for this example. Here is my config:
const sellTimer = 20; // 35/2 = 17.5, and round up to 20 just to be safe
const gasLimit = 1; // I don't want to keep any extra
const sellItemsAndLimits = [
['Wine', 0], // Don't keep any wine (it will sell when I have > 0+9 wine, so 10)
['Pinot_Noir_Grapes', 20], // I want to keep at least 20, so this will sell anything over 29
['Oak_Wood', 10] // I want to keep between 10 and 20, so anything over 19 will be sold
];
I'm running a Pumpkin Pie build, I have 3 Trade Piers and 2 Trade Depots, my longest travel time is 3mins (so 180secs) and fuel cost is 2. I'm selling grapes for cash but I also sometimes have surplus of wood, gas, eggs, pumpkins, etc. I want to keep a few of each though so I can always make my pies. Here is my config:
const sellTimer = 40; // 180/5 = 36, going to round up to 40 to be safe
const gasLimit = 2; // I don't want to keep any extra but my limit is 2 fuel per trip
const sellItemsAndLimits = [
['Wood', 45], // sell when I have 55 or more
['Gasoline', 65], // sell when I have 75 or more
['Pinot_Noir_Grapes', 0], // sell as soon as I can
['Wheat', 20], // want to keep at least 20, sell when 30 or more
['Eggs', 15], // want to keep at least 15, sell when 25 or more
['Sugarcane', 20], // same as wheat, you get the idea
['Pumpkin', 20], // same as above
['Pumpkin_Pie', 0] // sell pies as soon as I have at least 10
];
I have only 1 Trade Pier with a time of only 15secs and 1 gas cost. I do want to keep some extra gas for myself though, as I will manually use a Freight Pier sometimes which isn't handled by this script. The only things I want to sell automatically are blue steel and surplus cotton yarn. I also want to save some blue steel for the last day of the competition, so I will keep 2 stacks and sell the rest. Here is my config:
const sellTimer = 20; // 15/1 = 15, but going to round up anyway
const gasLimit = 10; // trip cost is 1, but I want to keep a few for manual sells
const sellItemsAndLimits = [
['Cotton_Yarn', 5], // keep at least 5, sell when I have 15 or more
['Blue_Steel', 20] // I want to keep 2 stacks of 10, so this will only sell when I have 30 or more, I will never drop under 20
];