Creating Script Setups: The Right Way
<div class="raph">
<div class="post-title">
<h1>Creating Script Setups</h1>
<h2>The Right Way</h2>
</div>
<h2>Index</h2>
<ol class="numbered">
<li>
<a class="anchor js-anchor" href="http://forums.tibiawindbot.com/showthread.php?1236#1">What's a setup?</a>
<ol>
<li><a class="anchor js-anchor" href="http://forums.tibiawindbot.com/showthread.php?1236#1.1">How it was done</a></li>
<li><a class="anchor js-anchor" href="http://forums.tibiawindbot.com/showthread.php?1236#1.2">How we are doing it</a></li>
</ol>
</li>
<li>
<a class="anchor js-anchor" href="http://forums.tibiawindbot.com/showthread.php?1236#2">How to build a setup?</a>
<ol>
<li><a class="anchor js-anchor" href="http://forums.tibiawindbot.com/showthread.php?1236#2.1">OK, but where to I put that JASON thing?</a></li>
<li>
<a class="anchor js-anchor" href="http://forums.tibiawindbot.com/showthread.php?1236#2.2">OK, but how do I build that JSON thing?</a>
<ol>
<li><a class="anchor js-anchor" href="http://forums.tibiawindbot.com/showthread.php?1236#2.2.1">Group Widget</a></li>
<li><a class="anchor js-anchor" href="http://forums.tibiawindbot.com/showthread.php?1236#2.2.2">Line Edit Widget</a></li>
<li><a class="anchor js-anchor" href="http://forums.tibiawindbot.com/showthread.php?1236#2.2.3">Checkbox Widget</a></li>
<li><a class="anchor js-anchor" href="http://forums.tibiawindbot.com/showthread.php?1236#2.2.4">Combobox Widget</a></li>
<li><a class="anchor js-anchor" href="http://forums.tibiawindbot.com/showthread.php?1236#2.2.5">Spinbox Widget</a></li>
<li><a class="anchor js-anchor" href="http://forums.tibiawindbot.com/showthread.php?1236#2.2.6">DoubleSpinbox Widget</a></li>
<li><a class="anchor js-anchor" href="http://forums.tibiawindbot.com/showthread.php?1236#2.2.7">RangeSpinbox Widget</a></li>
</ol>
</li>
</ol>
</li>
<li><a class="anchor js-anchor" href="http://forums.tibiawindbot.com/showthread.php?1236#3">OK, but how do I read those values?</a></li>
</ol>
<h2 id="1">What's a Setup?</h2>
<p>The Setup is where the user who downloads your script, or even yourself, will be able to configure the script, to make it suit his needs. You could add options to enable or disable specific hunting areas, specify custom behavior and much more; there are endless possibilities.</p>
<div class="indent">
<h3 id="1.1">How it was done</h2>
<p>If you come from previous bots, you are probably used to this kind of setup. If you don't, no worries, we won't be using it. Well, this has always been used, since NeoBot times, and it worked since then, but it put unnecessary stress on the end user and often caused unintended typing mistakes that would compromise the whole script.</p>
http://i.imgur.com/J3ok6ay.png
<h6>Image taken from the internet.<h6>
<h3 id="1.2">How we are doing it</h3>
<p>So, we thought of a way to make things easier, even more. And this is what we came up with:</p>
http://i.imgur.com/5hOTrNW.png
<h6>Example built based on the image above.</h6>
</div>
<h2 id="2">How to build a Setup?</h1>
<p>To build the setup, we'll have to work with a markup language called JSON. If you're not familiar with it, that's cool, take it easy, it's not that hard. Take a look at the code I used to build example above:</p>
<div class="bbcode_container">
<div class="bbcode_description">JSON Code:</div>
<pre class="bbcode_code">{
"type" : "group",
"name" : "generalInfo",
"text" : "General Information",
"children" : [
{
"type" : "lineedit",
"name" : "account",
"text" : "Account:",
"description" : "Your account name.",
"value" : "myaccount"
},
{
"type" : "lineedit",
"name" : "password",
"text" : "Password:",
"description" : "Your account's password.",
"value" : "mysecretpassword"
},
{
"type" : "lineedit",
"name" : "charList",
"text" : "Chars. List:",
"description" : "The name of your characters, comma separated.",
"value" : "John, Bob, Ann, Joe, Mary"
},
{
"type" : "checkbox",
"name" : "relog",
"text" : "Log on the next char",
"description" : "Should the bot log on the next character once the current one finishes?",
"value" : true
}
]
},
{
"type" : "group",
"name" : "otherOptions",
"text" : "Other Options",
"column" : 2,
"children" : [
{
"type" : "combobox",
"name" : "vocation",
"text" : "Vocation",
"description" : "Which vocation should be chosen?",
"items" : ["Knight", "Paladin", "Sorcerer", "Druid"]
},
{
"type" : "combobox",
"name" : "weapon",
"text" : "Knight Weapon",
"description" : "If you chose Knight as vocation, which weapon type should be chosen?",
"items" : ["Axe", "Sword", "Club"]
},
{
"type" : "combobox",
"name" : "city",
"text" : "City",
"description" : "What city should be chosen?",
"items" : ["Ankrahmun", "Edron", "Darashia", "Liberty Bay", "Port Hope", "Ab'Dendriel", "Carlin", "Thais", "Venore"]
}
]
}</pre>
</div>
<p>I believe it has a fairly simple syntax, so I won't take long describing it. <span class="warning">Just remember to use " and not '.</span></p>
<div class="indent">
<h3 id="2.1">OK, but where to I put that J<s>A</s>SON thing?</h3>
<p>You put the JSON inside a place we call User Options, which is just stylish way to say setup. You can find it under Cavebot\Settings tab, on the bottom right corner. It's a button named Edit User Options.</p>
http://i.imgur.com/C1HPeqr.png
<h3 id="2.2">OK, but how do I build that JSON thing?</h3>
<p>Well, I'm glad you finally learned how to spell it correctly. We shall move on then: the Setup is based on widgets. A widget can be thought of as a setting in the setup. It's a text field, a checkbox, etc... Each widget has its functionality and we'll be going over every single one of them in this tutorial.</p>
<div class="indent">
<h4 id="2.2.1">Group Widget</h4>
<p>This is our main widget. It's inside it that we place all the other widgets.</p>
<h5>Properties:</h5>
- type: The widget type; "group" in this case.
- name: The name of the widget. It's used to retrieve its current value.
- text: The title of the group box; if none is provided, name is used.
- description: The description to be displayed on info box; if none is provided, text is used.
- checkable: Whether the widget should be checkable; a checkbox will appear beside it and checking/unchecking enables/disables the groupbox and its children.
- column: The column the group box should be place on; 1 for first column, 2 for second.
- children: The widgets the group box will contain.
<h5>Examples:</h5>
<div class="cms_table">
<table class="cms_table">
<tbody>
<tr valign="top">
<td class="cms_table_td fit-widget">
<img src="http://i.imgur.com/4srl011.png" alt="" />
</td>
<td class="cms_table_td">
<div class="bbcode_container">
<div class="bbcode_description">JSON Code:</div>
<pre class="bbcode_code">{
"type" : "group",
"name" : "groupName",
"text" : "Title",
"children" : []
}</pre>
</div>
</td>
</tr>
<tr valign="top">
<td class="cms_table_td fit-widget">
<img src="http://i.imgur.com/tac2QAj.png" alt="" />
</td>
<td class="cms_table_td">
<div class="bbcode_container">
<div class="bbcode_description">JSON Code:</div>
<pre class="bbcode_code">{
"type" : "group",
"name" : "General Information",
"checkable" : true,
"children" : [
{
"type" : "lineedit",
"name" : "account",
"text" : "Account:",
"description" : "Your account name.",
"value" : "myaccount"
},
{
"type" : "lineedit",
"name" : "password",
"text" : "Password:",
"description" : "Your account's password.",
"value" : "mysecretpassword"
},
{
"type" : "lineedit",
"name" : "charList",
"text" : "Chars. List:",
"description" : "The name of your characters, comma separated.",
"value" : "John, Bob, Ann, Joe, Mary"
},
{
"type" : "checkbox",
"name" : "relog",
"text" : "Log on the next char",
"description" : "Should the bot log on the next character once the current one finishes?",
"value" : true
}
]
}</pre>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<h4 id="2.2.2">Line Edit Widget</h4>
<p>This is one of the simplest widgets. It's basically a text field, in which you can input any text. It could be used to get the name of a special character, some backpacks for the setup or even a safelist, if handled correctly.</p>
<h5>Properties:</h5>
- type: The widget type; "lineedit" in this case.
- name: The name of the widget. It's used to retrieve its current value.
- text: The label to be displayed beside the text field; if none is provided, name is used.
- description: The description to be displayed on info box; if none is provided, text is used.
- placeholder: The placeholder for the widget.
- value: The default value for the field.
<h5>Examples:</h5>
<div class="cms_table">
<table class="cms_table">
<tbody>
<tr valign="top">
<td class="cms_table_td fit-widget">
<img src="http://i.imgur.com/m0fuAGo.png" alt="" />
</td>
<td class="cms_table_td">
<div class="bbcode_container">
<div class="bbcode_description">JSON Code:</div>
<pre class="bbcode_code">{
"type" : "group",
"name" : "General Information",
"children" : [
{
"type" : "lineedit",
"name" : "account",
"text" : "Account:",
"description" : "Your account name.",
"value" : "myaccount"
}
]
}</pre>
</div>
</td>
</tr>
<tr valign="top">
<td class="cms_table_td fit-widget">
<img src="http://i.imgur.com/N0w9XN6.png" alt="" />
</td>
<td class="cms_table_td">
<div class="bbcode_container">
<div class="bbcode_description">JSON Code:</div>
<pre class="bbcode_code">{
"type" : "group",
"name" : "Cool Title",
"children" : [
{
"type" : "lineedit",
"name" : "safelist",
"text" : "Safe List:"
}
]
}</pre>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<h4 id="2.2.3">Checkbox Widget</h4>
<p>This one is pretty simple too. You're probably used to it in most websites/softwares, like on that "remember me" thing. It's useful for simple yes/no questions, like specifying if a special path to the hunt should be taken or if the bot should use a specific hunting strategy.</p>
<h5>Properties:</h5>
- type: The widget type; "checkbox" in this case.
- name: The name of the widget. It's used to retrieve its current value.
- text: The label to be displayed beside the checkbox; if none is provided, name is used.
- description: The description to be displayed on info box; if none is provided, text is used.
- value: The default value for the field; true or false.
<h5>Examples:</h5>
<div class="cms_table">
<table class="cms_table">
<tbody>
<tr valign="top">
<td class="cms_table_td fit-widget">
<img src="http://i.imgur.com/XWjqnya.png" alt="" />
</td>
<td class="cms_table_td">
<div class="bbcode_container">
<div class="bbcode_description">JSON Code:</div>
<pre class="bbcode_code">{
"type" : "group",
"name" : "General Information",
"children" : [
{
"type" : "checkbox",
"name" : "dostuff",
"text" : "Do some stuff?"
}
]
}</pre>
</div>
</td>
</tr>
<tr valign="top">
<td class="cms_table_td fit-widget">
<img src="http://i.imgur.com/3mle99S.png" alt="" />
</td>
<td class="cms_table_td">
<div class="bbcode_container">
<div class="bbcode_description">JSON Code:</div>
<pre class="bbcode_code">{
"type" : "group",
"name" : "Waddup",
"children" : [
{
"type" : "checkbox",
"name" : "raphael",
"text" : "Does Raphael rock?",
"value" : true
}
]
}</pre>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<h4 id="2.2.4">Combobox Widget</h4>
<p>This is lets you choose an option from a few pre-specified options. This is good to let the user choose, let's say, a city as destination, a tool to be used as rope or even the backpack used.</p>
<h5>Properties:</h5>
- type: The widget type; "combobox" in this case.
- name: The name of the widget. It's used to retrieve its current value.
- text: The label to be displayed beside the spinbox; if none is provided, name is used.
- description: The description to be displayed on info box; if none is provided, text is used.
- items: The list of the pre-specified options.
<h5>Examples:</h5>
<div class="cms_table">
<table class="cms_table">
<tbody>
<tr valign="top">
<td class="cms_table_td fit-widget">
<img src="http://i.imgur.com/MX3qJnK.png" alt="" />
</td>
<td class="cms_table_td">
<div class="bbcode_container">
<div class="bbcode_description">JSON Code:</div>
<pre class="bbcode_code">{
"type" : "group",
"name" : "General Information",
"children" : [
{
"type" : "combobox",
"name" : "city",
"text" : "City",
"description" : "What city should be chosen?",
"items" : ["Ankrahmun", "Edron", "Darashia", "Liberty Bay", "Port Hope", "Ab'Dendriel", "Carlin", "Thais", "Venore"]
}
]
}</pre>
</div>
</td>
</tr>
<tr valign="top">
<td class="cms_table_td fit-widget">
<img src="http://i.imgur.com/OsWLFxQ.png" alt="" />
</td>
<td class="cms_table_td">
<div class="bbcode_container">
<div class="bbcode_description">JSON Code:</div>
<pre class="bbcode_code">{
"type" : "group",
"name" : "General Stuff",
"children" : [
{
"type" : "combobox",
"name" : "vocation",
"text" : "Vocation",
"description" : "Which vocation should be chosen?",
"items" : ["Knight", "Paladin", "Sorcerer", "Druid"]
}
]
}</pre>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<h4 id="2.2.5">Spinbox Widget</h4>
<p>This is the Line Edit Widget, but for integers. It's good for those situations were you only want to get numbers, like when asking for the amount of supplies to buy or with how much cap the script should leave the cave.</p>
<h5>Properties:</h5>
- type: The widget type; "spinbox" in this case.
- name: The name of the widget. It's used to retrieve its current value.
- text: The label to be displayed beside the spinbox; if none is provided, name is used.
- description: The description to be displayed on info box; if none is provided, text is used.
- value: The default value for the field.
- prefix: The string to be prepended to the number.
- suffix: The string to be appended to the number.
- max: The maximum value that should be accepted; if none is provided, 100 is assumed.
- min: The minimum value that should be accepted; if none is provided, 0 is assumed.
- step: The step by which the up/down arrow should increase/descrease the value; if none is provided, 1 is assumed.
<h5>Examples:</h5>
<div class="cms_table">
<table class="cms_table">
<tbody>
<tr valign="top">
<td class="cms_table_td fit-widget">
<img src="http://i.imgur.com/jlc7hLn.png" alt="" />
</td>
<td class="cms_table_td">
<div class="bbcode_container">
<div class="bbcode_description">JSON Code:</div>
<pre class="bbcode_code">{
"type" : "group",
"name" : "General Information",
"children" : [
{
"type" : "spinbox",
"name" : "age",
"text" : "Age:",
"suffix" : " years",
"min" : 16,
"value" : 18
}
]
}</pre>
</div>
</td>
</tr>
<tr valign="top">
<td class="cms_table_td fit-widget">
<img src="http://i.imgur.com/1ZHoqly.png" alt="" />
</td>
<td class="cms_table_td">
<div class="bbcode_container">
<div class="bbcode_description">JSON Code:</div>
<pre class="bbcode_code">{
"type" : "group",
"name" : "Survey",
"children" : [
{
"type" : "spinbox",
"name" : "grade",
"text" : "Tutorial's Grade",
"description" : "It's over nine thousand!",
"min" : 9000,
"max" : 10000,
"value" : 9001
}
]
}</pre>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<h4 id="2.2.6">DoubleSpinbox Widget</h4>
<p>This is exactly like Spinbox Widget, but for doubles; that is, numbers that have a fractional part. It's probably good for lots of stuff, but I really can't think of anything right now.</p>
<h5>Properties:</h5>
- type: The widget type; "doublespinbox" in this case.
- name: The name of the widget. It's used to retrieve its current value.
- text: The label to be displayed beside the spinbox; if none is provided, name is used.
- description: The description to be displayed on info box; if none is provided, text is used.
- value: The default value for the field.
- prefix: The string to be prepended to the number.
- suffix: The string to be appended to the number.
- max: The maximum value that should be accepted; if none is provided, 100 is assumed.
- min: The minimum value that should be accepted; if none is provided, 0 is assumed.
- step: The step by which the up/down arrow should increase/descrease the value; if none is provided, 1 is assumed.
<h5>Examples:</h5>
<div class="cms_table">
<table class="cms_table">
<tbody>
<tr valign="top">
<td class="cms_table_td fit-widget">
<img src="http://i.imgur.com/GJ8Z1KO.png" alt="" />
</td>
<td class="cms_table_td">
<div class="bbcode_container">
<div class="bbcode_description">JSON Code:</div>
<pre class="bbcode_code">{
"type" : "group",
"name" : "General Math",
"children" : [
{
"type" : "doublespinbox",
"name" : "pi",
"text" : "PI",
"description" : "Ya hungry?",
"min" : 3.14,
"max" : 3.14,
"value" : 3.14
}
]
}</pre>
</div>
</td>
</tr>
<tr valign="top">
<td class="cms_table_td fit-widget">
<img src="http://i.imgur.com/JKphbS6.png" alt="" />
</td>
<td class="cms_table_td">
<div class="bbcode_container">
<div class="bbcode_description">JSON Code:</div>
<pre class="bbcode_code">{
"type" : "group",
"name" : "More Math",
"children" : [
{
"type" : "doublespinbox",
"name" : "numbah",
"text" : "Some Numbah",
"min" : 0,
"value" : 2.71
}
]
}</pre>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<h4 id="2.2.7">RangeSpinbox Widget</h4>
<p>You're probably tired of this already, but this is exactly like Spinbox Widget, works for ranges; that is, it asks for two numbers instead of one. It's good for those situations where you need a maximum and minimum value, so you can make it random, like some waiting time before taking some action.</p>
<h5>Properties:</h5>
- type: The widget type; "rangespinbox" in this case.
- name: The name of the widget. It's used to retrieve its current value.
- text: The label to be displayed beside the spinbox; if none is provided, name is used.
- description: The description to be displayed on info box; if none is provided, text is used.
- value: The default value for the field.
- prefix: The string to be prepended to the number.
- suffix: The string to be appended to the number.
- max: The maximum value that should be accepted; if none is provided, 100 is assumed.
- min: The minimum value that should be accepted; if none is provided, 0 is assumed.
- step: The step by which the up/down arrow should increase/descrease the value; if none is provided, 1 is assumed.
<h5>Examples:</h5>
<div class="cms_table">
<table class="cms_table">
<tbody>
<tr valign="top">
<td class="cms_table_td fit-widget">
<img src="http://i.imgur.com/MsCECnH.png" alt="" />
</td>
<td class="cms_table_td">
<div class="bbcode_container">
<div class="bbcode_description">JSON Code:</div>
<pre class="bbcode_code">{
"type" : "group",
"name" : "General Information",
"children" : [
{
"type" : "rangespinbox",
"name" : "waitSpawn",
"text" : "Spawn Wait Time:",
"description" : "How long should the bot stand still to wait for the creatures to respawn? It's a random value in the selected range.",
"suffix" : " ms",
"min" : 1000,
"max" : 30000,
"value" : 10000
}
]
}</pre>
</div>
</td>
</tr>
<tr valign="top">
<td class="cms_table_td fit-widget">
<img src="http://i.imgur.com/K4YhK9M.png" alt="" />
</td>
<td class="cms_table_td">
<div class="bbcode_container">
<div class="bbcode_description">JSON Code:</div>
<pre class="bbcode_code">{
"type" : "group",
"name" : "Moar Info",
"children" : [
{
"type" : "rangespinbox",
"name" : "ammoRefill",
"text" : "Min. Ammo to Refill",
"min" : 0,
"max" : 100,
"value" : 5
}
]
}</pre>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<h2 id="3">OK, but how do I read those values?</h2>
<p>To read the widgets' values, we'll be using the getuseroption function. Simply use the name property you set for your widget to get the value. Something like this:</p>
</div>