How to edit, create and remove config, how to add scripts, how script are loaded (alphabetically), link to place where you can learn lua (or some tutorial), log functions (print, info, warn, error), main variables (now, time, player, storage), how to get item id, link to bot files and functions (https://github.com/OTCv8/otclientv8/tree/master/modules/game_bot)
To create a config navigate to %appdata%\OTClientV8\otclientv8\bot and create a folder with desired config name. Every folder in the bot directory is treated as a config.
Following images shows 2 configs. Default config and a config called config1 created by the user.
Inside of a config will be your .lua files containing the scripts you want to run. The client will run the files in alphabetical order. See next picture for a visual demonstration on which while runs first.
You can also follow the quick in-client tutorial on how to setup your configs if you feel confident enough to tackle it on your own. Picture shown below is the in-client tutorial.
Getting started with scripting
Before diving into the unknown world of otclientv8 scripting it's highly recommended to learn Lua and the basic principles of programming.
Now that you feel more comfortable with the Lua language and how scripting / programming works lets dive right into it.
First off lets cover the built in debugging functions we can use in otclientv8.
info(string) -- Displays white text in the macro window warn(string) -- Displays yellow text in the macro window error(string) -- Displays red text in the macro window print(string) -- Prints to the built in terminal (ctrl+t to access terminal)
- info: Great way to print information you're collecting to know exactly what you're working with
- warn: Great to use when you meet a condition that could possibly cause an issue
- error: Great to use when you meet a condition that WILL cause an error
- print: A neat way to constantly log a lot of values that you want to monitor (terminal can display way more text than macro window)
Now that we're familiar with the logging features lets take a look at some built in variables we can access.
now -- Time in milliseconds from when the application started time -- Time in milliseconds from when the application started player -- Local player object storage -- A way to store variables even when client is restarted
- now/time: Very useful for scripts that are dependant on time example: mwall timers
- player: Contains a lot of information about the player such as position, health, outfit etc
- storage: Great to use when you want to store values even when you close the client
Lets take a look at some examples on how to use these variables and logging functions.
-- Example how to use certain warning depending on a condition macro(1000, "HP Tracker", function() if hppercent() > 90 then info("Your hp is in a good condition") else if and hppercent() > 50 then warn("Your hp is getting low, please heal") else error("Your hp is ridiculously low, HEAL NOW!") end end) -- Information about macro can be found here (http://bot.otclient.ovh/books/tutorials/page/macros) -- Example how to log player position in terminal macro(1000, "Log Player Pos", function() print("X: " .. posx() .. " Y: " .. posy() .. " Z: " .. posz()) end) -- Warn if player has skull macro(250, "Skull Tracker", function() if player:getSkull() ~= 0 then warn("You have a skull!!!") end end)
As you can see in the examples above there's quite a few use cases above where logging information can be useful. In the scripts above I made sure to use built in functions to not confuse you with a lot of extra code.
- posx(): Same as player:getPosition().x (returns the x position of player)
- posy(): Same as player:getPosition().y (returns the y position of player)
- posz(): Same as player:getPosition().z (returns the z position of player)
- hppercent(): Same as player:getHealthPercent() (returns the health percentage of player)
I also made use of a player function, more specifically the getSkull() function which is accessed through a creature objects. It returns the ID of the skull (0 if there's no skull).
Now that we know how to make use of the logging functions and some built in functions lets make a script that has some real value in terms of gameplay. Try to make sense of the following code before reading through the walkthrough guide below.
local healSpellWeak = "Exura" local healSpellMedium = "Exura Gran" local healSpellStrong = "Exura Vita" macro(250, "Auto Heal", function() if hppercent() > 90 and hppercent() < 99 then say(healSpellWeak) else if hppercent() > 50 then say(healSpellMedium) else say(healSpellStrong) end ene)
If you can't make sense of the code don't worry. Lets walk it through step by step. First we assign 3 variables to contain a string with the spell name of our choosing. A weaker healing spell, a medium and then a strong one depending on how critical our health is. We then create a macro, this macro will run every 250 milliseconds and the callback for the macro is our function that contains the logic for when we should heal ourselves. The functions works as following, if players hp is between 90 and 99 percent we will use the weaker healing spell however if player hp drops below 90 percent but is still above 50 percent we will use the medium strong healing spell but if all of those if statements fail we will use the strongest spell possible to make sure we don't die. Note that we're using a new function called say(), more info about that below.
- say(string): Accepts a string as parameter and will make your character say that string in game.
Information about macros can be found here