-
Posts
2314 -
Joined
-
Last visited
-
Days Won
6 -
Feedback
100%
Everything posted by Explv
-
An alternative would be to use OSBot's Event with the async option set: Event customEvent = new Event() { @Override public int execute() throws InterruptedException { return 0; } }; customEvent.setAsync(); execute(customEvent);
-
I will add some fail safes, thanks for the report
-
I'm confused as to why you need a break condition. Could you try to explain it more clearly? What is the InteractionEvent(path) for? What exactly is your use case here, what are you trying to achieve? There is a probably a simpler way to achieve it
-
The performance impact is insignificant. Especially as we're talking about OSBot scripts here. In my opinion two functions is much better for readability and usability. Performance should not be a consideration whatsoever here. And you wouldn't have two functions with 100 lines of code, the functionality shouldn't be duplicated, it would look like: public boolean interact(String itemName, String action) { // Generate x, y point interact(itemName, action, generatedX, generatedY); } public boolean interact(String itemName, String action, int x, int y) { // Do interaction stuff } Generally you want to keep functions as simple as possible, a good rule to follow is that a function should do just one thing. If you only had a single function, it would be doing two things, generating a random point, and then interacting at that point. By defining separate functions it communicates more clearly what the intention is when you are making a call. For example: interact("Knife", "Use", -1, -1); It's not clear what the intention is here, you would need to go to the API docs, or look at the function definition to figure out what -1, -1 does. If you saw: interact("Knife", "Use"); The intention is clear, the "Use" interaction will be performed on the knife.
-
You don't need to call setModel after adding elements to the model. Just set the model once like so: ListModel<String> model = new DefaultListModel<>(); JList<String> whitelist = new JList<>(model); model.addElement("Whatever"); Event handlers are fine where you have put them. However, talking purely from a style perspective, the constructor should be the first function in the class, and the member variables should be above the constructor.
-
1. DO NOT use absolute positioning (null layout), it's harder to maintain, and can easily looked fucked up on different systems with different configurations. 2. DO NOT use GUI designers/builders, they produce bad code which is hard to maintain, and often is not the best way to build the GUI. You also cannot achieve more advanced things if you're using a builder. Another good reason to do it "by hand", is so that you actually know what you are doing, you will learn nothing from a GUI builder. 3. Look at https://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html, by combining these layout managers in nested JPanels you can easily achieve your desired GUI Here is an example using the GridBagLayout: https://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html#gridbag import javax.swing.*; import javax.swing.border.EmptyBorder; import java.awt.*; import static java.awt.GridBagConstraints.HORIZONTAL; import static java.awt.GridBagConstraints.NONE; public class GUI { private final JFrame jFrame; public GUI() { jFrame = new JFrame("Pigeon GUI"); JPanel mainPanel = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); jFrame.setContentPane(mainPanel); mainPanel.setBorder(new EmptyBorder(10, 10, 10, 10)); JLabel titleLabel = new JLabel("Pigeon GUI"); gbc.gridx = 0; gbc.gridy = 0; gbc.gridwidth = 4; gbc.insets = new Insets(0, 10, 20, 10); mainPanel.add(titleLabel, gbc); JLabel nameLabel = new JLabel("Name:"); gbc.gridx = 0; gbc.gridy = 1; gbc.gridwidth = 1; gbc.insets = new Insets(0, 0, 0, 5); mainPanel.add(nameLabel, gbc); JTextField nameField = new JTextField(20); gbc.gridx = 1; gbc.gridy = 1; gbc.gridwidth = 1; gbc.insets = new Insets(0, 0, 0, 0); mainPanel.add(nameField, gbc); JScrollPane whitelistScrollPane = new JScrollPane(); JList<String> whitelist = new JList<>(); whitelistScrollPane.add(whitelist); gbc.gridx = 2; gbc.gridy = 1; gbc.ipadx = 200; gbc.ipady = 200; gbc.gridwidth = 2; gbc.insets = new Insets(10, 10, 0, 10); mainPanel.add(whitelistScrollPane, gbc); JButton insertButton = new JButton("Insert"); gbc.gridx = 2; gbc.gridy = 2; gbc.fill = HORIZONTAL; gbc.weightx = 0.5; gbc.gridwidth = 1; gbc.ipadx = 0; gbc.ipady = 0; gbc.insets = new Insets(10, 10, 0, 10); mainPanel.add(insertButton, gbc); JButton deleteButton = new JButton("Delete"); gbc.gridx = 3; gbc.gridy = 2; gbc.fill = HORIZONTAL; gbc.weightx = 0.5; gbc.gridwidth = 1; gbc.ipadx = 0; gbc.ipady = 0; gbc.insets = new Insets(10, 10, 0, 10); mainPanel.add(deleteButton, gbc); JButton startButton = new JButton("Start"); gbc.gridwidth = 4; gbc.gridx = 0; gbc.gridy = 3; gbc.fill = NONE; gbc.insets = new Insets(20, 10, 0, 10); mainPanel.add(startButton, gbc); jFrame.pack(); // resize the JFrame so that all the components are at or above their preferred sizes jFrame.setLocationRelativeTo(null); // center the gui on screen } public void open() { jFrame.setVisible(true); } public void close() { jFrame.setVisible(false); jFrame.dispose(); } public static void main(String[] args) { SwingUtilities.invokeLater(() -> new GUI().open()); } } Here is another example purely using nested JPanels with BorderLayout and FlowLayouts. import javax.swing.*; import javax.swing.border.EmptyBorder; import java.awt.*; public class GUI { private final JFrame jFrame; public GUI() { jFrame = new JFrame("Pigeon GUI"); // We want to split the GUI into three sections, title at the top, inputs in the middle, start button at the bottom // To do this we use a BorderLayout: https://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html#border JPanel mainPanel = new JPanel(new BorderLayout()); mainPanel.setPreferredSize(new Dimension(500, 400)); jFrame.setContentPane(mainPanel); // use this panel as the main content panel for the GUI // Create a JPanel to contain the title. Here we use a FlowLayout https://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html#flow // We set the alignment to FlowLayout.CENTER so the title appears in the middle. JPanel titlePanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); titlePanel.setBorder(new EmptyBorder(5, 5, 5, 5)); // We give the JPanel an empty border of 5px, so that there is some padding JLabel titleLabel = new JLabel("Pigeon GUI"); titlePanel.add(titleLabel); mainPanel.add(titlePanel, BorderLayout.NORTH); // Add the title to the North side of the main panel // Create a JPanel to contain the main GUI inputs (textfield and whitelist) JPanel inputsPanel = new JPanel(new BorderLayout()); // Create a JPanel to contain the name label and name input JPanel namePanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); namePanel.setBorder(new EmptyBorder(10, 10, 10, 10)); JLabel nameLabel = new JLabel("Name:"); namePanel.add(nameLabel); JTextField nameField = new JTextField(20); namePanel.add(nameField); inputsPanel.add(namePanel, BorderLayout.WEST); // Create a JPanel to contain the whitelist and buttons JPanel whitelistPanel = new JPanel(new BorderLayout()); whitelistPanel.setBorder(new EmptyBorder(10, 10, 10, 10)); inputsPanel.add(whitelistPanel, BorderLayout.EAST); // Create a JScrollPane to contain the whitelist // Add the JScrollPane to the whitelistpanel above JScrollPane whitelistScrollPane = new JScrollPane(); JList<String> whitelist = new JList<>(); whitelistScrollPane.add(whitelist); whitelistPanel.add(whitelistScrollPane, BorderLayout.CENTER); // Create a JPanel to contain the whitelist buttons JPanel whitelistButtons = new JPanel(new FlowLayout(FlowLayout.CENTER)); JButton insertButton = new JButton("Insert"); whitelistButtons.add(insertButton); JButton deleteButton = new JButton("Delete"); whitelistButtons.add(deleteButton); whitelistPanel.add(whitelistButtons, BorderLayout.SOUTH); mainPanel.add(inputsPanel, BorderLayout.CENTER); // Add the inputs panel to the centre of the main panel // Crete a JPanel to contain the start button JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); buttonPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); JButton startButton = new JButton("Start"); buttonPanel.add(startButton); mainPanel.add(buttonPanel, BorderLayout.SOUTH); // Add the button panel to the south of the main panel jFrame.pack(); // resize the JFrame so that all the components are at or above their preferred sizes jFrame.setResizable(false); jFrame.setLocationRelativeTo(null); // center the gui on screen } public void open() { jFrame.setVisible(true); } public void close() { jFrame.setVisible(false); jFrame.dispose(); } public static void main(String[] args) { SwingUtilities.invokeLater(() -> new GUI().open()); } }
-
The player names in the widgets probably have non-breaking spaces instead of regular spaces: if (friend.getMessage().replace('\u00A0', ' ').equals(name)) Or at the top of your function: name = name.replace(' ', '\u00A0');
-
Are any of you use java reflection in your scripts?
Explv replied to Pegasus's topic in Scripting Help
- -
Adding an ActionListener to a text field isn't going to work (you would need to use a DocumentListener, but that would be ugly as hell and unnecessary) The better way to approach it would be to get the text from the text field when the user clicks start. startButton.addActionListener(e -> chat = txtnameOfNpc.getText()); Your GUI code all kinds of fucked up though
-
That sounds like a case where you have a really, really bad regex pattern, which was identified to be a performance bottleneck, and was optimised. It doesn't mean you should avoid regex everywhere. It seems pretty weird that you would be doing such an operation on page load anyway. 50ms was just a number I pulled out of thin air, and whether or not 50ms is a long time depends on the application. I work on systems that load millions of lines of data every day, and take hours to complete. If I write a regex pattern that is run once and takes 1 second to complete (which is pretty uncommon), the performance of it is irrelevant to the overall performance of the system. If a regex is taking 1 second for a simple operation, then yes, you should probably use something else, or investigate whether there is a better way to write the pattern. But it really isn't very common that a regex pattern takes 1 second to run on a single input (unless that input is absolutely gigantic) Anyway, you do you. I'm just a big fan of maximizing readability first, and optimizing later
-
Never prematurely optimise. In the majority of use cases it is absolutely preferred for someone to use a simple, succinct regex pattern, rather than write x lines of code. The x lines of code might execute 50ms faster, but who cares, I would rather read the code faster. I would only use something other than regex when I *know*, through profiling or through common sense, that removing it would result in a noticeable impact in overall run time. You can use regex to search for patterns in millions of strings, and the performance will still be great. It really depends on the pattern you are using, and the size of the input. Whether to use regex or not should be decided on a case-by-case basis.
-
One tip for when you are learning is to just use a site like https://regex101.com/ instead of using a programming language. It's faster to change your pattern, you can see the output more clearly, and can easily tell what's going wrong. As for tutorials... let me google that for you... ? https://medium.com/factory-mind/regex-tutorial-a-simple-cheatsheet-by-examples-649dc1c3f285 https://regexone.com/ https://www.regular-expressions.info/tutorial.html https://www.rexegg.com/ https://ryanstutorials.net/regular-expressions-tutorial/ http://www.vogella.com/tutorials/JavaRegularExpressions/article.html Regex for basic strings is trivial, and is clearly explained in the thousands of tutorials online..
-
Well firstly @trainux, don't check if getDialogues().inDialogue(), because as you said yourself, the player is always in a dialogue. Whenever you are talking to an NPC on the island the "Click here to continue" / "Click to continue" widget will be visible. So just check for that instead. Just look at my open source script https://github.com/Explv/Tutorial-Island
-
Just store the NPC as a global variable so you can access it later.
-
Make them all non-static, except for constants, which you can leave as static, but you should also make them final. There's very rarely a good reason to be using static, and it just causes a lot of pain.
-
Updated my answer to fix this issue.
-
It's deprecated, you shouldn't use it, and it doesn't make any sense to create a World instance yourself. To determine if a world is PVP it just checks the activity String that you provide. Like mentioned in the other post you should use the widgets from the world switcher, or find a different solution.
-
Updated to latest version (now includes Slepe)
-
Depends what she's into. GTA is a game that usually most people like, you can just fuck around without having to follow strict game rules or anything. If she wants cartoony stuff, you could pick up a switch/wii and get mariokart / other mario games / zelda / whatever.
-
I'm aware of this issue, it's first on my list of things to fix. Will take a look when I have time
-
Why do people keep posting this shit here. This section is supposed to be for help with writing scripts, not for script ideas. Someone also made this thread a couple of days ago, go look there instead of posting a new one
-
Will take a look, thanks for the report. Yeah thieving is pretty borked at the moment, it's on my list to fix. Taking a look at fixing karamja fishing first. Good to hear the other agility courses worked well. Let me know if you encounter any more issues. Thanks