Jump to content

inventory #contains


progamerz

Recommended Posts

I am having some problems using #contains in a magic script, this is my code:

private boolean hasRunes() {
		return getInventory().contains("Fire rune") && getInventory().contains("Air rune") && getInventory().contains("Mind rune");
	}

What happens is at first it will return true if i have all runes but after casting a spell, it would ALWAYS return false, is it a problem in my code, if so how can i fix it? any suggestions?

Thanks

Link to comment
Share on other sites

1 minute ago, Donald Trump said:

So once the tab has changed off the inventory tab you're saying it goes false. If that's correct then it would be because it doesn't know if your inventory has it because it can't see the inventory?

Nope, what i am saying is lets say i am doing auto cast, onStart() returns true that it has the runes, but onLoop() returns false after -1 amount of runes so i am not sure

Link to comment
Share on other sites

25 minutes ago, progamerz said:

Yup i tried it would work well but, it keeps switching tabs from inventory to spells tab and reverse

Could always check if the spell widget is highlighted or whatever.

Or store how many spells you can cast at the start, and decrement every successful spell.

Just some ideas, cba to check what's wrong with your code myself.

  • Like 1
Link to comment
Share on other sites

17 minutes ago, Donald Trump said:

Is onstart even designed for that usage?

That is called debuging? please if u are here to get 100 post counts, u can check other threads(not being rude)

20 minutes ago, Explv said:

Could always check if the spell widget is highlighted or whatever.

Or store how many spells you can cast at the start, and decrement every successful spell.

Just some ideas, cba to check what's wrong with your code myself.

Ok thanks ill try it

Edited by progamerz
Link to comment
Share on other sites

18 minutes ago, progamerz said:

That is called debuging? please if u are here to get 100 post counts, u can check other threads(not being rude)

Ok thanks ill try it

The code should work so obviously it must be a case of that. The code is fine the method of delivery is questionable, do what you want.

