Skip to main content

Simple Farm (Basic Mechanics)

Searching for how  to create a bot with the Farm game in Telegram? In this article, we will tell you how to create a bot with the game Farm using @MenuBuilderBot. We will reveal the BASIC principles of the game mechanics of the user receiving profit from the purchase of plants (trees) and harvesting.

It is important to understand that the basic principles themselves are not enough to create a QUALITY "immersive" GAME, but by understanding the basics - you can apply them to your specific project in the form you need. To create the necessary entourage, the basic game mechanics must be surrounded and justified by a plot scenario, as well as auxiliary functionality (balance replenishment, the presence of different types of balances for different in-game currencies or items, the presence of various ways to formalize the basic mechanics in some scenario-based form, the ability for the user to HIMSELF specify or select individual parameters).

❖ Necessary skills

WARNING: This guide is NOT intended to teach beginners and assumes that you have basic skills in working with the constructor and are READY to create more complex projects. The guide reveals the PRINCIPAL SCHEME of operation of individual game mechanics, in particular the basic PRINCIPLES OF WORKING WITH TIME. If in the process of studying the presented material your basic knowledge turns out to be insufficient, we advise you to study the basics before continuing - we will not teach you "how to create buttons" in this guide.

Despite the fact that the manual is designed for knowledgeable admins, to simplify the initial understanding of the given schemes - they are given IN THEIR MOST BASIC FORM. In the future, having understood the principles of their work, you will be able to complicate them as necessary - such an approach will allow you YOURSELF to form the CORRECT PRINCIPLES OF WORK with new functionality and knowledge - will make it clear that YOU DO NOT NEED TO THOUGHTFULLY COPY the given approaches (and then come to support and say that nothing works and you do not understand anything) - you need to comprehend their principle using simple examples and then, as your understanding grows, move on to more complex application options.

List of required skills:

Creating Buttons and Messages
Variables
Macros
Balance in the bot
Conditions
Actions
Expressions
Working with Date and Time

❖ Basic scheme of the mechanics of the Farm game in the bot

In this scheme:
• The user improves the garden by buying trees that bear fruit every day.
• Different trees bear different amounts of fruit per amount of time.
• The user harvesting fruits once a day (trees do not bear any fruit until the previous harvest is not over).
• The harvested crop goes to the Warehouse, from where it can be sold to receive coins on the Balance.

Preparatory actions

    At this stage, we are preparing the functionality of our bot to create game mechanics.

● You already have the numeric variable «balance» - the user’s Main Balance is stored there.

● Create Numeric variables to store tree types (garden):
«fa_app_trees» - it will store the number of Apple trees.
«fa_pea_trees» - it will store the number of Pear trees.
«fa_ora_trees» - it will store the number of Orange trees.

● Create Numeric variables to store the collected fruits (warehouse):
«fa_app_items» - it will store the number of Apples.
«fa_pea_items» - it will store the number of Pears.
«fa_ora_items» - it will store the number of Oranges.

● Create Date and Time variables to store the last harvest date:
«fa_app_collect» - it will store the Apple harvest date.
«fa_pea_collect» - it will store the Pears harvest date.
«fa_ora_collect» - it will store the Oranges harvest date.

Checking the status

Status check button - allows the player to find out the main game indicators at the moment.

● Create a «My Garden» button with a message like:

