Jump to content

HHumanSimulator | Simple task delay manager


House

Recommended Posts

What is this? A class which manages timers for delayed actions in a script with a fancy name including SIMULATOR!

Why is it useful? Ease of implementation.

Flaws? It can only be treated as one timer at a time and can not track multiple delays at a time unless the code is expanded.

 

This is pretty meh but its useful and maybe someone will find it useful when they start out scripting.

 

In tasks such as smithing or other highly afk tasks i think that reaction time to notice inventory completion is important to simulate human like behavior to reduce bans. This sort of "anti-ban" if they even do anything helps break patterns that could be detectable, then again if you have a shitty method to interact with things in the world then it won't save you.

Also note that humans are not as random as you think they are and everyone has habits!

 

[updated using suggestions by @PolishCivil]

public class HHumanSimulator {

	//Default time in seconds to wait.
	private static final int default_min_reaction_time = 5;
	private static final int default_max_reaction_time = 15;
	//While active the script will be idle.
	private static boolean active = false;
	//Time is saved in milliseconds in here every time a new simulation start.
	private static long start_time;
	//The randomly generated wait time in milliseconds in stored here.
	private static long current_reaction_time;

	//Check if you can do the task.
	public static boolean check() {
		if (!active) {
			start_time = System.currentTimeMillis();
			current_reaction_time = randomReactionTime(default_min_reaction_time, default_max_reaction_time);
			active = true;
		}
		if (System.currentTimeMillis() - start_time > current_reaction_time)
			active = false;
		return !active;
	}
	
	//Same as above however this method lets you add your own custom times rather than default.
	public static boolean check(int new_min_reaction_time, int new_max_reaction_time) {
		if (!active) {
			start_time = System.currentTimeMillis();
			current_reaction_time = randomReactionTime(new_min_reaction_time, new_max_reaction_time);
			active = true;
		}
		if (System.currentTimeMillis() - start_time > current_reaction_time)
			active = false;
		return !active;
	}
	
	//Same as above however lets you set a % chance for it to trigger or not.
	public static boolean check(int new_min_reaction_time, int new_max_reaction_time, int trigger_chance) {
		if (!active && trigger(trigger_chance)) {
			start_time = System.currentTimeMillis();
			current_reaction_time = randomReactionTime(new_min_reaction_time, new_max_reaction_time);
			active = true;
		}
		if (System.currentTimeMillis() - start_time > current_reaction_time)
			active = false;
		return !active;
	}
	
	//Returns a boolean based on a % chance.
	private static boolean trigger(int chance) {
		int rand = ThreadLocalRandom.current().nextInt(101);
		return rand <= chance;
	}

	//Returns the time left till simulation is done.
	public static long debugTimeLeft() {
		return current_reaction_time - (System.currentTimeMillis() - start_time);
	}

	//Generates a random long between two values.
	private static long randomReactionTime(int min, int max) {
		int random_reaction_time = ThreadLocalRandom.current().nextInt((max - min) + 1) + min;
		return random_reaction_time * 1000L;
	}

}

Example Usage:

		if (!inventory.contains(gold_bar_id)) {
			if (HHumanSimulator.check(5, 15, 50))
				GoldSmither.setState(State.BANK);
			return;
		}
Edited by House
  • Like 1
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...