Jump to content

Looking for feedback on my script


Recommended Posts

Posted

Anyways, made a quick alching script, just putting here if anyone has any comments on how to make it more efficient/smaller and tips on something to improve in coding if there is.

 @Override
    public int onLoop() throws InterruptedException
    
    	{
    		switch (state)
    	{
    	
    	case INIT:
    		if (getMagic().canCast(Spells.NormalSpells.HIGH_LEVEL_ALCHEMY ));
    			state = State.ALCH;
    				break;
    	
    	case ALCH:
    		if (inventory.contains("Maple longbow (u)"));
    			state = State.ALCH2;
    		
    	case ALCH2:
    		getMagic().castSpell(Spells.NormalSpells.HIGH_LEVEL_ALCHEMY);
    			sleep(random(350, 455));
    				state = State.ALCH3;
    					break;
    		
    	case ALCH3:
    		if (getMagic().isSpellSelected())
    			{
    				getInventory().interactWithNameThatContains("Cast", "Maple longbow");
    					sleep(random(1250, 1700)); 
    						state = State.ALCH; }
    							break;
    			
    			
    	}   		
        return random(200, 300);
    }
Posted

A valiant effort!

 

A few things. The structure is acceptable but a little scrambled. You'd be better off just using if loops instead of playing around with enumerated state frameworks for such a simple activity.

 

Secondly, it would be a good idea to put the string of the item you're interacting with as a variable at the top of your code so you can adjust it as a parameter in one place.

 

Finally, i'd recommend instead of using static sleep durations such as sleep(random(x,y));, you use conditional sleeps which wait until the magic tab /inventory / spell selected or whatever to determine what stage of the alch you are in. If it makes you feel more comfortable, you can add very small delays in-between, but I think the tick rate and network speed will account for atleast some randomness anyway.

 

Other than that, looks like it gets the job done, and congrats on writing your first script! Pretty good!

 

the next step is maybe a gui and/or paint! :)

 

~apa


PS i'm a pretty tired out so sorry if something I said didn't make sense, too tired to proof read

Posted

A valiant effort!

 

A few things. The structure is acceptable but a little scrambled. You'd be better off just using if loops instead of playing around with enumerated state frameworks for such a simple activity.

 

Secondly, it would be a good idea to put the string of the item you're interacting with as a variable at the top of your code so you can adjust it as a parameter in one place.

 

Finally, i'd recommend instead of using static sleep durations such as sleep(random(x,y));, you use conditional sleeps which wait until the magic tab /inventory / spell selected or whatever to determine what stage of the alch you are in. If it makes you feel more comfortable, you can add very small delays in-between, but I think the tick rate and network speed will account for atleast some randomness anyway.

 

Other than that, looks like it gets the job done, and congrats on writing your first script! Pretty good!

 

the next step is maybe a gui and/or paint! smile.png

 

~apa

PS i'm a pretty tired out so sorry if something I said didn't make sense, too tired to proof read

 

 

I will experiment with implementing conditional sleeps into the script and paint then and im using states since i plan on adding different types of antiban later on since when i decompiled some local scripts i found they all used switch so i guess it's more efficient? walking  Anyways thanks alot for the feedback :)

 

-erki

Posted

Switch cases are more organized, so I prefer them.

 

One suggestion I have is to use dynamic state detection to make your script more robust. Right now, you cycle from ALCH 1 to ALCH 3 and back. Imagine what might happen if the game lags after ALCH2, causing the spell to get deselected, however. Your script expects to be in ALCH3, but the spell will never get selected, causing your script to get stuck.

 

What I mean is:

 

onLoop() {

 

state = // code to figure out what state you should be in

switch (state) {

    // blah blah

}

 

}

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...