My Garden
🍏: {floor(dt_passedm("%fa_app_collect%", 24) * %fa_app_trees% * 10 / 24)}, growth time: {dt_passed_hm("%fa_app_collect%")
🍐: {floor(dt_passedm("%fa_pea_collect%", 24) * %fa_pea_trees% * 30 / 24)}, growth time: {dt_passed_hm("%fa_pea_collect%")}
🍊: {floor(dt_passedm("%fa_ora_collect%", 24) * %fa_ora_trees% * 50 / 24)}, growth time: {dt_passed_hm("%fa_ora_collect%")}

The maximum growth time is one day (24 hours). After that, the amount of fruit stops growing until you collect it.

In your warehouse:
🍏: %fa_app_items%
🍐: %fa_pea_items%
🍊: %fa_ora_items%

Fruit growth is calculated using a formula. After 24 hours, the growth stops.
Here's how it works (using Apple Trees as an example):
1. Calculate how many HOURS have passed since the last harvest (in fractional hours):
dt_passedm("%fa_app_collect%", 24) - the elapsed time in hours, but NOT more than 24 hours.
2. Multiply the number of hours that have passed (from the formula above) by the number of trees in the garden and the number of their fruits per hour:
%fa_app_trees% * 10 / 24 - multiplying the number of trees by their yield per DAY (10) and dividing by the number of hours in a day (24) - we geting the number per hour.
3. Wrap the result in the floor() Function - so that the message contains only integers (it cannot be half an Apple).

Upgrading the Garden

The Improve button allows you to increase the number of trees of each type. One button - improves one type of trees by a specified amount.

● Create an «Upgrade Garden» button.

● Add a Message to the button describing the characteristics of each tree type (example for Apples):

🍏 Apple Orchard
Current Level: %fa_app_trees%
Produces: {(%fa_app_trees%)*10} 🍏 per day
Next Level: {%fa_app_trees%+1}
Will produce: {(%fa_app_trees% + 1)*10} 🍏 per day
Upgrade Cost: {pow(10,(%fa_app_trees% + 1))} coins

● Create a button «Upgrade Apple Orchard» with the Condition «{%balance% >= pow(10,(%fa_app_trees% + 1))}» and the error message «Insufficient funds».

In the example described, the cost of each Garden upgrade (each level) grows exponentially and represented as: the base cost of one tree (at level zero) to the power of the number of existing trees (levels) plus 1. This variant is presented here as an example of one of the ways to increase the cost of levels, using mathematical methods - without describing each level separately.
Level 1 - 10 coins
Level 2 - 100 coins
Level 3 - 1000 coins etc.

● Add «Action of Numbers» (deducting funds from the balance - calculating the number of coins using the formula)
Variable to change: balance
Operation type: Change Value
Value
: -{pow(10,(%fa_app_trees% + 1)} (raise the base cost of the level (10) to the power of the next level number)
Condition: none
Failure Message: none
Success Message: optional

● Add «Action of Numbers» (upgrading the garden)
Variable to change: fa_app_trees
Operation type: Change Value
Value: 1 (one)
Condition: none
Failure Message: none
Success Message: optional

● Add a Message to the button: «Apple Orchard upgraded to level %fa_app_trees%!»

IMPORTANT: It is important to understand that in this case only a generalized mechanism is described and, in a good way (since the received profit is calculated by time), when buying a new tree, it would be necessary to recalculate the fruits that have already grown at the moment into a separate variable and show the current (calculated by the formula) amount as the sum of the calculated income and the fixed one. Because when buying a new tree without fixing the amount and updating the time, the total amount of fruits will be calculated according to the old time, but with a new number of trees - as a result, it will turn out that the new tree has been bearing fruit since the moment the player harvested the crop last time (which is incorrect and opens up scope for abuse).

Another implementation option is to immediately harvest the crop (see below) at the moment of buying a new tree (increasing the level of the garden) - but this action will require some kind of scenario justification so that the player does not get the impression that the accumulated amount of fruits (calculated by the formula) disappears after the upgrade.

There is no universal solution here - it all depends in what form the described mechanics are clothed in your specific project. In this tutorial, we do not create a game, but describing approaches of implementing typical game mechanics.

Harvesting

The Harvest button allows you to transfer to the "Warehouse" the amount of fruit calculated by the formula ("grown") for each type of tree.

● Create a «Harvest» button with a message like:

Harvest:
🍏 Apples: {floor(dt_passedm("%fa_app_collect%", 24) * %fa_app_trees% * 10 / 24)}
🍐 Pears: {floor(dt_passedm("%fa_pea_collect%", 24) * %fa_pea_trees% * 30 / 24)}
🍊 Oranges: {floor(dt_passedm("%fa_ora_collect%", 24) * %fa_ora_trees% * 50 / 24)}

The Harvesting of a single crop - we will show at the example of Apples - for harvesting other crops the process will be similar.

● Inside the «Harvest» button, create a «Collect Apples» button:

● Add «Action of Numbers» (transferring grown up to the Warehouse)
Variable to change: fa_app_items
Operation type: Change Value
Value: {floor(dt_passedm("%fa_app_collect%", 24) * %fa_app_trees% * 10 / 24)}
Condition: none
Failure Message: none
Success Message: optional

The calculation mechanism for the grown is described above in the «Checking the status» section of  «My Garden» button.

● Add «Action of Numbers» (setting new profit counting time)
Variable to change: fa_app_collect
Operation type: Set Value
Value
: {dt_now()} (time "now")
Condition: none
Failure Message: none
Success Message: optional

You can add a command to this button (without transition) and pull it with the «Action of Commands» every time you upgrade the Apple Orchard - transferring the grown and setting a new time (see above).

● Add a Message to the button: «Apples (%fa_app_items_v%) have been moved to the Warehouse!»

Selling fruits

The sell fruit button allows you to exchange the harvest stored in the Warehouse for Coins at a specified price.

We will consider the sale of a separate crop using the example of Apples - for the sale of other crops the process will be similar.

● Create a «Sell Fruits» button with a message like:

Selling Fruits:
🍏 Apple: 2 coins
🍐 Pear: 5 coins
🍊 Orange: 10 coins
My Warehouse:
🍏 Apples: %fa_app_items% ({%fa_app_items% * 2} coins)
🍐 Pears: %fa_pea_items% ({%fa_pea_items% * 5} coins)
🍊 Oranges: %fa_ora_items% ({%fa_ora_items% * 10} coins)

● Inside the «Sell Fruits» button, create a «Sell Apples» button:

● Add «Action of Numbers» (adding the amount to the Balance)
Variable to change: balance
Operation type: Change Value
Value: {%fa_app_items% * 2}
Condition: none
Failure Message: none
Success Message: optional

● Add «Action of Numbers» (deducting sold fruits)
Variable to change: fa_app_items
Operation type: Change Value
Value: {%fa_app_items% - %fa_app_items%} (subtracting the number from itself - see below)
Condition: none
Failure Message: none
Success Message: optional

When deducting sold fruits, we use the "Change Value" mode and subtract the number from itself, instead of simply "Set Value" of the variable equal to 0 (zero). This is necessary so that the button message can show the number of fruits sold - if we "Set Value" then the "_v" macros will not work.

● Add a Message to the button: «Sold %fa_app_items_v% Apples, received %balance_v% coins!»

In the presented form, selling fruit is more like an "airdrop". In order to become similar to game mechanics, selling should also be associated with certain kinds of difficulties - what exactly - you decide yourself (for example, you can let players to only sell a certain amount per day, etc.).

❖ Options for improving basic mechanics

The ability to harvest the entire crop at once

You can give players the opportunity (for a fee) to collect the ENTIRE harvest by pressing ONE button. To do this, create a button that will deduct the amount of payment you set from the Balance using «Action of Numbers», and then duplicate, in this button, the functionality from the "Harvest" section for each available crop.

OPTIMIZATION OPTION: assign a command to each of the buttons for collecting a separate crop. Then, in the button that collects the ENTIRE crop at a time, you may not duplicate the Actions, but call the buttons for collecting each crop with its commands (using the Action of Commands) and get the same result with fewer Actions. This is especially useful if the collection buttons have more actions than two (two as in the basic version).

Improved tree varieties

Put the yield of each type of Tree into a separate variable and increase the number stored there using mechanics similar to those you used when upgrading the Garden. With each upgrade, remember that it should be done only after harvesting or by recalculating the amount grown by the time of the upgrade.