Link to comment
Share on other sites

	/**
	 * Calculate how many casts you can perform. This takes infinite-rune items
	 * (e.g. kodai wand/tomb of fire/staves) into consideration too.
	 * 
	 * @param airRunesRequired - Air runes required
	 * @param waterRunesRequired - Water runes required
	 * @param earthRunesRequired - Earth runes required
	 * @param fireRunesRequired - Fire runes required
	 * @param bodyRunesRequired - Body runes required
	 * @param mindRunesRequired - Mind runes required
	 * @param cosmicRunesRequired - Cosmic runes required
	 * @param chaosRunesRequired - Chaos runes required
	 * @param natureRunesRequired - Nature runes required
	 * @param lawRunesRequired  - Law runes required
	 * @param deathRunesRequired  - Death runes required
	 * @param astralRunesRequired - Astral runes required
	 * @param bloodRunesRequired - Blood runes required
	 * @param soulRunesRequired - Soul runes required
	 * @return castCount - How many casts can be performed
	 */
	private long getCastCount(
			int airRunesRequired,
			int waterRunesRequired,
			int earthRunesRequired,
			int fireRunesRequired,
			int bodyRunesRequired,
			int mindRunesRequired,
			int cosmicRunesRequired,
			int chaosRunesRequired,
			int natureRunesRequired,
			int lawRunesRequired,
			int deathRunesRequired,
			int astralRunesRequired,
			int bloodRunesRequired,
			int soulRunesRequired
			) {
		
		long castCount = Long.MAX_VALUE;
		
		long[][] amounts = new long[12][2];
		long[] amount;
		
		boolean infiniteAirRunes = equipment.isWearingItemThatContains(EquipmentSlot.WEAPON, "Air", "Mist", "Dust", "Smoke");
		boolean infiniteWaterRunes = equipment.isWearingItemThatContains(EquipmentSlot.WEAPON, "Water", "Mist", "Mud", "Steam", "Kodai");
		boolean infiniteEarthRunes = equipment.isWearingItemThatContains(EquipmentSlot.WEAPON, "Earth", "Dust", "Mud", "Lava");
		boolean infiniteFireRunes = equipment.isWearingItemThatContains(EquipmentSlot.WEAPON, "Fire", "Smoke", "Steam", "Lava") || equipment.isWearingItemThatContains(EquipmentSlot.SHIELD, "Tomb of fire");

		long mistRuneCount = inventory.getAmount("Mist rune");
		long dustRuneCount = inventory.getAmount("Dust rune");
		long mudRuneCount = inventory.getAmount("Mud rune");
		long smokeRuneCount = inventory.getAmount("Smoke rune");
		long steamRuneCount = inventory.getAmount("Steam rune");
		long lavaRuneCount = inventory.getAmount("Lava rune");

		amounts[0][0] = airRunesRequired;
		amounts[1][0] = waterRunesRequired;
		amounts[2][0] = earthRunesRequired;
		amounts[3][0] = fireRunesRequired;
		amounts[4][0] = bodyRunesRequired;
		amounts[5][0] = mindRunesRequired;
		amounts[6][0] = cosmicRunesRequired;
		amounts[7][0] = chaosRunesRequired;
		amounts[8][0] = natureRunesRequired;
		amounts[9][0] = lawRunesRequired;
		amounts[10][0] = deathRunesRequired;
		amounts[11][0] = astralRunesRequired;
		amounts[12][0] = bloodRunesRequired;
		amounts[13][0] = soulRunesRequired;
		
		// ELEMENTAL RUNES
		if (infiniteAirRunes) {
			amounts[0][1] = -1;
		} else {
			amounts[0][1] += inventory.getAmount("Air rune");
			amounts[0][1] += mistRuneCount;
			amounts[0][1] += dustRuneCount;
			amounts[0][1] += smokeRuneCount;
		}
		
		if (infiniteWaterRunes) {
			amounts[1][1] = -1;
		} else {
			amounts[1][1] += inventory.getAmount("Water rune");
			amounts[1][1] += mistRuneCount;
			amounts[1][1] += mudRuneCount;
			amounts[1][1] += steamRuneCount;
		}
		
		if (infiniteEarthRunes) {
			amounts[2][1] = -1;
		} else {
			amounts[2][1] += inventory.getAmount("Earth rune");
			amounts[2][1] += dustRuneCount;
			amounts[2][1] += mudRuneCount;
			amounts[2][1] += lavaRuneCount;
		}
		
		if (infiniteFireRunes) {
			amounts[3][1] = -1;
		} else {
			amounts[3][1] += inventory.getAmount("Fire rune");
			amounts[3][1] += smokeRuneCount;
			amounts[3][1] += steamRuneCount;
			amounts[3][1] += lavaRuneCount;
		}
		
		// NON-ELEMENTAL RUNES
		amounts[4][1] = inventory.getAmount("Body rune");
		amounts[5][1] = inventory.getAmount("Mind rune");
		amounts[6][1] = inventory.getAmount("Cosmic rune");
		amounts[7][1] = inventory.getAmount("Chaos rune");
		amounts[8][1] = inventory.getAmount("Nature rune");
		amounts[9][1] = inventory.getAmount("Law rune");
		amounts[10][1] = inventory.getAmount("Death rune");
		amounts[11][1] = inventory.getAmount("Astral rune");
		amounts[12][1] = inventory.getAmount("Blood rune");
		amounts[13][1] = inventory.getAmount("Soul rune");
		
		for (int i = 0; i < amounts.length; i++) {
			amount = amounts[i];
			long requiredCount = amount[0];
			long runeCount = amount[1];
			if (requiredCount > 0 && runeCount != -1) {
				castCount = Math.min(castCount, runeCount / requiredCount);
			}
		}
		
		return castCount;
	}

 

Edited by liverare
  • Like 1
Link to comment
Share on other sites

4 hours ago, liverare said:

	/**
	 * Calculate how many casts you can perform. This takes infinite-rune items
	 * (e.g. kodai wand/tomb of fire/staves) into consideration too.
	 * 
	 * @param airRunesRequired - Air runes required
	 * @param waterRunesRequired - Water runes required
	 * @param earthRunesRequired - Earth runes required
	 * @param fireRunesRequired - Fire runes required
	 * @param bodyRunesRequired - Body runes required
	 * @param mindRunesRequired - Mind runes required
	 * @param cosmicRunesRequired - Cosmic runes required
	 * @param chaosRunesRequired - Chaos runes required
	 * @param natureRunesRequired - Nature runes required
	 * @param lawRunesRequired  - Law runes required
	 * @param deathRunesRequired  - Death runes required
	 * @param astralRunesRequired - Astral runes required
	 * @param bloodRunesRequired - Blood runes required
	 * @param soulRunesRequired - Soul runes required
	 * @return castCount - How many casts can be performed
	 */
	private long getCastCount(
			int airRunesRequired,
			int waterRunesRequired,
			int earthRunesRequired,
			int fireRunesRequired,
			int bodyRunesRequired,
			int mindRunesRequired,
			int cosmicRunesRequired,
			int chaosRunesRequired,
			int natureRunesRequired,
			int lawRunesRequired,
			int deathRunesRequired,
			int astralRunesRequired,
			int bloodRunesRequired,
			int soulRunesRequired
			) {
		
		long castCount = Long.MAX_VALUE;
		
		long[][] amounts = new long[12][2];
		long[] amount;
		
		boolean infiniteAirRunes = equipment.isWearingItemThatContains(EquipmentSlot.WEAPON, "Air", "Mist", "Dust", "Smoke");
		boolean infiniteWaterRunes = equipment.isWearingItemThatContains(EquipmentSlot.WEAPON, "Water", "Mist", "Mud", "Steam", "Kodai");
		boolean infiniteEarthRunes = equipment.isWearingItemThatContains(EquipmentSlot.WEAPON, "Earth", "Dust", "Mud", "Lava");
		boolean infiniteFireRunes = equipment.isWearingItemThatContains(EquipmentSlot.WEAPON, "Fire", "Smoke", "Steam", "Lava") || equipment.isWearingItemThatContains(EquipmentSlot.SHIELD, "Tomb of fire");

		long mistRuneCount = inventory.getAmount("Mist rune");
		long dustRuneCount = inventory.getAmount("Dust rune");
		long mudRuneCount = inventory.getAmount("Mud rune");
		long smokeRuneCount = inventory.getAmount("Smoke rune");
		long steamRuneCount = inventory.getAmount("Steam rune");
		long lavaRuneCount = inventory.getAmount("Lava rune");

		amounts[0][0] = airRunesRequired;
		amounts[1][0] = waterRunesRequired;
		amounts[2][0] = earthRunesRequired;
		amounts[3][0] = fireRunesRequired;
		amounts[4][0] = bodyRunesRequired;
		amounts[5][0] = mindRunesRequired;
		amounts[6][0] = cosmicRunesRequired;
		amounts[7][0] = chaosRunesRequired;
		amounts[8][0] = natureRunesRequired;
		amounts[9][0] = lawRunesRequired;
		amounts[10][0] = deathRunesRequired;
		amounts[11][0] = astralRunesRequired;
		amounts[12][0] = bloodRunesRequired;
		amounts[13][0] = soulRunesRequired;
		
		// ELEMENTAL RUNES
		if (infiniteAirRunes) {
			amounts[0][1] = -1;
		} else {
			amounts[0][1] += inventory.getAmount("Air rune");
			amounts[0][1] += mistRuneCount;
			amounts[0][1] += dustRuneCount;
			amounts[0][1] += smokeRuneCount;
		}
		
		if (infiniteWaterRunes) {
			amounts[1][1] = -1;
		} else {
			amounts[1][1] += inventory.getAmount("Water rune");
			amounts[1][1] += mistRuneCount;
			amounts[1][1] += mudRuneCount;
			amounts[1][1] += steamRuneCount;
		}
		
		if (infiniteEarthRunes) {
			amounts[2][1] = -1;
		} else {
			amounts[2][1] += inventory.getAmount("Earth rune");
			amounts[2][1] += dustRuneCount;
			amounts[2][1] += mudRuneCount;
			amounts[2][1] += lavaRuneCount;
		}
		
		if (infiniteFireRunes) {
			amounts[3][1] = -1;
		} else {
			amounts[3][1] += inventory.getAmount("Fire rune");
			amounts[3][1] += smokeRuneCount;
			amounts[3][1] += steamRuneCount;
			amounts[3][1] += lavaRuneCount;
		}
		
		// NON-ELEMENTAL RUNES
		amounts[4][1] = inventory.getAmount("Body rune");
		amounts[5][1] = inventory.getAmount("Mind rune");
		amounts[6][1] = inventory.getAmount("Cosmic rune");
		amounts[7][1] = inventory.getAmount("Chaos rune");
		amounts[8][1] = inventory.getAmount("Nature rune");
		amounts[9][1] = inventory.getAmount("Law rune");
		amounts[10][1] = inventory.getAmount("Death rune");
		amounts[11][1] = inventory.getAmount("Astral rune");
		amounts[12][1] = inventory.getAmount("Blood rune");
		amounts[13][1] = inventory.getAmount("Soul rune");
		
		for (int i = 0; i < amounts.length; i++) {
			amount = amounts[i];
			long requiredCount = amount[0];
			long runeCount = amount[1];
			if (requiredCount > 0 && runeCount != -1) {
				castCount = Math.min(castCount, runeCount / requiredCount);
			}
		}
		
		return castCount;
	}

 

Tyvm i already made one but, it isn't understandable as this thanks will upgrade to this :)

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...