Jump to content

Looking for feedback on my script


erkis123

Recommended Posts

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);
    }
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

}

 

}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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