Results 1 to 5 of 5

Thread: Making my own script... tutorial?

  1. #1
    Normal User
    Join Date
    Feb 2013
    Posts
    17
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quoted
    0 Post(s)
    Reputation
    12
    Rep Power
    4

    Exclamation Making my own script... tutorial?

    I'm trying to learn how to make my own scripts.. obviously its not easy... can anyone point me to a script maker for dummys or point me on where to get started?

  2. #2
    Banned
    Join Date
    May 2012
    Posts
    1,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quoted
    0 Post(s)
    Reputation
    127
    Rep Power
    0
    The best starting point is by looking at other scripts made by people. Check out the free script section to look at people's scripts. Use the actions they use and put it on yours

    “For the things we have to learn before we can do them, we learn by doing them.”
    ― Aristotle

  3. #3
    Normal User
    Join Date
    Feb 2013
    Posts
    17
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quoted
    0 Post(s)
    Reputation
    12
    Rep Power
    4
    I copied and pasted some actions for the bp part, and when i get to that part in my script it doesn't seem to open it or work really..

  4. #4
    Normal User ThiagoMaster's Avatar
    Join Date
    Jan 2013
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quoted
    0 Post(s)
    Reputation
    11
    Rep Power
    4
    That's probably because you have to set the bps names on the setup...

    Really, if you want to do a script from 0 you need to do a huge digging at the forum to learn everything, it will take time..

  5. #5
    Normal User
    Join Date
    Jan 2013
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quoted
    0 Post(s)
    Reputation
    11
    Rep Power
    4
    Though there is no mass documentation for this software, this post is very helpful on the methods/functions you can include in your scripts.

    http://www.tibiaibot.com/forum/showt...-and-Functions

    How does a function work?

    A function for all intents and purposes is a shortcut so you do not have to write the same code over and over again. Let's say I want to create a waypoint that is at the mouth of a cave. Before I go into this cave I want to make sure all my BPs are open and in the right order. Well in iBot there is a function called openitem(), if you go to the link I have posted before this paragraph you can see that this function is listed there and it says..

    openitem(string item, optional string locationfrom, optional bool new, optional integer index) [void]

    The first part "openitem" is the name of the function, if you want to use this function you have to "call" it by using it's name.

    Next, you'll see a parentheses -> ( ----- What is contained within () are called arguments(I think...I get my languages nomenclature backwards sometimes), I digress. These "arguments" are what the function needs in order to perform the task that you are asking of it, i.e. you cannot open an item without knowing which item to open right?

    string item
    is a variable. Just like in math a variable is an unknown value. x + 5 = 10, therefore the variable x is equal to 5. The word "string" is reserved as a "special word" in this language. That means that if you want to declare you own variable you cannot name it "string", as this would conflict. An example of a "string" would be "Red Backpack". If you notice in some scripts that you download you can go to the Settings\\Actions\\Setup and browse through the backpack setup for the script and you will see something like this. MAIN_BACKPACK = 'Green Backpack' -- Using this example "MAIN_BACKPACK" is a variable, this variable is also a string because we are setting it equal to something in between quotes. 'Green Backpack'[/B] Now that the iBot developers have made the script editor more like a programming text editor you will notice certain keywords appear in different colors (thank you by the way iBot team!). Anything surrounded by quotes will be RED.
    item is the variable itself, so this part "string item" simply means that the first value you pass into this function needs to be the item's name

    optional string locationfrom
    The first word you notice here is optional, this means that you DO NOT have to supply a variable for this if you do not want to.
    string is the same as before, defining that the value that is going to be passed in for locationfrom will be a string.
    locationfrom is again just a variable, just like before with item.

    optional bool new
    Again you will notice that this says optional as well, meaning you do not have to supply a value for this if you do not want to.
    bool
    Is another specially reserved word for this language, put simply this data type can only be two things, true or false. For instance if I had a variable
    that was used to represent whether or not my character was standing in a protection zone, I would use a bool for this, because you are either IN a protection zone -- TRUE, or you are NOT IN a protection zone -- FALSE. (Bool is a shortened name for boolean, some languages use boolean some use bool don't ask why)
    new
    You guessed it, this is just a variable that is used to tell YOU what you are supposed to "pass" to this function when you "call" it.
    This parameter is the same thing as Control + Right Clicking a backpack (if you are on classic control) and clicking open in a new window. Basically when you use this function it allows you to say TRUE -- I want to open this backpack/item in a new window, FALSE -- I just want to open this backpack/item in the same window as the backpack/item it's contained in, or you can simply not pass in a value for this at all.

    optional integer index
    Okay I have to plead a little ignorance on this argument, because I'm not sure what the "index" refers to here. Yet again this is an optional value, meaning again that you do not have to specify this when you call the method if you do not want to.
    integer
    Could not be simpler, it is simply a number. However it is very important to understand something here. Look at this example:

    VARIABLE_A = 123
    VARIABLE_B = "123"
    VARIABLE_A and VARIABLE_B are NOT the same thing. A is set equal to an integer because we are simply putting a number on the other side of the equals sign. However, B has quotes surrounding it's numbers. Therefore VARIABLE_B is NOT A NUMBER(called an int or integer) it is a string because it is surrounded by quotes.

    index
    Hopefully a moderator can fill in this blank. I have not had to use this argument yet though, so maybe a mod can fill this in.


    Ok now that's out of the way let's say this is our backpack setup. On your back you are carrying a Brocade Backpack, inside your main backpack you are carrying your supplies in a Purple Backpack, and inside your main backpack you are also carrying empty backpacks for gold that are Golden Backpacks. So in order to open your backpack you can create a new waypoint that is in 'action'. Once you create this waypoint you can write code in the white box that appears when you right-click on the action waypoint inside the iBot window. So lets type our first function out.

    openitem("Brocade Backpack", "back", true)

    Now when iBot runs this script it sees that you are calling the openitem function and says, "Ok the first thing I need is...'string item'". Therefore, the first value we pass in is "Brocade Backpack". Now technically since all the other arguments for this function are optional we don't have to pass anything else, i.e. openitem("Brocade Backpack"), but I like to specify WHERE this item that I'm opening is; just so I don't have to worry about my script messing up. When you get the hang of it you will develop your own coding style. After item the next value that this function is expecting is locationfrom, for that we passed in "back". If you look at the link I posted above you can see that every equipment slot on your character has a name, and they are listed on that page. Not surprisingly the place where your backpack is equipped is called........back. -> "back" (which is what we pass after the item name). Finally, the last value we pass is TRUE which represents the bool value that this function is expecting. (A note: Technically you would not have to tell it to open your main backpack in a new window, because your mainbackpack is not in anything else so when you right click it in-game it is always going to open it in a new window, but think of it as a good habit to get into.) So now we have our main backpack open, now we just need our supplies and gold backpacks open. However, sometimes when you open several backpacks in a row your code will execute too quickly and might skip an openitem command because it cannot open them as quickly as the code is executing. So we can use an iBot function called wait(). Wait simply tells iBot to stop cavebot for a certain amount of time, it is measured in milliseconds so if we say, wait(1000), that tells the bot to stop executing for 1 second. That 1 second is plenty of time to pause in between opening backpacks. So far our code looks like this.

    openitem("Brocade Backpack", "back", true)
    wait(1000)

    Now to open the supplies backpack.

    openitem("Purple Backpack", "Brocade Backpack", true)

    Notice here that we said the item we want to open is the Purple Backpack, we also told the function that the Purple Backpack is located inside our Brocade Backpack, and we have also passed in true for opening this backpack in a new window. This time opening this backpack in a new window is important because we want to keep our main backpack open, but we also want to have our supplies backpack open too. This is where passing in true will make it open this backpack in a new window. Once again we will make it wait before opening the other backpack.

    openitem("Brocade Backpack", "back", true)
    wait(1000)
    openitem("Purple Backpack", "Brocade Backpack", true)
    wait(1000)

    Then we simply repeat this command, but change the values passed in for the gold backpacks.

    openitem("Golden Backpack", "Brocade Backpack", true)

    Now one final function that is helpful is resizewindows(), if you look at the post at that link, you will see that this function resizes all open windows in your game client. So if you have a lot of stuff in your main backpack, when it opens it will take up a lot of room until you shrink it, this function will automatically shrink all open windows to the smallest size for you.

    So our complete action script will look like this:

    openitem("Brocade Backpack", "back", true)
    wait(1000)
    openitem("Purple Backpack", "Brocade Backpack", true)
    wait(1000)
    openitem("Golden Backpack", "Brocade Backpack", true)
    wait(1000)
    resizewindows()

    This post was originally going to be just the link to the functions and variables post, but somehow it turned into this :P I hope you find this helpful, as it did not take a short amount of time to write. Also, any mods that read this...I am fairly experienced at writing scripts for iBot, but I am more used to writing in JAVA so if I got something wrong to do with the lua context or worded something incorrectly feel free to right me below. Also, I am interested in hearing what the index parameter is used for as well.

Posting Permissions

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