Tutorial 2: Adding a new command
In your “my first exts.cpp” insert these lines at the end of the file:
CHARACTER_EXTENSION "Peasant"
OFFERS_COMMAND "my cmd 1"
END_CHARACTER_EXTENSION
COMMAND "my cmd 1"
BUTTON_ENABLED "interface\icons\SIC_Bell.tga"
DEFAULT_HINT Gimme_some_gold
START_SEQUENCE
ACTION INCREASE_ITEM "Gold" FINDER_SELF CONSTANT 10
END_START_SEQUENCE
END_COMMAND
When you open the modded savegame and you select a peasant, you will see a bell button in the bottom-left corner of the screen. If you click it, the gold of the peasant will be increased by 10.
Commands are defined in COMMAND blocks. BUTTON_ENABLED allows you to put an icon for the command. DEFAULT_HINT contains the text for the tooltip.
The start sequence contains one or more actions that are executed when the command is clicked. In this example there is an action which increases the value of an item. An item can be shortly described as a “variable” or a “number container”. All objects (characters, buildings, and also players) have for every item their own values. “Gold” is the item that contains the amount of gold an object holds. FINDER_SELF means that we want to modify the gold item of the peasant(s) that is/are selected. CONSTANT 10 is the value we want to add to the item value. In this case we add 10 to the gold value of the selected peasant(s).
Bonus
Other interesting items are: “Food”, “Wood”, “Stone”, “Hit Points”
If you change FINDER_SELF to FINDER_PLAYER, the amount of gold of the player of the selected object will be increased instead of the selected object itself. Note that the item can be increased multiple times if you select multiple peasants because the START_SEQUENCE is in fact executed for every peasant.
Change INCREASE_ITEM to DECREASE_ITEM if you want to subtract, or to SET_ITEM if you simply want to copy the last value to the item.