Page 1 of 3 123 LastLast
Results 1 to 10 of 23

Thread: [Tutorial] Learning Actions

  1. #1
    Normal User Nightcrawler's Avatar
    Join Date
    Apr 2012
    Posts
    190
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quoted
    0 Post(s)
    Reputation
    16
    Rep Power
    5

    [Tutorial] Learning Actions

    This is a tutorial for beginners.

    1. Programming basics
    1.1 Programming logic
    1.2 Lua Syntax
    1.2.1 If, elseif
    1.2.2 While, do while
    1.2.3 Operators
    2. Actions
    2.1 iBot Functions
    3. Building a script


    1. Programming basics

    Variables
    A variable is a block of code that can save data for you to use later. First you need to declare, then you can store the data.

    If you are using the Actions in CaveBot then you need to declare variables for local usage.

    Code:
    local VariableX
    And give it a value:
    Code:
    local VariableX
    VariableX = 1337
    Also you can declare and give a value at the same time:

    Code:
    local VariableX = 1337
    The local variables will just be used for its Waypoint, being eliminated and losing data when the bot enter in the next Waypoint.

    If you need to use the same Value in a variable in many parts of the script, then you need to use variables as global. Where? How?

    In Actions>Setup.

    Global variables don't need to be declared, you just need to give the values:
    Code:
    VariableX = 1337
    If you call the VariableX in any part of your script, it will bring 1337 as a value.

    Pratical use: I can store a value in a variable called CapToBack to tell in some point of my script that I need to go back for refill, because I need to deposit and get more cap.

    The variables type can be called by:

    String (str), if they store text.
    Code:
    s = "abc!@#123"
    Code:
    s = "1"
    Integer (int), if they store integer numbers.
    Code:
    i = 1
    Float if they store decimal numbers.
    Code:
    f = 0.321
    Boolean (bool), if they store true or false values.
    Code:
    b = false
    1.1 Programming logic

    The programming logic is how you must think to develop your Actions, it will follow some steps and it is not hard to understand.

    First you need to think in what you need at all. Then, make from it a programming code.

    Action1:

    What I think:
    If my mana is 60 or more and I'm not on haste then cast haste, end that is all.

    What I should tell to iBot:
    Code:
    if mp >= 60 and not hasted then
      cast("utani hur")
    end
    Action2

    What I think:
    While I'm not in the sqm of my waypoint do the following: go to the waypoint that lead me to that sqm, end that is all I need.

    What I should tell to iBot:
    Code:
    while not islocation() do
      gotolabel("WaypointX")
    end
    1.2 Lua Syntax



    Actions in iBot are programmed using the Lua Functions v5.1.

    Here we will take a loot at the most common used syntax of the lua language for our iBot scripts, if and while. Also you can take a look at the Lua 5.1 Reference Manual.

    You can run and test your own code online. In the Lua Demo tool.

    1.2.1 If

    How to use If, elseif.

    if (conditions) then (run code) end

    Code:
    if itemcount("Gold Coin") > 0 then
      depositall()
    end
    if (conditions) then (run code) else (run code) end

    Code:
    if itemcount("Gold Coin") > 0 then
      depositall()
    else
      gotolabel("Hunt")
    end
    if (conditions) then (run code) elseif (conditions) then (run code) else (run code) end

    Code:
    if itemcount("Gold Coin") > 0 then
      depositall()
    elseif itemcount("Gold Coin") == 0 and itemcount("Platinum Coin") > 0 then
      
      local PlatinumInGold = itemcount("Platinum Coin") * 100
      local Total = PlatinumInGold / 2
      
      say("hi")
      wait(1000)
      npcsay("deposit "..Total)
    
    else
      gotolabel("Hunt")
    end
    1.2.2 While

    How to use While, Do While.

    while (conditions) do (run code) end

    Code:
    while mp < 10 do
      say("My mana is lower than 10")
    end
    do (run code) while (conditions) end

    Code:
    do
      gotolabel("RunToTheHills")
    while 
      hppc < 10
    end
    Note: While do, will check first and do while the conditions are met. Do while, will do first then check for conditions to do again.


    1.2.3 Operators

    Arithmetic operators
    + (addition), - (subtraction), * (multiplication), / (division), % (modulo) and ^ (exponentiation)

    Relational operators
    ==, ~=, <, >, <=, and >=

    These operators always result in false or true.

    Logical operators
    and, or, and not.

    All logical operators consider both false and nil as false and anything else as true.

    Concatenation
    The string concatenation operator in Lua is denoted by two dots ('..'). If both operands are strings or numbers, then they are converted to strings.

    This way you can merge text with variables into a new string to say something for a npc:

    i.e:
    Code:
    local Total = 1337
    
    say("hi")
    wait(1000)
    npcsay("withdraw "..Total)
    2 Actions

    There are 2 places where you can use your Actions, in the Actions or in the CaveBot.

    You will use the Actions>Setup to set variables for your script Setup. Actions>List if you need an Action to run regardless of CaveBot, like a safe exori, an auto mana shield and etc.

    You will use the CaveBot>Action if you need something just for the waypoint. Like an action for deposit items, withdraw gold and etc.

    2.1 iBot Functions



    Now you know a little more about lua, you should step into iBot Functions.

    To get started with the iBot functions take a look at the Actions[*] thread and at the basic Lua Script samples thread.

    3 Building a Script
    Last edited by Raphael; 12-21-2012 at 03:33 PM. Reason: While -> while. Remeber Lua is case sensitive.

  2. #2
    Normal User Nightcrawler's Avatar
    Join Date
    Apr 2012
    Posts
    190
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quoted
    0 Post(s)
    Reputation
    16
    Rep Power
    5
    3. Coming soon.

  3. #3
    Normal User idibruxo's Avatar
    Join Date
    Apr 2012
    Location
    aracaju-se
    Posts
    319
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quoted
    0 Post(s)
    Reputation
    12
    Rep Power
    5
    god tutorial

  4. #4
    Normal User blakw's Avatar
    Join Date
    Mar 2012
    Location
    www.blakw.com
    Posts
    817
    Mentioned
    221 Post(s)
    Tagged
    2 Thread(s)
    Quoted
    345 Post(s)
    Reputation
    462
    Rep Power
    10
    Sticky thread.


    ------------------------------------Latest Releases:------------------------------------
    Vocations:
    Darashia Lions Rock
    Oramond Seacrest Serpents X1

    For a better iBot!

    (◣_◢)

  5. #5
    iBot User
    Join Date
    Apr 2012
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quoted
    0 Post(s)
    Reputation
    17
    Rep Power
    5
    Action1:

    What I think:
    If my mana is 60 or more and I'm not on haste then cast haste, end that is all.

    What I should tell to iBot:
    Code:
    Code:
    if mp >= 60 and hasted then
      cast("utani hur")
    end
    I hope u wanted to say

    Code:
    if mp >= 60 and not hasted then
      cast("utani hur")
    end
    Se eu te ajudei, ou se você gostou do meu post clique na estrela do lado de Report, chamado Add Reputation, essa é a melhor forma de agradecimento!
    If i helped you or you lked my post, click in the starts to the left of the Report button, called Add Reputation, this is the best way of thanking me.

  6. #6
    Normal User Nightcrawler's Avatar
    Join Date
    Apr 2012
    Posts
    190
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quoted
    0 Post(s)
    Reputation
    16
    Rep Power
    5
    Haha, yep. Didn't notice that. Ty.

  7. #7
    iBot User
    Join Date
    Feb 2012
    Posts
    85
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quoted
    0 Post(s)
    Reputation
    10
    Rep Power
    5
    Global variables works in actions?

  8. #8
    Normal User Heardy's Avatar
    Join Date
    May 2012
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quoted
    0 Post(s)
    Reputation
    26
    Rep Power
    5
    Thanks Nightcrawler, I completely forgot how to script earlier because I haven't done it since Neo! >.<

  9. #9
    iScripter Eli's Avatar
    Join Date
    Mar 2012
    Posts
    3,764
    Mentioned
    492 Post(s)
    Tagged
    2 Thread(s)
    Quoted
    956 Post(s)
    Reputation
    586
    Rep Power
    10
    I've looking for it!

  10. #10
    iBot User
    Join Date
    May 2012
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quoted
    0 Post(s)
    Reputation
    10
    Rep Power
    5
    What if its another spell than haste like magic shield? Like this?
    if mp >= 60 and not shielded then
    cast("utamo vita")
    end

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •