Popular Post Pug Posted August 29, 2014 Popular Post Share Posted August 29, 2014 (edited) Welcome to my first tutorial. I've seen quite alot of questions round the forums as of late regarding paints and little miss-haps members are having. I'd like to think paints for my script have always been pretty snazzy and informative. Now its time to make everyone's paint a bit more special. I'l be covering some methods that have since been included into the API but i like to calculate them myself as it keeps you're brain active and is generally good coding practice to do as much as you can yourself. All my tutorials are given in laymens terms to help those with no experience. Area's Covered In This Tutorial: Script Running Time So where to start, well maybe you just want to show the time your script runs for? First we need two variables. One to tell us when the script started. We will call this timeBegan. The other variable will be to tell us how long the script has ran for. We shall call this timeRan. First we need to declare these two variables at the top of our script like so: private long timeBegan; private long timeRan; ok so now that is out of the way we need to assign values to these variables. Lets start with timeBegan first. In your onStart() method we need to tell the script that the current time needs to equal our variable so: timeBegan = System.currentTimeMillis(); The code above essentially recording the start time of the script. Now we need to do a short calculation to work out how long our script has been running. It is as simple as the current time minus the time when the script was started. We then store this value in the variable we made earlier called timeRan This will then constantly update as time progresses. Put this at the top of your onPaint() method: timeRan = System.currentTimeMillis() - this.timeBegan; Now we need to display out timeRan variable. To do this we need to use java's drawstring method. We also need to format the time into human readable time. If you didnt the time ran would show in milliseconds and that would get majorly confusing. So under your onPaint() method put this other method: private String ft(long duration) { String res = ""; long days = TimeUnit.MILLISECONDS.toDays(duration); long hours = TimeUnit.MILLISECONDS.toHours(duration) - TimeUnit.DAYS.toHours(TimeUnit.MILLISECONDS.toDays(duration)); long minutes = TimeUnit.MILLISECONDS.toMinutes(duration) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS .toHours(duration)); long seconds = TimeUnit.MILLISECONDS.toSeconds(duration) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS .toMinutes(duration)); if (days == 0) { res = (hours + ":" + minutes + ":" + seconds); } else { res = (days + ":" + hours + ":" + minutes + ":" + seconds); } return res; } the above method will format seconds, minutes & hours into seconds. After copying and pasting the above you will need to import timeUnit else you will get errors, the import should go on line 1 of your script with all the other imports you may be using. import java.util.concurrent.TimeUnit; Now we have our formatting method we now need to display that variable. We do this by using the code below. Add it into your onPaint() method: g.drawString(ft(timeRan), 1, 1); Lets look at what we have above for a second so that you understand it. The two letters ft are relating to the formatting method above. So you are saying format(timeRan). You then have two numbers after that, 1 and 1. these relate to X and Y on the screen. you can find these values by turning on the ' Mourse Position Debug' in the client settings. So now you can display the time your script has ran for, congratulations. To see if you got everything correct, see the full script here: http://pastebin.com/5baWdRuW Xp Gained Ok so now we have time down lets look at something more interesting, how to work out the xp gained for what ever skill you are training. For this we again need to start with three variables, the first gives us the beginning xp of the skill we are training, we shall call this beginningXp we also need a variable to tell us the up to date xp of that skill. We shall call this currentXp. Lastly we need a variable to show the xp that has been gained, we shall call this xpGained Declare them in your variables at the start of the script like so: private int beginningXP; private int currentXp; private int xpGained; Ok so now like we did with time we need assign the starting xp of our skill to the variable beginningXp. We do this by accessing the skill class within the API. The skill class is a really useful addition to our API and i really recommend playing around with it as it can tell you alot about the player. So, we in your onStart() method put the following: beginningXp = skills.getExperience(Skill.RUNECRAFTING); You can replace 'RUNECRAFTING' with what ever skill you are training. Also notice that 'skills' and 'Skill' are different classes which do different things. 'skills is a class which can be used to do such things as get the experince until a level, get the exp, get the level, hover over the skill and numerous other things. 'Skill' is to identify a particular skill such as ATTACK or HITPOINTS. Please also note using the Skill class will require the import as follows: import org.osbot.rs07.api.ui.Skill; Ok so now we need another short calculation in our onPaint() method to work out our current xp like so: currentXp = skills.getExperience(Skill.RUNECRAFTING); the above goes in your onPaint() method just so we are crystal clear. So now we have the xp we started with, and we have the xp which we currently have. We now need to minus one against the other and put it in a drawstring. So first we take one from the other. Put this next bit below our current xp calcluation. xpGained = currentXp - beginningXp; Ok so we have the xp gained equals the current xp minus the beginning xp. Simple yes? good. Now we need to display the variable xpGained in a drawstring. Put the next bit below the last calculation or below your time ran drawstring if you did that bit to. g.drawString("" + xpGained, 1, 1); Above you can see that we have two speech marks. Between these you can put text such as "Xp Gained: " but as i use a image i include the text in that image and its therefore not needed in the drawstring. We also have the xpGained variable in there and also the 1 and 1 again. These as i said above relate to X and Y on screen. Congrats you have xp gained. To see if you got everything correct, see the full script here: http://pastebin.com/MtmTxL2w Showing Levels Ok so now we have a half ok paint. So what about if we want to show our current level in a skill, or the beginning level or how many levels we have gained. Welll i will show all three of these now. So lets start off with some more variables, yay i hear you say. Ok so we need three more variables which you should put at the top of script where the others have gone before. The first is for showing your beginning level, we shall call this ironically enough beginningLevel. Next we need a variable to show the current level, guess what this one is called? yep, currentLevel. Lastly we need a variable to show how many levels we have gained, we shall call this one levelsGained. So declare these like so: (you should now be able to be skipping ahead slightly and declaring them on your own) private int currentLevel; private int beginningLevel; private int levelsGained; Right so now we need to grab the level we had on starting the script much like we did with the Xp calculations, this is similar, so in your onStart() method put: beginningLevel = skills.getStatic(Skill.RUNECRAFTING); You will notice that we are using the 'skills' class once again expect this time we are using getStatic. I found this odd at first as it didnt make sense but you will get used to it. Then you have once again 'Skill'. And again i have used an example of RUNECRAFTING though you will obviously change it to what skill you are wanting the level for. So far we have declared our variables and we have our beginning level. We now need to need to go back into our onPaint() method and assign our currentLevel a value like so: currentLevel = skills.getStatic(Skill.RUNECRAFTING); Again to be crystal clear the above code goes into your onPaint() method. It's exacttly the same code as our beginningLevel variable, the only difference being that this code is called over and over again where as the when we used it in the onStart() method it will only be called once. Now we have out beginningLevel and our currentLevel. You can display these in your onPaint() method if you wish like so: g.drawString("" + beginningLevel, 1,1); g.drawString("" + currentLevel, 1,1); Like i explained above the 1 and 1 stand for X & Y co-ordinates on screen, Now if you want to display how many levels you have gained we will have to do one more simple calculation. That's going to be your current level minus your beginning level. The code below should go above the drawstrings & below to where we assigned values to currentLevel levelsGained = currentLevel - beginningLevel; Lastly we display the value of levelsGained in our paint, by doing the following: g.drawString("" + levelsGained, 1, 1); That's it, you should now have the ability to display your levels in a way that suits you. Some people like to display the levels in a way such as: 1 / 5 ( +4 ) beginning level / current level ( + 4 levels ) To see if you got everything correct, see the full script here: http://pastebin.com/LSEY2SAe Adding Gold Made Ok so this is going to be quite an important one i think, how to calculate your profits and display them correctly. So first thing is first lets declare some more variables. Before we do though this could get a lot more complicated than its going to. I say this because if you for example are runecrafting then you will obviously need to take into account the cost of ess as well which in fact brings your profits down to what they should be. But for the purpose of this particular segment il be keeping it at the basics. We are going to have four variables to declare, the first being costOfItem. You can get this by grabbing the live price from zybez which i will show you how to do in another section of this tutorial. We will also need itemsMade whether this be logs, runes, bows, fish, etc.Thirdly we will be needing gpGained, which will be used to store the value of a calculation. Lastly we need totalGpGained, il explain the use of this later. So declare the above variables at the top of your script like so: private int costOfItem; private int itemsMade; private double gpGained; private double totalGpGained; So now we have those, we are going to assign a value to costOfItem, and like i said above in another section i will show you how to grab the live price but for now we are going to go ahead and assign a random value of 500. So put the following into your onStart() method: costOfItem = 500; So now we have the price of our item but we dont know how many items we have fished, cut, cooked, made. To work this out you would have the following code either in your onMessage() method where by every time the client detects "You cut a log" you add one to the variable ItemsMade or you would add one to the same variable each time you were inside for example the crafting method of your runecrafting script. Either way the code for that is as follows: itemsMade += 1; if you have more than 1 item gained at a time, for example 28 runes per trip, but want it to be accurate you could also use: itemsMade += inventory.getAmount("your Item"); So now we have how many items have been made and how much said item costs. We can now work out the profits! yay. Ok so we will use our variable gpGained to store the value of itemsMade multiplied by the value or itemCost. this is displayed as the following in your onPaint() method: gpGained = itemsMade - costOfItem; Ok so we are making good progress, we have worked out how much gold has been made but as it is at the moment its going to be displayed something like this: Profit Made: 5634545 You dont really want all those annoying numbers not formatted at all do we. So first we are going to divide gpGained by one thousand to give us (using the above example 5634545) would be 5634.545k instead, thats slightly better no? so copy the following code into your onPaint() method and put it below the above code you copied: totalGpGained = gpGained / 1000; Finally we shall be formatting the end result to remove the numbers after the decimal point (using the above example it will then display as 5634k which is what we are after) So copy the following code into your onPaint() method below the above code: DecimalFormat df = new DecimalFormat("#"); g.drawString("" + df.format(totalGpGained) + " k", 1,1); Ok so let me just take a minute to explain the above code so your not like what the actual fuck. Do we have 'DecialFormat' this is doing to remove sections of a integer we dont want, we do this by using the # you see in the top line. So putting just the one # will mean that the formatting will remove everything after the decimal point. If you wanted to display an integer to one decimal point you would put #.# two decimal places would be #.## So you get the picture. Moving onto the second line we have our drawString again, we then have df.format which is refering to line one where you see where 'df' has been declared much like you would a variable. the part between the brackets in this case totalGpGained is whats going to be formatted. We then have a text string " k" and your 1 and 1 which are the X and Y co-ordinates again. We now have our formatted total gold made, congratulations. To see if you got everything correct, see the full script here: http://pastebin.com/bGQH9mT2 Adding Gold Made Per Hour So to follow on from the above segment we are going to work out profit made per hour. I obviously recommend reading the above section on working out Gold Made before using this section. Ok so first we need to declare another two variables. the first is gpPerHour which is going to store the value of the current time minus when the script started which we then divide by gpGained and lastly divide that by 3600000. A little complicated i know but once you see it below it will be easier to understand. The second variable is totalGpPerHour, this is going to be the value of gpPerHour divided by 1000. So put the following at the top of your script where your variables have been going: private int gpPerHour; private int totalGpPerHour; Next we need to put the following into your onPaint() method above the formatting segment: gpPerHour = (int)(gpGained / ((System.currentTimeMillis() - timeBegan) / 3600000.0D)); This is the long calculation i spoke of above. I hope it is now slightly more clear than it was when i explained it, if not dont worry alls you need to know is that calculation gives you the gp made per hour in raw un-formatted numbers. You also need to have the timeBegan in your code from the first segment of this tutorial when we worked out how to display the amount of time our script has been running. We will now go on to format that value as we did in the previous segment. So first we want to divide gpPerHour by 1000. Copy and paste the following into your onPaint() method below the previous gpPerHour calculation: totalGpPerHour = gpPerHour / 1000; Lastly we can now remove the numbers after the decimal place and input that value into our drawString, place the following into your onPaint method below the last drawString of TotalGpMade: g.drawString("" + df.format(totalGpPerHour) + " k/hr", 1, 1); Note you dont need to declare the df.format part again as its been used in the last segment. Your paint should now display gold made per hour correctly. Congrats. To see if you got everything correct, see the full script here: http://pastebin.com/URD1bvsx Adding a background Image Ok so now we have the basics id like to add a little more depth to the tutorial. We have some numbers displayed and basic stats about our script so now we need a snazzy background image to go behind this text. So your first port of call is one of two places. The image editor of your choice (Photoshop, fireworks, paint, illustrator to name but a few) or you can go to the graphics section of the forum and request a paint background image for yourself. Alot of our members will be more than happy to make one for you im sure. Now i like to make my own because i can then tweak it at my own leisure. So lets start off basic and say we have our background image done in paint its a nice colour and you have the font all set out far enough apart that you can put the text next to it via our friend drawString. An example would be something like this: Above you can see my own paint which i made a few months ago. I achieved this by starting from the back with the meshy grey colour then making the border or orange with black glow and then started adding in the text. Anyway, so you have your image done. First thing is first we need to upload this image to a image hosting website online. I use www.postimg.org because its free and reliable. So upload your image and get the direct link to it. We will first need to import the image from the net to our script so we assign the image to a variable. Put this at the top where your other variables have been going: private final Image bg = getImage("www.linkToYourImage.com/image.png"); After pasting this in you will get an error but dont worry its because we havent added a method to grab the image from the internet yet. Add the following method to the script below your onPaint() method. Note i said below not inside it. Make sure its still inside the last } though private Image getImage(String url) { try { return ImageIO.read(new URL(url)); } catch (IOException e) {} return null; } Ok so now we have the method to grab images from the internet and we have our image stored in a variable ready to be shown. Now we just have to put this variable into use in our onPaint() method. So add the following line into your onPaint() method: g.drawImage(bg, 1, 1, null); Looking at the above code we have 'bg' which is out variable that holds the image, then we have once again 1 and 1 which are the X and Y co-ordinates on screen where you want your picture to be displayed note that the x and y should be the top left corner of the image. After you have that you are done it really was that simple. Congrats, check out the sample code below to make sure you have everything in the right place. To see if you got everything correct, see the full script here: http://pastebin.com/Ry4A7rcx Percent To Next Level Now this is where those of you that have never really scripted before may start to struggle. This is going to get a little technical and long so if you are ready lets go. So first like the other segments we are going to declare some new variables. Lets declare those at the top of your script: private int currentXp; private int currentLevel; private double currentLevelXp; private double nextLevelXp; private double percentTNL; Some of these you will have seen in previous segments, others maybe not. CurrentXp & currentLevel are self explanatory, currentLevelXp is new to you. We will assign a value to this variable from a XP table which i will provide shortly. We also have nextLevelXp which is again going to have a value assigned from the XP table. Lastly we have our end goal variable percentTNL. this is going to be a value from 1-100. As i said above here is the XP Table: final int[] XP_TABLE = { 0, 0, 83, 174, 276, 388, 512, 650, 801, 969, 1154, 1358, 1584, 1833, 2107, 2411, 2746, 3115, 3523, 3973, 4470, 5018, 5624, 6291, 7028, 7842, 8740, 9730, 10824, 12031, 13363, 14833, 16456, 18247, 20224, 22406, 24815, 27473, 30408, 33648, 37224, 41171, 45529, 50339, 55649, 61512, 67983, 75127, 83014, 91721, 101333, 111945, 123660, 136594, 150872, 166636, 184040, 203254, 224466, 247886, 273742, 302288, 333804, 368599, 407015, 449428, 496254, 547953, 605032, 668051, 737627, 814445, 899257, 992895, 1096278, 1210421, 1336443, 1475581, 1629200, 1798808, 1986068, 2192818, 2421087, 2673114, 2951373, 3258594, 3597792, 3972294, 4385776, 4842295, 5346332, 5902831, 6517253, 7195629, 7944614, 8771558, 9684577, 10692629, 11805606, 13034431, 200000000 }; put the above method below your variables and above the onStart() method. The xp table probably isnt needed anymore im not sure but i like it. Basically what it does is provide all the xp for each level 1-99. This will help us calculate percent until the next level. Once we have these things we can start assigning values to the variables above. First is currentXp put this at the top of your onPaint() method: currentXp = skills.getExperience(Skill.RUNECRAFTING); Next we need to assign a value to currentLevel, i have used the RUNECRAFTING skill as an example but again you dont have to, you would apply the skill that suits your needs, so put this under the above code ^ currentLevel = skills.getStatic(Skill.RUNECRAFTING); Now we are going to grab data from the XP table for our current level, i have used the RUNECRAFTING skill as an example but again you dont have to, you would apply the skill that suits your needs put this under the above code ^ currentLevelXp = XP_TABLE[currentLevel]; Now to get the xp for the next level, put this under the above code ^ nextLevelXp = XP_TABLE[currentLevel + 1]; Now we can make the calculation to get percent until next level, put this under the above code ^ percentTNL = ((currentXp - currentLevelXp) / (nextLevelXp - currentLevelXp) * 100); Great we have our percentTNL value. Now we need to format that to one decimal place and then display it on screen using our drawString. So put the following under the above code ^ DecimalFormat df = new DecimalFormat("#.#"); g.drawString("" + df.format(percentTNL), 1, 1); Ok so if you have followed the above segments you will already be familiar with the formatting code. I have chosen one decimal place but that is up to you, maybe you will just want 70% instead of 70.5% The choice is yours. Well that was alot easier to explain than i thought it would be. Congrats if you stuck with it. To see if you got everything correct, see the full script here: http://pastebin.com/kPgMUvpt Time Until Next Level OK so now we are beginning to get into the segments of this tutorial where there is alot of variables required to finish the calculation i apologise in advance haha. So first we need to once again declare some more variables. Like so: private long timeBegan; private int xpGained; private int xpPerHour; private int currentXp; private int currentLevel; private int beginningXp; private double nextLevelXp; private double xpTillNextLevel; private long timeTNL; Thanks to good naming i believe all the variables above are easily read and understood if you have got this far. I will go through each one in more details as we assign values. We will again be needing the XP table. Put the following code below the variables above: final int[] XP_TABLE = { 0, 0, 83, 174, 276, 388, 512, 650, 801, 969, 1154, 1358, 1584, 1833, 2107, 2411, 2746, 3115, 3523, 3973, 4470, 5018, 5624, 6291, 7028, 7842, 8740, 9730, 10824, 12031, 13363, 14833, 16456, 18247, 20224, 22406, 24815, 27473, 30408, 33648, 37224, 41171, 45529, 50339, 55649, 61512, 67983, 75127, 83014, 91721, 101333, 111945, 123660, 136594, 150872, 166636, 184040, 203254, 224466, 247886, 273742, 302288, 333804, 368599, 407015, 449428, 496254, 547953, 605032, 668051, 737627, 814445, 899257, 992895, 1096278, 1210421, 1336443, 1475581, 1629200, 1798808, 1986068, 2192818, 2421087, 2673114, 2951373, 3258594, 3597792, 3972294, 4385776, 4842295, 5346332, 5902831, 6517253, 7195629, 7944614, 8771558, 9684577, 10692629, 11805606, 13034431, 200000000 }; We can now start to assign values to our variables, firstly lets assign the current time when starting the script to timeBegan. Put the following code in your onStart() method: timeBegan = System.currentTimeMillis(); Next we assign beginningXp a value by using the following code. Put it below the above code ^ in your onStart() method beginningXp = skills.getExperience(Skill.RUNECRAFTING); we have to assign a value of zero to timeTNL on start also so that you dont get and bunch of random number upon starting your script, put the following code below the above code in your onStart() method: timeTNL = 0; Now we have the variables set onStart() we can proceed to fill out the rest that go in the onPaint() method. First we assign the current xp for your chosen skill, I have chosen RUNECRAFTING but of course you can change that to what you need. put this in your onPaint() method: currentXp = skills.getExperience(Skill.RUNECRAFTING); next we assign the current level, put the following below the above code ^ currentLevel = skills.getStatic(Skill.RUNECRAFTING); next we work out the xpGained by subtracting the beginning xp from the current xp, put the following below the above code ^ xpGained = currentXp - beginningXp; We also need a xp per hour calculation which is very similar to the gpPerHour which we used in a previous segment, put the following code in your onPaint() method below the above code ^ xpPerHour = (int)( xpGained / ((System.currentTimeMillis() - this.timeBegan) / 3600000.0D)); Next we need to assign a value to the variable nextLevelXp. We get this from the xp table once again, put the following code below the code above ^ nextLevelXp = XP_TABLE[currentLevel + 1]; We also need the xp until the next level, which is a key part of the final calculation, put the following below the above code ^ xpTillNextLevel = nextLevelXp - currentXp; Now we can work out the value of time until the next level. First we need to add a small if statement into our onPaint method to stop the script churning out a screen full of random numbers, put the following below the above code: if (xpGained >= 1) { timeTNL = (long) ((xpTillNextLevel / xpPerHour) * 3600000); } Now we can display our time until next level with time formatting, first you will need to put the following method after your onPaint() method if you havent added it already : private String ft(long duration) { String res = ""; long days = TimeUnit.MILLISECONDS.toDays(duration); long hours = TimeUnit.MILLISECONDS.toHours(duration) - TimeUnit.DAYS.toHours(TimeUnit.MILLISECONDS.toDays(duration)); long minutes = TimeUnit.MILLISECONDS.toMinutes(duration) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS .toHours(duration)); long seconds = TimeUnit.MILLISECONDS.toSeconds(duration) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS .toMinutes(duration)); if (days == 0) { res = (hours + ":" + minutes + ":" + seconds); } else { res = (days + ":" + hours + ":" + minutes + ":" + seconds); } return res; } Now to display the time till next level in our drawString, put this within your onPaint method: g.drawString("" + ft(timeTNL), 1,1); And there we go you have done it, abit long winded i know but worth it congratulations. To see if you got everything correct, see the full script here: http://pastebin.com/RtbL2xCK Will add more later Like this post if it helped Edited August 29, 2014 by Pug 24 1 Quote Link to comment Share on other sites More sharing options...
BurritoBug Posted August 29, 2014 Share Posted August 29, 2014 I thought i was going to learn about drawing in paint 5 Quote Link to comment Share on other sites More sharing options...
Pug Posted August 29, 2014 Author Share Posted August 29, 2014 I thought i was going to learn about drawing in paint in the scripting section? lawlll you funny ;) 1 Quote Link to comment Share on other sites More sharing options...
Hayden Posted August 29, 2014 Share Posted August 29, 2014 Great tutorial! Looks like you put some time into this. Quote Link to comment Share on other sites More sharing options...
BurritoBug Posted August 29, 2014 Share Posted August 29, 2014 in the scripting section? lawlll you funny I clicked on it from recent topics, so i couldn't see which section it was in Quote Link to comment Share on other sites More sharing options...
Pug Posted August 29, 2014 Author Share Posted August 29, 2014 Great tutorial! Looks like you put some time into this. thanks Hayden, i plan on adding more content to the first post over the coming hours/days will also add example scripts to each section so that people can see it all in the right place. I clicked on it from recent topics, so i couldn't see which section it was in haha jokingggg dont worry all good ^_^ Quote Link to comment Share on other sites More sharing options...
Fay Posted August 29, 2014 Share Posted August 29, 2014 It is so clean! Amazing job on the tutorial. I was never one for a flashy interface but this make me REALLY want to build one . Quote Link to comment Share on other sites More sharing options...
Pug Posted August 29, 2014 Author Share Posted August 29, 2014 It is so clean! Amazing job on the tutorial. I was never one for a flashy interface but this make me REALLY want to build one . thanks, have a go at it, let me know how you get on Quote Link to comment Share on other sites More sharing options...
thepecher Posted August 30, 2014 Share Posted August 30, 2014 Nice informative tut pug! Maybe add in buttons, percentage to level bars etc..? just a thought Quote Link to comment Share on other sites More sharing options...
Pug Posted August 31, 2014 Author Share Posted August 31, 2014 Nice informative tut pug! Maybe add in buttons, percentage to level bars etc..? just a thought hey pecher, thanks. Yep guna add it all eventually wrote all thats there in one day and since got snowed under with my rc script will add all that you see in my paints later on Quote Link to comment Share on other sites More sharing options...
Botre Posted August 31, 2014 Share Posted August 31, 2014 (edited) Very nice guide. However, having many recurring calculations in your onPaint could become unnecessarily expensive, I recommend creating separate looping threads with a custom loop times holding the values the paint should then draw . It does make a difference in performance cost to make the script calculate the data to be painted every 5 seconds instead of every lets say 500ms, and from a consumer point of view it doesn't make a huge difference because most of the time they aren't even around to watch that data (considering botting is essentially an AFK activity). Performance is key! Edited August 31, 2014 by Botrepreneur Quote Link to comment Share on other sites More sharing options...
thepecher Posted August 31, 2014 Share Posted August 31, 2014 Very nice guide. However, having many recurring calculations in your onPaint could become unnecessarily expensive, I recommend creating a separate looping thread with a custom loop time holding the values the paint should then draw (this thread would also go to sleep whenever the paint is hidden). It does make a difference in performance cost to make the script calculate the data to be painted every 5 seconds instead of every lets say 500ms, and from a consumer point of view it doesn't make a huge difference because most of the time they aren't even around to watch that data (considering botting is essentially an AFK activity). Performance is key! Never actually though of that but just adding a sleep in onPaint would have the same effect right while being a bit simpler? Quote Link to comment Share on other sites More sharing options...
Botre Posted August 31, 2014 Share Posted August 31, 2014 Never actually though of that but just adding a sleep in onPaint would have the same effect right while being a bit simpler? Multiple threads for different paint data is the best way to go imo, for example: you might want to have real-time display of the run time which would be relatively cheap in terms of processing but only a once every 5 seconds update of your experience tracker(s) which would be more costly. But if you don't mind applying the same performance cost restrictions to all calculations, then pausing your onPaint could do just that indeed ^^ 1 Quote Link to comment Share on other sites More sharing options...
Pug Posted August 31, 2014 Author Share Posted August 31, 2014 thats some clever shit guys, interesting. Quote Link to comment Share on other sites More sharing options...
Swizzbeat Posted September 29, 2014 Share Posted September 29, 2014 (edited) Do NOT add a sleep in the onPaint method OSBot subclasses the Canvas (specifically to override the getGraphics method) which allows us to paint directly over the game image buffer. Adding a sleep will not only make your paint update slower but also the game frame rate. Edited September 29, 2014 by Swizzbeat 2 Quote Link to comment Share on other sites More sharing options...