Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package scripts;
- import java.awt.Color;
- import java.awt.Font;
- import java.awt.Graphics;
- import java.awt.Graphics2D;
- import java.awt.Image;
- import java.awt.RenderingHints;
- import java.io.IOException;
- import java.net.URL;
- import java.util.ArrayList;
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- import javax.swing.GroupLayout;
- import javax.swing.LayoutStyle;
- import javax.swing.border.*;
- import javax.imageio.ImageIO;
- import org.tribot.api.General;
- import org.tribot.api.input.Mouse;
- import org.tribot.api2007.Camera;
- import org.tribot.api2007.Game;
- import org.tribot.api2007.GameTab;
- import org.tribot.api2007.Inventory;
- import org.tribot.api2007.Login;
- import org.tribot.api2007.Magic;
- import org.tribot.api2007.NPCs;
- import org.tribot.api2007.Skills;
- import org.tribot.api2007.Skills.SKILLS;
- import org.tribot.api2007.GameTab.TABS;
- import org.tribot.api2007.types.RSItem;
- import org.tribot.api2007.types.RSNPC;
- import org.tribot.script.Script;
- import org.tribot.script.ScriptManifest;
- import org.tribot.script.interfaces.Painting;
- import scripts.DTools.DAntiban;
- import scripts.DTools.DTimer;
- @ScriptManifest(authors = { "TheD" }, category = "TheDScripts", name = "DStunAlcher")
- public class DStunAlcher extends Script implements Painting
- {
- private long startNewsTime = System.currentTimeMillis();
- private String alch_item_name = "";
- private String NPC_TO_STUN = "";
- private String alchSpell = "";
- private String stunSpell= "";
- private int task = 1;
- private int waited = 0;
- private int to_wait = 0;
- private boolean ABC2 = true;
- private boolean ABC2_reactions = true;
- private ArrayList<String> latestNews = new ArrayList<String>();
- private final Font font2 = new Font("Arial", Font.BOLD, 14);
- private final Font font3 = new Font("Arial", 1, 16);
- private State scriptState = State.NOTHING;
- private int magiclvl = 0;
- private int magicxp = 0;
- private boolean GUIWait = true;
- private GUI g = new GUI();
- private boolean castsecondspell = false;
- private boolean castfirstspell = false;
- private enum State { NOTHING,ALCH,STUN
- };
- @Override
- public void run()
- {
- //BEFORE GUI
- this.setLoginBotState(false);
- g.setVisible(true);
- while(GUIWait == true)
- {
- sleep(500);
- if(!GUIWait) break;
- }
- DTimer.startScriptTimer();
- sleep(500);
- DTimer.callGUI();
- //AFTER GUI
- Mouse.setSpeed(General.random(150, 160));
- General.useAntiBanCompliance(true);
- to_wait = General.random(10, 40);
- DAntiban.timedActions();
- DAntiban.generateTrackers(500);
- this.setLoginBotState(true);
- if(Login.getLoginState() == Login.STATE.INGAME)
- {
- magiclvl = Skills.getActualLevel(SKILLS.MAGIC);
- magicxp = Skills.getXP(SKILLS.MAGIC);
- }
- while(true)
- {
- if(ABC2) DAntiban.timedActions();
- loop();
- sleep(50,200);
- if(DTimer.checkEndTimer()) //returns true if we succesfully logged out & are not in combat
- {
- this.stopScript();
- }
- }
- }
- private void loop()
- {
- scriptState = getState();
- switch(scriptState)
- {
- case ALCH:
- if(GameTab.getOpen() != TABS.MAGIC) { waited++; if(waited < to_wait) { to_wait = General.random(10, 40); break; }}
- if(Magic.isSpellSelected() && Magic.getSelectedSpellName().contains(stunSpell)) { task = 2; break; }
- if(Game.getUptext().startsWith("Cast "+alchSpell+" / 1") || !Game.getUptext().startsWith("Cast "+alchSpell) || !Magic.getSelectedSpellName().contains(alchSpell)) Magic.selectSpell(alchSpell);
- if(GameTab.getOpen() != TABS.INVENTORY) break;
- RSItem[] item_to_alch = Inventory.find(alch_item_name);
- if(item_to_alch.length > 0)
- {
- DAntiban.sleep(General.random(1, 4));
- item_to_alch[0].click("Cast "+alchSpell+" -> "+item_to_alch[0].getDefinition().getName());
- }
- waited = 0;
- if(castsecondspell) task = 2;
- if(!ABC2_reactions) DAntiban.smartSleep(750);
- dynamicSleep();
- break;
- case STUN:
- if(GameTab.getOpen() != TABS.MAGIC) { waited++; if(waited < to_wait) { to_wait = General.random(10, 40); break; }}
- if(Magic.isSpellSelected() && Magic.getSelectedSpellName().contains(alchSpell)) { task = 1; break; }
- if(!Game.getUptext().equals("Cast "+stunSpell+"") || Magic.getSelectedSpellName() == null || !Magic.getSelectedSpellName().contains(stunSpell)) { Magic.selectSpell(stunSpell);}
- DAntiban.sleep(General.random(3, 11));
- if(Magic.isSpellSelected())
- {
- RSNPC[] npc_to_stun = NPCs.findNearest(NPC_TO_STUN);
- if(npc_to_stun.length > 0)
- {
- RSNPC stunNPC = null;
- if(npc_to_stun[0] != null) stunNPC = npc_to_stun[0];
- if(stunNPC != null && !stunNPC.getPosition().isOnScreen()) Camera.turnToTile(stunNPC.getPosition());
- stunNPC.click("Cast "+stunSpell+" -> "+stunNPC.getDefinition().getName());
- }
- }
- waited = 0;
- if(castfirstspell) task = 1;
- if(!ABC2_reactions) DAntiban.smartSleep(600);
- dynamicSleep();
- break;
- case NOTHING:
- break;
- }
- }
- private State getState()
- {
- if(castfirstspell && Inventory.find(alch_item_name).length > 0 && Inventory.find("Nature rune").length > 0 && (task == 1 || NPCs.find(NPC_TO_STUN).length < 1))
- return State.ALCH;
- if(castsecondspell && NPCs.findNearest(NPC_TO_STUN).length > 0 && Inventory.find("Soul rune").length > 0 && (task == 2 || Inventory.find(alch_item_name).length < 1 || Inventory.find("Nature rune").length < 1))
- return State.STUN;
- return State.NOTHING;
- }
- private void dynamicSleep()
- {
- if(ABC2_reactions && castsecondspell && castfirstspell)
- {
- DAntiban.generateTrackers(400);
- DAntiban.timedActions();
- DAntiban.sleepReactionTime();
- }
- else if(!ABC2_reactions && !castsecondspell && castfirstspell)
- {
- sleep(500,1200);
- }
- else if(ABC2_reactions && !castsecondspell && castfirstspell)
- {
- DAntiban.generateTrackers(1000);
- DAntiban.timedActions();
- DAntiban.sleepReactionTime();
- }
- else if(ABC2_reactions && !castfirstspell && castsecondspell)
- {
- DAntiban.generateTrackers(500);
- DAntiban.timedActions();
- DAntiban.sleepReactionTime();
- }
- else if(!ABC2_reactions && !castfirstspell && castsecondspell)
- {
- sleep(500,2000);
- }
- }
- int newsToShow = 0;
- private void getnewsdata()
- {
- int newsTimer = (int) (System.currentTimeMillis() - startNewsTime) / 1000;
- if(newsTimer > 8)
- {
- startNewsTime = System.currentTimeMillis();
- if(newsToShow == (latestNews.size() -1)) newsToShow = 0;
- else if(newsToShow < (latestNews.size())) newsToShow++;
- }
- }
- private Image getImage(String url)
- {
- try
- {
- return ImageIO.read(new URL(url));
- }
- catch(IOException e)
- {
- return null;
- }
- }
- private int xpPH = 0;
- private int xpGot = 0;
- private int magiclvlsgained = 0;
- private void calculatePaint()
- {
- xpGot = (Skills.getXP(SKILLS.MAGIC) - magicxp);
- xpPH = DTimer.getPH(xpGot);
- magiclvlsgained = Skills.getActualLevel(SKILLS.MAGIC)-magiclvl;
- }
- private final Image dchickenspaintimg = getImage("http://d-scripting.com/DEssentials/paint/dstunalcherpaint.png");
- private final RenderingHints aa = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
- private final Color darkred = new Color(193,48,38);
- int paintOffset = 320;
- @Override
- public void onPaint(Graphics g)
- {
- if(GUIWait) return;
- getnewsdata();
- calculatePaint();
- Graphics2D g2 = (Graphics2D)g;
- g2.setRenderingHints(aa);
- g2.drawImage(dchickenspaintimg, 0, paintOffset, null);
- g.setColor(Color.CYAN);
- g.setFont(font3);
- if(newsToShow < (latestNews.size())) g.drawString("NEWS: "+ latestNews.get(newsToShow), 40,40);
- g.setColor(darkred);
- g.setFont(font2);
- g.drawString("Time ran: "+ DTimer.getHour() + ":" + DTimer.getMinute() + ":" + DTimer.getSecond(), 5,paintOffset+60);
- g.drawString("Magic level: "+Skills.getActualLevel(SKILLS.MAGIC)+" (+"+magiclvlsgained+")", 5,paintOffset+75);
- g.drawString("Magic XP gained: "+xpGot+" ("+xpPH+" p/h)", 5,paintOffset+90);
- if(DTimer.getEndAfterTime()) g.drawString("Ending script when we ran "+(DTimer.getEndHour())+":"+(DTimer.getEndMinute())+":"+(DTimer.getEndSeconds())+" (HH:MM:SS)", 5,paintOffset+105);
- if(!DTimer.getEndAfterTime()) g.drawString("Not using End-timer or not yet set-up", 5,paintOffset+105);
- g.drawString("State: "+scriptState, 5,paintOffset+120);
- g.drawString("Version: 1.00", 5,paintOffset+160);
- }
- public class GUI extends JFrame {
- public GUI() {
- initComponents();
- }
- private void StartScriptButtonActionPerformed(ActionEvent e)
- {
- ABC2 = useABC2.isSelected();
- ABC2_reactions = abc2ReactionTimes.isSelected();
- castfirstspell = castFirstSpell.isSelected();
- castsecondspell = castSecondSpell.isSelected();
- alch_item_name = itemToAlchName.getText();
- NPC_TO_STUN = npctostunName.getText();
- String alchToCast = alchType.getSelectedItem().toString();
- String secondSpellToCast = secondSpell.getSelectedItem().toString();
- if(alchToCast.startsWith("1. ")) alchSpell = "Low Level Alchemy";
- if(alchToCast.startsWith("2. ")) alchSpell = "High Level Alchemy";
- if(secondSpellToCast.startsWith("1. ")) stunSpell = "Confuse";
- if(secondSpellToCast.startsWith("2. ")) stunSpell = "Weaken";
- if(secondSpellToCast.startsWith("3. ")) stunSpell = "Curse";
- if(secondSpellToCast.startsWith("4. ")) stunSpell = "Vulnerability";
- if(secondSpellToCast.startsWith("5. ")) stunSpell = "Enfeeble";
- if(secondSpellToCast.startsWith("6. ")) stunSpell = "Stun";
- GUIWait = false;
- g.dispose();
- }
- private void DScriptingdotcomActionPerformed(ActionEvent e)
- {
- DTimer.openSite("http://www.d-scripting.com/");
- }
- private void visitDTribotPofileActionPerformed(ActionEvent e)
- {
- DTimer.openSite("https://tribot.org/forums/profile/8498-thed/");
- }
- private void moreDScriptsActionPerformed(ActionEvent e)
- {
- DTimer.openSite("http://d-scripting.com/more");
- }
- private void initComponents() {
- menuBar1 = new JMenuBar();
- menu1 = new JMenu();
- DScriptingdotcom = new JMenuItem();
- visitDTribotPofile = new JMenuItem();
- moreDScripts = new JMenuItem();
- dialogPane = new JPanel();
- contentPanel = new JPanel();
- label1 = new JLabel();
- label2 = new JLabel();
- itemToAlchName = new JTextField();
- label3 = new JLabel();
- alchType = new JComboBox<>();
- label4 = new JLabel();
- secondSpell = new JComboBox<>();
- useABC2 = new JCheckBox();
- abc2ReactionTimes = new JCheckBox();
- label5 = new JLabel();
- npctostunName = new JTextField();
- castSecondSpell = new JCheckBox();
- castFirstSpell = new JCheckBox();
- buttonBar = new JPanel();
- StartScriptButton = new JButton();
- //======== this ========
- setAlwaysOnTop(true);
- setResizable(false);
- setTitle("DScripts by TheD");
- Container contentPane = getContentPane();
- contentPane.setLayout(new BorderLayout());
- //======== menuBar1 ========
- {
- //======== menu1 ========
- {
- menu1.setText("General");
- //---- DScriptingdotcom ----
- DScriptingdotcom.setText("D-Scripting.com");
- DScriptingdotcom.addActionListener(e -> DScriptingdotcomActionPerformed(e));
- menu1.add(DScriptingdotcom);
- //---- visitDTribotPofile ----
- visitDTribotPofile.setText("Visit TheD's TRiBot Profile");
- visitDTribotPofile.addActionListener(e -> visitDTribotPofileActionPerformed(e));
- menu1.add(visitDTribotPofile);
- //---- moreDScripts ----
- moreDScripts.setText("More DScripts");
- moreDScripts.addActionListener(e -> moreDScriptsActionPerformed(e));
- menu1.add(moreDScripts);
- }
- menuBar1.add(menu1);
- }
- setJMenuBar(menuBar1);
- //======== dialogPane ========
- {
- dialogPane.setBorder(new EmptyBorder(12, 12, 12, 12));
- //DScripting mark
- dialogPane.setBorder(new javax.swing.border.CompoundBorder(
- new javax.swing.border.TitledBorder(new javax.swing.border.EmptyBorder(0, 0, 0, 0),
- "DScripting Limited", javax.swing.border.TitledBorder.CENTER,
- javax.swing.border.TitledBorder.BOTTOM, new java.awt.Font("Dialog", java.awt.Font.BOLD, 12),
- java.awt.Color.red), dialogPane.getBorder())); dialogPane.addPropertyChangeListener(new java.beans.PropertyChangeListener(){public void propertyChange(java.beans.PropertyChangeEvent e){if("border".equals(e.getPropertyName()))throw new RuntimeException();}});
- dialogPane.setLayout(new BorderLayout());
- //======== contentPanel ========
- {
- //---- label1 ----
- label1.setText("DStunAlcher");
- label1.setFont(new Font("Tahoma", Font.PLAIN, 48));
- //---- label2 ----
- label2.setText("Item to alch name (Exact):");
- label2.setFont(new Font("Tahoma", Font.PLAIN, 12));
- //---- itemToAlchName ----
- itemToAlchName.setFont(new Font("Tahoma", Font.PLAIN, 12));
- //---- label3 ----
- label3.setText("Type of alch:");
- label3.setFont(new Font("Tahoma", Font.PLAIN, 12));
- //---- alchType ----
- alchType.setFont(new Font("Tahoma", Font.PLAIN, 12));
- alchType.setModel(new DefaultComboBoxModel<>(new String[] {
- "1. Low alchemy",
- "2. High alchemy"
- }));
- alchType.setSelectedIndex(1);
- //---- label4 ----
- label4.setText("Type of secondary spell:");
- label4.setFont(new Font("Tahoma", Font.PLAIN, 12));
- //---- secondSpell ----
- secondSpell.setFont(new Font("Tahoma", Font.PLAIN, 12));
- secondSpell.setModel(new DefaultComboBoxModel<>(new String[] {
- "1. Confuse",
- "2. Weaken",
- "3. Curse",
- "4. Vulnerability",
- "5. Enfeeble",
- "6. Stun"
- }));
- secondSpell.setSelectedIndex(3);
- //---- useABC2 ----
- useABC2.setText("Use ABC2");
- useABC2.setSelected(true);
- useABC2.setFont(new Font("Tahoma", Font.PLAIN, 12));
- //---- abc2ReactionTimes ----
- abc2ReactionTimes.setText("Use ABC2 Reaction times");
- abc2ReactionTimes.setFont(new Font("Tahoma", Font.PLAIN, 12));
- //---- label5 ----
- label5.setText("NPC name to Stun (Exact):");
- label5.setFont(new Font("Tahoma", Font.PLAIN, 12));
- //---- npctostunName ----
- npctostunName.setFont(new Font("Tahoma", Font.PLAIN, 12));
- //---- castSecondSpell ----
- castSecondSpell.setText("Do the following:");
- castSecondSpell.setFont(new Font("Tahoma", Font.PLAIN, 12));
- castSecondSpell.setSelected(true);
- //---- castFirstSpell ----
- castFirstSpell.setText("Do the following:");
- castFirstSpell.setFont(new Font("Tahoma", Font.PLAIN, 12));
- castFirstSpell.setSelected(true);
- GroupLayout contentPanelLayout = new GroupLayout(contentPanel);
- contentPanel.setLayout(contentPanelLayout);
- contentPanelLayout.setHorizontalGroup(
- contentPanelLayout.createParallelGroup()
- .addGroup(contentPanelLayout.createSequentialGroup()
- .addComponent(label1)
- .addGap(0, 234, Short.MAX_VALUE))
- .addGroup(contentPanelLayout.createSequentialGroup()
- .addContainerGap()
- .addGroup(contentPanelLayout.createParallelGroup()
- .addGroup(contentPanelLayout.createSequentialGroup()
- .addComponent(useABC2)
- .addGap(18, 18, 18)
- .addComponent(abc2ReactionTimes))
- .addGroup(contentPanelLayout.createSequentialGroup()
- .addGroup(contentPanelLayout.createParallelGroup()
- .addGroup(contentPanelLayout.createSequentialGroup()
- .addComponent(label4)
- .addGap(11, 11, 11))
- .addGroup(GroupLayout.Alignment.TRAILING, contentPanelLayout.createSequentialGroup()
- .addComponent(label5)
- .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)))
- .addGroup(contentPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
- .addComponent(secondSpell, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
- .addComponent(npctostunName, GroupLayout.PREFERRED_SIZE, 200, GroupLayout.PREFERRED_SIZE)
- .addComponent(castSecondSpell)))
- .addGroup(contentPanelLayout.createSequentialGroup()
- .addGroup(contentPanelLayout.createParallelGroup()
- .addComponent(label2)
- .addComponent(label3))
- .addGap(11, 11, 11)
- .addGroup(contentPanelLayout.createParallelGroup()
- .addComponent(alchType, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
- .addComponent(itemToAlchName, GroupLayout.PREFERRED_SIZE, 200, GroupLayout.PREFERRED_SIZE)
- .addComponent(castFirstSpell))))
- .addContainerGap(125, Short.MAX_VALUE))
- );
- contentPanelLayout.setVerticalGroup(
- contentPanelLayout.createParallelGroup()
- .addGroup(contentPanelLayout.createSequentialGroup()
- .addComponent(label1)
- .addGap(18, 18, 18)
- .addComponent(castFirstSpell)
- .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 12, Short.MAX_VALUE)
- .addGroup(contentPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
- .addComponent(label3)
- .addComponent(alchType, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
- .addGap(2, 2, 2)
- .addGroup(contentPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
- .addComponent(itemToAlchName, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
- .addComponent(label2))
- .addGap(18, 18, 18)
- .addComponent(castSecondSpell)
- .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
- .addGroup(contentPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
- .addComponent(label4)
- .addComponent(secondSpell, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(contentPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
- .addComponent(npctostunName, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
- .addComponent(label5))
- .addGap(18, 18, 18)
- .addGroup(contentPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
- .addComponent(useABC2)
- .addComponent(abc2ReactionTimes))
- .addContainerGap())
- );
- }
- dialogPane.add(contentPanel, BorderLayout.CENTER);
- //======== buttonBar ========
- {
- buttonBar.setBorder(new EmptyBorder(12, 0, 0, 0));
- buttonBar.setLayout(new GridBagLayout());
- ((GridBagLayout)buttonBar.getLayout()).columnWidths = new int[] {0, 80};
- ((GridBagLayout)buttonBar.getLayout()).columnWeights = new double[] {1.0, 0.0};
- //---- StartScriptButton ----
- StartScriptButton.setText("Start Script");
- StartScriptButton.addActionListener(e -> StartScriptButtonActionPerformed(e));
- buttonBar.add(StartScriptButton, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,
- GridBagConstraints.CENTER, GridBagConstraints.BOTH,
- new Insets(0, 0, 0, 0), 0, 0));
- }
- dialogPane.add(buttonBar, BorderLayout.SOUTH);
- }
- contentPane.add(dialogPane, BorderLayout.CENTER);
- pack();
- setLocationRelativeTo(getOwner());
- }
- private JMenuBar menuBar1;
- private JMenu menu1;
- private JMenuItem DScriptingdotcom;
- private JMenuItem visitDTribotPofile;
- private JMenuItem moreDScripts;
- private JPanel dialogPane;
- private JPanel contentPanel;
- private JLabel label1;
- private JLabel label2;
- private JTextField itemToAlchName;
- private JLabel label3;
- private JComboBox<String> alchType;
- private JLabel label4;
- private JComboBox<String> secondSpell;
- private JCheckBox useABC2;
- private JCheckBox abc2ReactionTimes;
- private JLabel label5;
- private JTextField npctostunName;
- private JCheckBox castSecondSpell;
- private JCheckBox castFirstSpell;
- private JPanel buttonBar;
- private JButton StartScriptButton;
- //END OF GUI
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement